├── .github
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── ISSUE_TEMPLATE
│ └── config.yml
├── PULL_REQUEST_TEMPLATE.md
└── SECURITY.md
├── .gitignore
├── LICENSE
├── README.md
├── assets
├── terraform-cost-estimation.png
└── terraform-cost-estimation.psd
├── docs
├── CNAME
├── index.html
├── main.js
└── style.css
├── samples
├── opa
│ └── terraform-cost-estimation.rego
├── terraform-code
│ ├── .gitignore
│ ├── data.tf
│ ├── main.tf
│ └── plan.json
├── terraform012-plan.json
└── terraform012-state.json
└── terraform.jq
/.github/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, sex characteristics, gender identity and expression,
9 | level of experience, education, socio-economic status, nationality, personal
10 | appearance, race, religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies within all project spaces, and it also applies when
49 | an individual is representing the project or its community in public spaces.
50 | Examples of representing a project or community include using an official
51 | project e-mail address, posting via an official social media account, or acting
52 | as an appointed representative at an online or offline event. Representation of
53 | a project may be further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at anton@antonbabenko.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 | For answers to common questions about this code of conduct, see
76 | https://www.contributor-covenant.org/faq
77 |
--------------------------------------------------------------------------------
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing Guidelines
2 |
3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
4 | documentation, we greatly value feedback and contributions from our community.
5 |
6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
7 | information to effectively respond to your bug report or contribution.
8 |
9 |
10 | ## Reporting Bugs/Feature Requests
11 |
12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features.
13 |
14 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already
15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
16 |
17 | * A reproducible test case or series of steps
18 | * The version of our code being used
19 | * Any modifications you've made relevant to the bug
20 | * Anything unusual about your environment or deployment
21 |
22 |
23 | ## Contributing via Pull Requests
24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
25 |
26 | 1. You are working against the latest source on the *master* branch.
27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
29 |
30 | To send us a pull request, please:
31 |
32 | 1. Fork the repository.
33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
34 | 3. Ensure local tests pass.
35 | 4. Commit to your fork using clear commit messages.
36 | 5. Send us a pull request, answering any default questions in the pull request interface.
37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
38 |
39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
41 |
42 |
43 | ## Finding contributions to work on
44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start.
45 |
46 |
47 | ## Code of Conduct
48 | This project has adopted the [Contributor Covenant][homepage], version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
49 |
50 | [homepage]: https://www.contributor-covenant.org
51 |
52 | For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq
53 |
54 |
55 | ## Licensing
56 |
57 | See the LICENSE file for our project's licensing.
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Description
2 |
3 |
4 | ## Motivation and Context
5 |
6 |
7 |
8 | ## Breaking Changes
9 |
10 |
11 |
12 | ## How Has This Been Tested?
13 |
14 |
15 |
16 |
17 | ## Screenshots (if appropriate):
18 |
--------------------------------------------------------------------------------
/.github/SECURITY.md:
--------------------------------------------------------------------------------
1 | ## Reporting a Vulnerability
2 |
3 | If you discover a potential security issue in this project please notify me via email to anton@antonbabenko.com.
4 |
5 | Please do **not** create a public github issue.
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | work
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Anonymized, secure and free Terraform Cost Estimation
2 |
3 | `cost.modules.tf` is entirely free cost estimation service, which is part of [modules.tf](https://modules.tf) that is currently in active development.
4 |
5 | Join the mailing list on [modules.tf](https://modules.tf) to stay updated!
6 |
7 | This is not an official HashiCorp product.
8 |
9 | ## tldr; Post your Terraform state or plan-file (as JSON) and get cost estimation:
10 |
11 | ```
12 | $ terraform state pull | curl -s -X POST -H "Content-Type: application/json" -d @- https://cost.modules.tf/
13 |
14 | {"hourly": 0.01, "monthly": 9.07}
15 | ```
16 |
17 | NB: Cost estimation uses official [AWS pricing data](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/price-changes.html) and does not include estimates for items not specified in Terraform configurations (e.g., usage patterns, amount of API calls, bandwidth, disk I/O, spot prices, AWS discounts, etc.).
18 |
19 | It is sometimes impossible to extract all information required for cost estimations from the Terraform plan provided, and it is more accurate to get estimates from the Terraform state file after the infrastructure is created.
20 |
21 | See the list of [supported resources](#supported-resources).
22 |
23 |
24 | ## Secrets and sensitive information
25 |
26 | As you probably know, **Terraform state and plan files may contain secrets and sensitive information** which you don't want to send anywhere to get cost estimates. There is a solution that is supported, secure, and easy to put in your continuous automation process.
27 |
28 | All you need to do is to process the Terraform state or plan file with [terraform.jq file](https://github.com/antonbabenko/terraform-cost-estimation/blob/master/terraform.jq) which is available in this repository.
29 |
30 | > Make sure that JQ version 1.6 is installed. Many Linux distributions install older version by default, and you need to update it as described in the [official documentation](https://stedolan.github.io/jq/download/).
31 |
32 | `terraform.jq` creates **anonymized cost keys** sufficient to perform cost estimation.
33 |
34 | For example, cost keys for a single EC2 instance and an Application Load Balancer in `eu-west-1` region look like this:
35 | ```
36 | {
37 | "keys": [
38 | "ec2#eu-west-1#t3.nano#shared#linux",
39 | "ec2#eu-west-1#alb"
40 | ]
41 | }
42 | ```
43 |
44 | The whole process looks like this:
45 |
46 | ```
47 | # Download terraform.jq file
48 | $ curl -sLO https://raw.githubusercontent.com/antonbabenko/terraform-cost-estimation/master/terraform.jq
49 |
50 | # Get terraform state (or plan), extract cost keys, send them to cost estimation service
51 | $ terraform state pull | jq -cf terraform.jq | curl -s -X POST -H "Content-Type: application/json" -d @- https://cost.modules.tf/
52 |
53 | {"hourly": 0.01, "monthly": 9.07}
54 | ```
55 |
56 | Sweet, isn't it?
57 |
58 |
59 | ## Things you should know about infrastructure costs:
60 |
61 | - [x] How much does my infrastructure is going to cost **before** create?
62 | - [x] How much does my infrastructure cost **after** it is created (based on Terraform state)?
63 | - [x] What is the **difference in the price** comparing to the current infrastructure (based on Terraform plan)?
64 | - [x] Can I have cost estimation based on Terraform 0.7 state files? Yes, any version of Terraform state files is supported!
65 |
66 |
67 | ## Example - Get cost estimates during `terraform plan`
68 |
69 | The flow is like this:
70 |
71 | 1. Plan Terraform changes into a plan-file
72 | 2. Convert the plan-file into JSON-file
73 | 3. Extract anonymized cost keys from the JSON-file (optional, but recommended)
74 | 4. Send cost keys to cost.modules.tf
75 | 5. Process response
76 |
77 | Step 3 recommended if you don't want to send the whole JSON-file, which may contain sensitive information.
78 |
79 | The whole command looks like this:
80 |
81 | ```
82 | # Install jq and download `terraform.jq` file as described in "secrets and sensitive information" section
83 |
84 | $ terraform plan -out=plan.tfplan > /dev/null && terraform show -json plan.tfplan | jq -cf terraform.jq | curl -s -X POST -H "Content-Type: application/json" -d @- https://cost.modules.tf/
85 | ```
86 |
87 | Alternatively, you can send the whole Terraform plan-file without modification as json, too:
88 |
89 | ```
90 | $ terraform plan -out=plan.tfplan > /dev/null && terraform show -json plan.tfplan | curl -s -X POST -H "Content-Type: application/json" -d @- https://cost.modules.tf/
91 | ```
92 |
93 |
94 | ### Helpers
95 |
96 | ```
97 | # Get Terraform plan as json
98 | $ terraform plan -out=plan.tfplan > /dev/null && terraform show -json plan.tfplan > plan.json
99 |
100 | # Get Terraform state as json (option 1)
101 | $ terraform state pull > plan.json
102 |
103 | # Get Terraform state as json (option 2)
104 | $ terraform show -json > plan.json
105 |
106 | # Do something is monthly cost is too high
107 | $ ... | curl -s -X POST -H "Content-Type: application/json" -d @- https://cost.modules.tf/ > costs.json
108 | $ jq 'if .monthly|tonumber > 10 then "$" else "$$$" end' costs.json
109 | ```
110 |
111 |
112 | ## Supported resources
113 |
114 | 1. EC2 instances (on-demand) and Autoscaling Groups (Launch Configurations and Launch Templates):
115 | - [x] aws_instance
116 | - [x] aws_autoscaling_group
117 | - [x] aws_launch_configuration
118 | - [x] aws_launch_template
119 |
120 | 2. EC2 Fleets (on-demand)
121 | - [x] aws_ec2_fleet
122 |
123 | 3. EBS Volumes, Snapshots, Snapshot Copies
124 | - [x] aws_ebs_volume
125 | - [x] aws_ebs_snapshot
126 | - [x] aws_ebs_snapshot_copy
127 |
128 | 4. Elastic Load Balancing (ELB, ALB, NLB)
129 | - [x] aws_elb
130 | - [x] aws_alb / aws_lb
131 |
132 | 5. NAT Gateways
133 | - [x] aws_nat_gateway
134 |
135 |
136 | Please suggest other resources worth covering by upvoting existing issue or opening new issue.
137 |
138 | As [AWS Community Hero](https://aws.amazon.com/developer/community/heroes/anton-babenko/), I work a lot with AWS, but I am equally interested in covering other popular [Terraform Providers](https://www.terraform.io/docs/providers/) with decent pricing API.
139 |
140 |
141 | ## Like this? Please follow me and share it with your network!
142 |
143 | [](https://twitter.com/antonbabenko)
144 | [](https://github.com/antonbabenko)
145 |
146 | Consider support my work on [GitHub Sponsors](https://github.com/sponsors/antonbabenko), [Buy me a coffee](https://www.buymeacoffee.com/antonbabenko), or [PayPal](https://www.paypal.me/antonbabenko).
147 |
148 |
149 | ## Disclaimer
150 |
151 | `cost.modules.tf` runs by [Betajob](https://www.betajob.com). We don't save, publish, share with anyone data submitted to the service.
152 | No identifiable customer information used to query pricing systems (check source code of [terraform.jq](https://github.com/antonbabenko/terraform-cost-estimation/blob/master/terraform.jq)).
153 |
154 | `terraform-cost-estimation` project managed by [Anton Babenko](https://github.com/antonbabenko).
155 |
156 | This is not an official HashiCorp product. You may want to look into [Terraform Cloud](https://www.terraform.io/docs/cloud/) where similar feature exists.
157 |
158 |
159 | ## License
160 |
161 | This code is released under the Apache 2.0 License. Please see LICENSE for more details.
162 |
163 | Copyright © 2020 Anton Babenko (Betajob AS)
--------------------------------------------------------------------------------
/assets/terraform-cost-estimation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antonbabenko/terraform-cost-estimation/5bce8cfd244c95e4c7df4056bcc6805e25302487/assets/terraform-cost-estimation.png
--------------------------------------------------------------------------------
/assets/terraform-cost-estimation.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antonbabenko/terraform-cost-estimation/5bce8cfd244c95e4c7df4056bcc6805e25302487/assets/terraform-cost-estimation.psd
--------------------------------------------------------------------------------
/docs/CNAME:
--------------------------------------------------------------------------------
1 | terraform-cost-estimation.com
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | Terraform Cost Estimation
15 |
21 |
22 |
28 |
29 |
30 |
31 |
Terraform Cost Estimation
32 |
from Terraform plan and Terraform state.
33 |
81 |
93 |
This is not an official HashiCorp product. You may want to look into Terraform Cloud where similar feature exists.
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/docs/main.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | (function (document) {
4 | const fileSelector = document.getElementById( 'file-selector' );
5 | const label = fileSelector.nextElementSibling,
6 | labelVal = label.innerHTML;
7 |
8 | fileSelector.addEventListener( 'change', function( e ) {
9 | let fileName = e.target.value.split( '\\' ).pop();
10 |
11 | if (fileName) {
12 | label.querySelector( 'span' ).innerHTML = fileName;
13 | } else {
14 | label.innerHTML = labelVal;
15 | }
16 | });
17 |
18 | // Firefox bug fix
19 | fileSelector.addEventListener( 'focus', function(){ fileSelector.classList.add( 'has-focus' ); });
20 | fileSelector.addEventListener( 'blur', function(){ fileSelector.classList.remove( 'has-focus' ); });
21 |
22 | ///////////
23 |
24 | const fileLabel = fileSelector.nextElementSibling
25 |
26 | const payloadSelector = document.getElementById("payload")
27 | const estimateButton = document.getElementById('estimate-button')
28 |
29 | const textAreaErrorSelector = document.getElementById('request-error-selector')
30 | const mainErrorSelector = document.getElementById('main-error')
31 |
32 | const estimatedCostsSelector = document.getElementById('estimated-costs')
33 | const estimatedCostsDiffSelector = document.getElementById('estimates-costs-diff')
34 |
35 | const toDisableButton = () => {
36 | estimateButton.classList.add('disabled')
37 | estimateButton.innerHTML = 'ESTIMATING...'
38 | }
39 |
40 | const toEnableButton = () => {
41 | estimateButton.classList.remove('disabled')
42 | estimateButton.innerHTML = 'ESTIMATE'
43 | }
44 |
45 |
46 | const isValidJSONString = (string) => {
47 | try {
48 | JSON.parse(string);
49 | } catch (e) {
50 | return false
51 | }
52 | return true
53 | }
54 |
55 | const setDataIntoTag = (data) => {
56 | const hasHourlyAndMonthlyField = data.hasOwnProperty('hourly') && data.hasOwnProperty('monthly')
57 |
58 | const hasDiffHourlyAndMonthlyField =
59 | data.hasOwnProperty('diff_hourly') && data.hasOwnProperty('diff_monthly')
60 |
61 | if (hasDiffHourlyAndMonthlyField) {
62 | estimatedCostsDiffSelector.innerHTML = `Estimated cost difference: USD ${data.diff_hourly} per hour, or USD ${data.diff_monthly} per month.
Total estimated costs: USD ${data.hourly} per hour, or USD ${data.monthly} per month.`
63 | } else if (hasHourlyAndMonthlyField) {
64 | estimatedCostsSelector.innerHTML = `Estimated costs: USD ${data.hourly} per hour, or USD ${data.monthly} per month.`
65 | }
66 | }
67 |
68 | const clearDataFromTag = () => {
69 | estimatedCostsSelector.innerHTML = ''
70 | estimatedCostsDiffSelector.innerHTML = ''
71 | }
72 |
73 | const postData = async (data = {}) => {
74 | try {
75 | const response = await fetch('https://cost.modules.tf/?from=website', {
76 | method: 'POST',
77 | mode: 'cors',
78 | headers: {
79 | 'Content-Type': 'application/json'
80 | },
81 | body: JSON.stringify(data)
82 | })
83 | toEnableButton()
84 | return response.json()
85 | } catch (e) {
86 | toEnableButton()
87 | mainErrorSelector.innerHTML = `Something went wrong: ${e}`
88 | console.warn('Something went wrong', e)
89 | }
90 | }
91 |
92 | fileSelector.addEventListener('change', (event) => {
93 | const fileReader = new FileReader();
94 | fileReader.onload = function (e) {
95 | const textFromFile = e.target.result;
96 | payloadSelector.value = textFromFile;
97 | };
98 | fileReader.readAsText(event.target.files[0], "UTF-8");
99 | })
100 |
101 | estimateButton.addEventListener('click', function (event) {
102 | event.preventDefault()
103 |
104 | clearDataFromTag()
105 |
106 | const payloadData = payloadSelector.value.replace(/\s+/g,'')
107 |
108 | if (!!payloadData && isValidJSONString(payloadData)) {
109 | toDisableButton()
110 | const parsedData = JSON.parse(payloadData)
111 | postData(parsedData).then(data => {
112 | if (!!data.errors) {
113 | const msg = data.errors[0] && data.errors[0].message
114 | textAreaErrorSelector.innerHTML = msg
115 | } else {
116 | fileSelector.value = ''
117 | payloadSelector.value = ''
118 | fileLabel.querySelector( 'span' ).innerHTML = 'Choose a file (json, tfstate) ...'
119 | textAreaErrorSelector.innerHTML = ''
120 | setDataIntoTag(data)
121 | }
122 | }).catch(e => {
123 | console.log(e)
124 | })
125 | } else {
126 | textAreaErrorSelector.innerHTML = 'Please choose correct JSON file or put the content in the field'
127 | }
128 | })
129 | })(document)
130 |
--------------------------------------------------------------------------------
/docs/style.css:
--------------------------------------------------------------------------------
1 | /* reset */
2 | html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big,
3 | cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd,
4 | ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details,
5 | embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary,
6 | time, mark, audio, video { margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline; }
7 | input:focus, select:focus, textarea:focus {outline:none}
8 | table,td,th,tr {border-collapse:collapse; border-spacing:0;}
9 | html, body{width:100%; height:100%;}
10 | input, select, textarea,button {font-family: 'Open Sans', arial, sans-serif; font-weight:400; box-sizing: border-box; color: #000;}
11 | button,input[type="button"]{cursor: pointer}
12 |
13 | .clear{clear:both; font-size:0;}
14 | .clearfix::after{clear: both; content: ""; display: table;}
15 |
16 |
17 |
18 | /* custom-file-input */
19 |
20 | .js .inputfile {
21 | width: 0.1px;
22 | height: 0.1px;
23 | opacity: 0;
24 | overflow: hidden;
25 | position: absolute;
26 | z-index: -1;
27 | }
28 |
29 | .inputfile + label {
30 | max-width: 80%;
31 | font-size: 16px;
32 | /* 20px */
33 | font-weight: 600;
34 | text-overflow: ellipsis;
35 | white-space: nowrap;
36 | cursor: pointer;
37 | display: inline-block;
38 | overflow: hidden;
39 | padding: 0.625rem 1.25rem;
40 | /* 10px 20px */
41 | }
42 |
43 | .no-js .inputfile + label {
44 | display: none;
45 | }
46 |
47 | .inputfile + label * {
48 | /* pointer-events: none; */
49 | /* in case of FastClick lib use */
50 | }
51 |
52 | .inputfile + label svg {
53 | width: 1em;
54 | height: 1em;
55 | vertical-align: middle;
56 | fill: currentColor;
57 | margin-top: -0.25em;
58 | /* 4px */
59 | margin-right: 0.25em;
60 | /* 4px */
61 | }
62 |
63 | /* style 2 */
64 |
65 | .inputfile-2 + label {
66 | color: #d3394c;
67 | border: 1px solid #e6e6e6;
68 | border-radius: 13px;
69 | }
70 |
71 | .inputfile-2:focus + label,
72 | .inputfile-2.has-focus + label,
73 | .inputfile-2 + label:hover {
74 | color: #722040;
75 | }
76 |
77 |
78 |
79 |
80 |
81 |
82 | /*Main Styles*/
83 | * {
84 | box-sizing: border-box;
85 | padding: 0;
86 | margin: 0;
87 | }
88 |
89 | body {
90 | background: #e6e6e6;
91 | font-size: 16px;
92 | font-family: 'Montserrat', Arial, sans-serif;
93 | font-weight: 400;
94 | padding-top: 50px;
95 | }
96 |
97 | .page-wrap {
98 | max-width: 920px;
99 | min-width: 320px;
100 | width: 100%;
101 | margin: 0 auto;
102 | background: #fff;
103 | border-radius: 10px;
104 | overflow: hidden;
105 | padding: 55px 55px 20px;
106 | }
107 | /*End Main Styles*/
108 |
109 | /*<>*/
110 | .page-wrap .main-title,
111 | .page-wrap .main-subtitle {
112 | text-align: center;
113 | color: #333333;
114 | }
115 |
116 | .page-wrap .main-title {
117 | font-weight: 900;
118 | font-size: 39px;
119 | line-height: 1.2;
120 | padding-bottom: 5px;
121 | }
122 | .page-wrap .main-subtitle {
123 | font-size: 18px;
124 | font-weight: 700;
125 | }
126 | /*End <>*/
127 |
128 | /*<