├── .gitignore ├── CODE_OF_CONDUCT ├── Dockerfile ├── LICENSE ├── contrib ├── LICENSE ├── aws.json └── core_providers.json ├── docs ├── CHANGELOG.md ├── LICENSE ├── README.md ├── _config.yml ├── _includes │ └── head-custom.html ├── _layouts │ └── default.html ├── design.md ├── editor.md ├── favicon.ico ├── hcl.md ├── images │ ├── create_edge.png │ ├── create_edge.xcf │ ├── create_resource.png │ ├── create_resource.xcf │ ├── edit_resource.png │ ├── edit_resource.xcf │ ├── export_hcl.png │ ├── export_hcl.xcf │ ├── graph_example.png │ ├── graph_example.xcf │ ├── provider_selection.png │ ├── provider_selection.xcf │ ├── providers_modal.png │ └── providers_modal.xcf ├── providers.md └── roadmap.md ├── package-lock.json ├── package.json ├── public ├── LICENSE ├── fulllogo_transparent_nobuffer.png ├── icononly_transparent_nobuffer.ico ├── icononly_transparent_nobuffer.png └── index.html ├── rollup.config.js ├── scripts └── setupTypeScript.js └── src ├── App.svelte ├── Editor.svelte ├── design.js ├── hcl.js ├── klay.js ├── main.js ├── main.scss ├── prevent_navigation.js ├── providers.js ├── store.js ├── tfSchema.js └── utils.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | /public/build/ 3 | local/ 4 | .idea/ 5 | 6 | .DS_Store 7 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT: -------------------------------------------------------------------------------- 1 | 2 | # Contributor Covenant Code of Conduct 3 | 4 | ## Our Pledge 5 | 6 | We as members, contributors, and leaders pledge to make participation in our 7 | community a harassment-free experience for everyone, regardless of age, body 8 | size, visible or invisible disability, ethnicity, sex characteristics, gender 9 | identity and expression, level of experience, education, socio-economic status, 10 | nationality, personal appearance, race, caste, color, religion, or sexual 11 | identity and orientation. 12 | 13 | We pledge to act and interact in ways that contribute to an open, welcoming, 14 | diverse, inclusive, and healthy community. 15 | 16 | ## Our Standards 17 | 18 | Examples of behavior that contributes to a positive environment for our 19 | community include: 20 | 21 | * Demonstrating empathy and kindness toward other people 22 | * Being respectful of differing opinions, viewpoints, and experiences 23 | * Giving and gracefully accepting constructive feedback 24 | * Accepting responsibility and apologizing to those affected by our mistakes, 25 | and learning from the experience 26 | * Focusing on what is best not just for us as individuals, but for the overall 27 | community 28 | 29 | Examples of unacceptable behavior include: 30 | 31 | * The use of sexualized language or imagery, and sexual attention or advances of 32 | any kind 33 | * Trolling, insulting or derogatory comments, and personal or political attacks 34 | * Public or private harassment 35 | * Publishing others' private information, such as a physical or email address, 36 | without their explicit permission 37 | * Other conduct which could reasonably be considered inappropriate in a 38 | professional setting 39 | 40 | ## Enforcement Responsibilities 41 | 42 | Community leaders are responsible for clarifying and enforcing our standards of 43 | acceptable behavior and will take appropriate and fair corrective action in 44 | response to any behavior that they deem inappropriate, threatening, offensive, 45 | or harmful. 46 | 47 | Community leaders have the right and responsibility to remove, edit, or reject 48 | comments, commits, code, wiki edits, issues, and other contributions that are 49 | not aligned to this Code of Conduct, and will communicate reasons for moderation 50 | decisions when appropriate. 51 | 52 | ## Scope 53 | 54 | This Code of Conduct applies within all community spaces, and also applies when 55 | an individual is officially representing the community in public spaces. 56 | Examples of representing our community include using an official e-mail address, 57 | posting via an official social media account, or acting as an appointed 58 | representative at an online or offline event. 59 | 60 | ## Enforcement 61 | 62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 63 | reported to the community leaders responsible for enforcement at 64 | [tbd](). 65 | All complaints will be reviewed and investigated promptly and fairly. 66 | 67 | All community leaders are obligated to respect the privacy and security of the 68 | reporter of any incident. 69 | 70 | ## Enforcement Guidelines 71 | 72 | Community leaders will follow these Community Impact Guidelines in determining 73 | the consequences for any action they deem in violation of this Code of Conduct: 74 | 75 | ### 1. Correction 76 | 77 | **Community Impact**: Use of inappropriate language or other behavior deemed 78 | unprofessional or unwelcome in the community. 79 | 80 | **Consequence**: A private, written warning from community leaders, providing 81 | clarity around the nature of the violation and an explanation of why the 82 | behavior was inappropriate. A public apology may be requested. 83 | 84 | ### 2. Warning 85 | 86 | **Community Impact**: A violation through a single incident or series of 87 | actions. 88 | 89 | **Consequence**: A warning with consequences for continued behavior. No 90 | interaction with the people involved, including unsolicited interaction with 91 | those enforcing the Code of Conduct, for a specified period of time. This 92 | includes avoiding interactions in community spaces as well as external channels 93 | like social media. Violating these terms may lead to a temporary or permanent 94 | ban. 95 | 96 | ### 3. Temporary Ban 97 | 98 | **Community Impact**: A serious violation of community standards, including 99 | sustained inappropriate behavior. 100 | 101 | **Consequence**: A temporary ban from any sort of interaction or public 102 | communication with the community for a specified period of time. No public or 103 | private interaction with the people involved, including unsolicited interaction 104 | with those enforcing the Code of Conduct, is allowed during this period. 105 | Violating these terms may lead to a permanent ban. 106 | 107 | ### 4. Permanent Ban 108 | 109 | **Community Impact**: Demonstrating a pattern of violation of community 110 | standards, including sustained inappropriate behavior, harassment of an 111 | individual, or aggression toward or disparagement of classes of individuals. 112 | 113 | **Consequence**: A permanent ban from any sort of public interaction within the 114 | community. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 2.1, available at 120 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 121 | 122 | Community Impact Guidelines were inspired by 123 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. 124 | 125 | For answers to common questions about this code of conduct, see the FAQ at 126 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at 127 | [https://www.contributor-covenant.org/translations][translations]. 128 | 129 | [homepage]: https://www.contributor-covenant.org 130 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 131 | [Mozilla CoC]: https://github.com/mozilla/diversity 132 | [FAQ]: https://www.contributor-covenant.org/faq 133 | [translations]: https://www.contributor-covenant.org/translations 134 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:17 2 | 3 | WORKDIR /usr/src/app 4 | 5 | COPY package*.json ./ 6 | RUN npm install 7 | 8 | COPY . . 9 | 10 | EXPOSE 5000/tcp 11 | 12 | CMD ["npm", "run", "dev"] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at https://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. -------------------------------------------------------------------------------- /contrib/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2021 Jason Rauen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /docs/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | ## Unreleased 5 | 6 | ## 20211204.1 7 | ### Added 8 | - Users can now add, set, remove, import, and export Terraform vairables, outputs, and locals 9 | ### Changed 10 | - Made some minor changes to improve accessibility 11 | 12 | ## 20211128.1 13 | Initialize changelog 14 | ### Added 15 | - Providers can be configured in the editor pane 16 | - The `terraform` block can also be configured this way 17 | - A Pan/Zoom control in the diagram area 18 | - Closes #1 19 | ### Changed 20 | - The HCL import will now handle `provider` and `terraform` blocks 21 | - The `terraform` block `required_providers` attribute is required for proper parsing 22 | 23 | 24 | 32 | -------------------------------------------------------------------------------- /docs/LICENSE: -------------------------------------------------------------------------------- 1 | This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | Terraforge is an application for generating Terraform code visually. Users select providers and then add resources as 2 | nodes to a graph that can be edited and arranged. Links between nodes appear automatically as the configuration of a 3 | node makes references to other nodes. When finished the design can be exported as Terraform HCL. The configuration will 4 | include all settings and configurations entered for the nodes. 5 | 6 | ![Terraforge Example](images/graph_example.png) 7 | 8 | ## Background 9 | Terraform is a tool for managing infrastructure and APIs in a codified manner utilizing a combination of a command-line 10 | application, a series of vendor specific plugins, and a declarative configuration language written in HCL. The 11 | configuration uses a flat file structure with layers of abstraction attained through local and remote modules. Writing 12 | Terraform configurations create many complex relationships between resources since each resource may rely on attributes 13 | of others. 14 | 15 | The Terraform application generates a Directed Acyclic Graph (DAG) based on the configuration which establishes the 16 | correct order of resource manipulation. There are several tools that allow users to input configuration files then 17 | output and visualize the DAG. However, there seems to be a lack of any tool that can reverse this process, starting 18 | with a visual representation of the desired infrastructure and exporting the Terraform code. This was the inspiration 19 | for Terraforge. 20 | 21 | ## Get started 22 | ### Running the App 23 | Install the dependencies... 24 | 25 | ```bash 26 | git clone https://github.com/badarsebard/terraforge.git 27 | cd terraforge 28 | npm install 29 | ``` 30 | 31 | ...then start [Rollup](https://rollupjs.org): 32 | 33 | ```bash 34 | npm run dev 35 | ``` 36 | 37 | Navigate to [localhost:5000](http://localhost:5000). You should see the app running. 38 | 39 | ### Using the App 40 | To get started right away use the Wizard under the Providers menu. 41 | - Select the Official and AWS checkboxes in the modal and click Submit. 42 | ![Providers Modal](images/providers_modal.png) 43 | - Select the `hashicorp/aws` provider from the dropdown on the right and choose either resource or data source radio buttons. 44 | ![](images/provider_selection.png) 45 | - Double-click an entry to add a node of that type to the graph in the center of the page. 46 | ![Create Rsource](images/create_resource.png) 47 | - Click a node to open a pane on the left-hand side of the window where the name and attributes of the node can be 48 | modified. 49 | ![Edit Node](images/edit_resource.png) 50 | - References between nodes can be made by entering `$type.name.attributes` in the attribute; e.g.`$aws_lb.front_end.arn`. 51 | ![Create Edge](images/create_edge.png) 52 | - After creating and editing some resources, export the Terraform configuration by using Export in the HCL menu. 53 | ![Export HCL](images/export_hcl.png) 54 | - The browser will download a file called `terraforge.tf` which will contain the Terraform configuration represented by the diagram and based on the configurations entered. 55 | ```terraform 56 | resource "aws_lb" "front_end" {} 57 | resource "aws_lb_listener" "https" { 58 | load_balancer_arn = aws_lb.front_end.arn 59 | } 60 | ``` 61 | 62 | Please note that the app is unable to, at this time, execute any Terraform commands so the output is unformatted and unvalidated. 63 | 64 | ## Documentation 65 | Learn about managing the available [providers](providers.md) and how resources and data sources are added. 66 | 67 | See all the details about the [editor](editor.md) and its components. 68 | 69 | Save and load work using [design](design.md) import and export. 70 | 71 | Turn your graph into a [Terraform config](hcl.md) by exporting HCL or pick up with an existing project using the import feature. 72 | 73 | See the [roadmap](roadmap.md) for a list of planned features. 74 | 75 | # License 76 | The majority of this project is licensed under the [Mozilla Public License, v. 2.0](https://mozilla.org/MPL/2.0/). The 77 | `contrib/` directory and its contents are licensed under the [MIT](https://www.mit.edu/~amini/LICENSE.md) license. Any 78 | file which does not contain the MPL license header is still covered by the MPL if it is located in a directory 79 | containing a `LICENSE` with the header. 80 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate 2 | title: Terraforge -------------------------------------------------------------------------------- /docs/_includes/head-custom.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | {% seo %} 11 | {% include head-custom.html %} 12 | 13 | 14 | 15 | 16 | 17 |
18 |
19 | {% if site.github.is_project_page %} 20 | View on GitHub 21 | {% endif %} 22 | Go to App 32 |

{{ site.title | default: site.github.repository_name }}

33 |

{{ site.description | default: site.github.project_tagline }}

34 | 35 | {% if site.show_downloads %} 36 |
37 | Download this project as a .zip file 38 | Download this project as a tar.gz file 39 |
40 | {% endif %} 41 |
42 | Home 43 | Providers 44 | Editor 45 | Design 46 | HCL 47 | Roadmap 48 | Changelog 49 |
50 |
51 |
52 | 53 | 54 |
55 |
56 | {{ content }} 57 |
58 |
59 | 60 | 61 | 69 | 70 | -------------------------------------------------------------------------------- /docs/design.md: -------------------------------------------------------------------------------- 1 | # Graph Import/Export 2 | Terraforge utilizes the cytoscape js library for the rendering and manipulation of the configuration graph. This library 3 | can import and export a representation of the graph and its data in a JSON format. Terraforge utilizes this 4 | import/export capability to save and load various configurations that users develop and work on. This is key since the 5 | application (currently) does not save state between sessions or even page loads. Refreshing or navigating to another 6 | page will lose any unsaved progress. The browser _should_ present a warning to the user if it detects any changes prior 7 | to navigation or refresh but this mechanism should not be relied on exclusively. The recommended method is to export 8 | the JSON data and save it for future import. 9 | 10 | ## Import/Export Walkthrough 11 | The navbar at the top of the page has a dropdown menu labeled `Design`. Hovering over this menu item will present the 12 | option to Import or Export. Clicking export will cause the browser to immediately download a file called 13 | `terraforge.json`. Clicking the import button will open a file dialog to select the JSON file later on. Please note that 14 | the diagram may not display immediately if a providers schema has not yet been loaded. -------------------------------------------------------------------------------- /docs/editor.md: -------------------------------------------------------------------------------- 1 | # Editor 2 | The editor has three main components: the resource selector, diagram, and node pane. 3 | 4 | ## Resource Selector 5 | The resource selector will appear on the right-hand side of the page once the providers schema is uploaded. Each 6 | provider will appear as an option in the dropdown and the radio buttons select between resource and data source types. 7 | Once both are selected a list of available resource for that provider and resource type. Double-clicking on a resource 8 | will add a new node to the diagram. 9 | 10 | ## Diagram 11 | The center portion of the page contains the current diagram of nodes and edges corresponding to the resources and their 12 | relationships. This area can be used to reposition the nodes and has the ability to pan and zoom. Clicking a node will 13 | open the node pane where the attributes of the node can be modified. 14 | 15 | ## Node Pane 16 | While a node on the diagram is selected (highlighted in blue) the node pane will open on the left-hand side of the page. 17 | This pane can be used to set each of the attributes and blocks associated with the resource or data source. The 18 | uppermost input is the name of the resource and will be reflected in the label of the node in the diagram. To the right 19 | of this input is a button with a times-circle icon that, when clicked, will delete the resource from the graph. 20 | 21 | The names of the attributes will appear as placeholders within text box inputs or labels to checkboxes for boolean 22 | values. If the resource accepts configuration blocks then the name of each block type will appear along with a button 23 | and green plus icon. Pushing the icon will add a textarea input for that block type. The user will need to enter the 24 | properly formatted HCL configuration for the block. Future versions of the app will provide independent inputs for the 25 | attributes of the block. Some resources accept multiple of the same kind of block. Pressing the button will add 26 | additional textarea inputs. If the schema specifies a maximum number of these configuration blocks, then no additional 27 | textarea will be added. 28 | 29 | As resources are configured throughout the diagram there will likely be need to make references between resources. 30 | These relationships are specified by referencing the type and name of a resource, prepended by a dollar-sign (`$`); 31 | e.g. `$aws_lb.front_end`. Like a Terraform configuration the user can specify attributes of the resource by adding 32 | additional segments separated by a period (`.`); e.g. `$aws_lb.front_end.arn`. However, only the type and name of the 33 | resource are required to create an edge between the two nodes. -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/favicon.ico -------------------------------------------------------------------------------- /docs/hcl.md: -------------------------------------------------------------------------------- 1 | # HCL 2 | 3 | ## Export 4 | The primary purpose of Terraforge is to provide a visual way to create Terraform configurations. This is accomplished 5 | through the `Export HCL` menu item in the navbar. This will take the existing diagram and all associated configuration 6 | data entered through the node pane will be converted to HCL and downloaded by the browser. Please note that currently 7 | the HCL spacing is not properly formatted. The user can run `terraform fmt` to reformat the spacing of the file. The 8 | exported configuration will also contain all variables, outputs, and locals defined through the app. 9 | 10 | ## Import 11 | Terraforge supports existing Terraform projects by importing a single `.tf` file and generating the graph representing 12 | those resources. This is still an experimental feature. There are several known limitations to the capability including: 13 | no meta-argument support, poor interpolation interpretation, no module support, lack of functions, or dynamic blocks. 14 | Many of these features are forthcoming and in development and described in detail in the [roadmap](roadmap.md). -------------------------------------------------------------------------------- /docs/images/create_edge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/images/create_edge.png -------------------------------------------------------------------------------- /docs/images/create_edge.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/images/create_edge.xcf -------------------------------------------------------------------------------- /docs/images/create_resource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/images/create_resource.png -------------------------------------------------------------------------------- /docs/images/create_resource.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/images/create_resource.xcf -------------------------------------------------------------------------------- /docs/images/edit_resource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/images/edit_resource.png -------------------------------------------------------------------------------- /docs/images/edit_resource.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/images/edit_resource.xcf -------------------------------------------------------------------------------- /docs/images/export_hcl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/images/export_hcl.png -------------------------------------------------------------------------------- /docs/images/export_hcl.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/images/export_hcl.xcf -------------------------------------------------------------------------------- /docs/images/graph_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/images/graph_example.png -------------------------------------------------------------------------------- /docs/images/graph_example.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/images/graph_example.xcf -------------------------------------------------------------------------------- /docs/images/provider_selection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/images/provider_selection.png -------------------------------------------------------------------------------- /docs/images/provider_selection.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/images/provider_selection.xcf -------------------------------------------------------------------------------- /docs/images/providers_modal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/images/providers_modal.png -------------------------------------------------------------------------------- /docs/images/providers_modal.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/docs/images/providers_modal.xcf -------------------------------------------------------------------------------- /docs/providers.md: -------------------------------------------------------------------------------- 1 | # Providers 2 | Terraforge relies on the same schema used by Terraform when executing the provider plugins. In effect, this schema 3 | provides all the options for resources and data sources available for creation. Terraforge has two ways to provide the 4 | schema: the wizard and direct upload. 5 | 6 | ## Wizard 7 | The providers wizard is a modal that allows the user to select the providers they'd like to use and automatically 8 | generate the needed schema for the app. Providers come it in three tiers: official, partner, and community. The official 9 | providers are written and maintained by Hashicorp. Partner providers are owned and maintained by third-party 10 | technology partners. Providers in this tier indicate HashiCorp has verified the authenticity of the Provider’s 11 | publisher, and that the partner is a member of the 12 | [HashiCorp Technology Partner Program](https://www.hashicorp.com/ecosystem/become-a-partner/). Community providers are 13 | published to the Terraform Registry by individual maintainers, groups of maintainers, or other members of the Terraform 14 | community. 15 | 16 | The modal has controls at the top that allow the user to filter the available provider options by their tier and name. 17 | Select the desired providers by marking the checkboxes and clicking the submit button at the bottom of the modal. 18 | 19 | ## Direct Upload 20 | The wizard provides a quick user-friendly way to start working in Terraforge, but it lacks the ability to target 21 | specific versions of different providers. Additionally, it only has access to providers hosted on 22 | [registry.terraform.io](https://registry.terraform.io). In order to use custom providers or specific versions of a 23 | provider the user should generate the schema and upload it to Terraforge. 24 | 25 | ### Creating the Schema 26 | Create Terraform file `main.tf` file which contains the required providers. Ensure all providers 27 | that are needed in Terraforge are listed together. 28 | ```terraform 29 | terraform { 30 | required_providers { 31 | aws = { 32 | source = "hashicorp/aws" 33 | version = "3.63.0" 34 | } 35 | kubernetes = { 36 | source = "hashicorp/kubernetes" 37 | version = "2.6.1" 38 | } 39 | } 40 | } 41 | ``` 42 | 43 | Once the Terraform configuration is in place the schema can be generated using the command: 44 | ```bash 45 | terraform providers schema -json > providers.json 46 | ``` 47 | 48 | This schema is then uploaded to Terraforge using the `Upload manually` button in the `Providers` menu. -------------------------------------------------------------------------------- /docs/roadmap.md: -------------------------------------------------------------------------------- 1 | # Roadmap 2 | Below is a list of features of Terraform that are currently unsupported and _may_ be implemented in the future. 3 | 4 | - ~~Configure providers~~ 5 | - ~~Configure the `terraform` block~~ 6 | - ~~Declare and set variables~~ 7 | - ~~Declare and set outputs~~ 8 | - ~~Declare and set locals~~ 9 | - Support of dynamic blocks 10 | - Support interpolation in strings 11 | - Support comments 12 | - Update graph based on the results of evaluating expressions and functions 13 | - Support meta-arguments: 14 | - depends_on 15 | - count 16 | - for_each 17 | - lifecycle 18 | - provider 19 | - Support modules and module expansion 20 | - Support outputs from child modules 21 | - Support provisioners 22 | - Multi-file (archive) import 23 | - Executing terraform commands like fmt, validate, and plan 24 | 25 | ## Improvement Ideas 26 | - ~~HCL import sets provider configuration based on the provider blocks present~~ 27 | - Support provider aliases 28 | - Support parsing expressions and functions during import 29 | - Improve type support of strings, lists, maps, etc 30 | - Handle quoted vs unquoted HCL strings (`resource` vs `"resource_name"`) 31 | - Create a `raw edit` mode that allows the user to directly modify the stanza 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "terraforge", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "build": "rollup -c", 7 | "dev": "rollup -c -w", 8 | "start": "sirv public --no-clear --host" 9 | }, 10 | "devDependencies": { 11 | "@rollup/plugin-commonjs": "^17.0.0", 12 | "@rollup/plugin-node-resolve": "^11.0.0", 13 | "autoprefixer": "^10.4.0", 14 | "bulma": "^0.9.3", 15 | "bulmaswatch": "^0.8.1", 16 | "node-sass": "^6.0.1", 17 | "postcss": "^8.3.11", 18 | "rollup": "^2.3.4", 19 | "rollup-plugin-css-only": "^3.1.0", 20 | "rollup-plugin-livereload": "^2.0.0", 21 | "rollup-plugin-svelte": "^7.0.0", 22 | "rollup-plugin-terser": "^7.0.0", 23 | "svelte": "^3.0.0", 24 | "svelte-preprocess": "^4.9.8" 25 | }, 26 | "dependencies": { 27 | "cytoscape": "^3.20.0", 28 | "cytoscape-klay": "^3.1.4", 29 | "cytoscape-panzoom": "^2.5.3", 30 | "sirv-cli": "^1.0.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /public/LICENSE: -------------------------------------------------------------------------------- 1 | This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. -------------------------------------------------------------------------------- /public/fulllogo_transparent_nobuffer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/public/fulllogo_transparent_nobuffer.png -------------------------------------------------------------------------------- /public/icononly_transparent_nobuffer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/public/icononly_transparent_nobuffer.ico -------------------------------------------------------------------------------- /public/icononly_transparent_nobuffer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/badarsebard/terraforge/560a6897c40df98182785359b011f58fb1e8ade8/public/icononly_transparent_nobuffer.png -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Terraforge 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import svelte from 'rollup-plugin-svelte'; 2 | import commonjs from '@rollup/plugin-commonjs'; 3 | import resolve from '@rollup/plugin-node-resolve'; 4 | import livereload from 'rollup-plugin-livereload'; 5 | import { terser } from 'rollup-plugin-terser'; 6 | import css from 'rollup-plugin-css-only'; 7 | import sveltePreprocess from "svelte-preprocess"; 8 | 9 | const production = !process.env.ROLLUP_WATCH; 10 | 11 | function serve() { 12 | let server; 13 | 14 | function toExit() { 15 | if (server) server.kill(0); 16 | } 17 | 18 | return { 19 | writeBundle() { 20 | if (server) return; 21 | server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], { 22 | stdio: ['ignore', 'inherit', 'inherit'], 23 | shell: true 24 | }); 25 | 26 | process.on('SIGTERM', toExit); 27 | process.on('exit', toExit); 28 | } 29 | }; 30 | } 31 | 32 | export default { 33 | input: 'src/main.js', 34 | output: { 35 | sourcemap: true, 36 | format: 'iife', 37 | name: 'app', 38 | file: 'public/build/bundle.js' 39 | }, 40 | plugins: [ 41 | svelte({ 42 | preprocess: sveltePreprocess({ 43 | sourceMap: !production, 44 | scss: { 45 | includePaths: [ 46 | 'node_modules', 47 | 'src' 48 | ] 49 | }, 50 | postcss: { 51 | plugins: [require('autoprefixer')()] 52 | } 53 | }), 54 | compilerOptions: { 55 | // enable run-time checks when not in production 56 | dev: !production 57 | } 58 | }), 59 | // we'll extract any component CSS out into 60 | // a separate file - better for performance 61 | css({ output: 'bundle.css' }), 62 | 63 | // If you have external dependencies installed from 64 | // npm, you'll most likely need these plugins. In 65 | // some cases you'll need additional configuration - 66 | // consult the documentation for details: 67 | // https://github.com/rollup/plugins/tree/master/packages/commonjs 68 | resolve({ 69 | browser: true, 70 | dedupe: ['svelte'] 71 | }), 72 | commonjs(), 73 | 74 | // In dev mode, call `npm run start` once 75 | // the bundle has been generated 76 | !production && serve(), 77 | 78 | // Watch the `public` directory and refresh the 79 | // browser on changes when not in production 80 | !production && livereload('public'), 81 | 82 | // If we're building for production (npm run build 83 | // instead of npm run dev), minify 84 | production && terser() 85 | ], 86 | watch: { 87 | clearScreen: false 88 | } 89 | }; 90 | -------------------------------------------------------------------------------- /scripts/setupTypeScript.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs") 2 | const path = require("path") 3 | const { argv } = require("process") 4 | 5 | const projectRoot = argv[2] || path.join(__dirname, "..") 6 | 7 | // Add deps to pkg.json 8 | const packageJSON = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf8")) 9 | packageJSON.devDependencies = Object.assign(packageJSON.devDependencies, { 10 | "svelte-check": "^2.0.0", 11 | "svelte-preprocess": "^4.0.0", 12 | "@rollup/plugin-typescript": "^8.0.0", 13 | "typescript": "^4.0.0", 14 | "tslib": "^2.0.0", 15 | "@tsconfig/svelte": "^2.0.0" 16 | }) 17 | 18 | // Add script for checking 19 | packageJSON.scripts = Object.assign(packageJSON.scripts, { 20 | "check": "svelte-check --tsconfig ./tsconfig.json" 21 | }) 22 | 23 | // Write the package JSON 24 | fs.writeFileSync(path.join(projectRoot, "package.json"), JSON.stringify(packageJSON, null, " ")) 25 | 26 | // mv src/main.js to main.ts - note, we need to edit rollup.config.js for this too 27 | const beforeMainJSPath = path.join(projectRoot, "src", "main.js") 28 | const afterMainTSPath = path.join(projectRoot, "src", "main.ts") 29 | fs.renameSync(beforeMainJSPath, afterMainTSPath) 30 | 31 | // Switch the app.svelte file to use TS 32 | const appSveltePath = path.join(projectRoot, "src", "App.svelte") 33 | let appFile = fs.readFileSync(appSveltePath, "utf8") 34 | appFile = appFile.replace(" 211 | 317 | 318 | 395 | 396 |
397 |
398 | {#if $editorOn} 399 |
400 | 401 |
402 | {/if} 403 |
404 |
405 |
406 |
407 | {#if $providerSchemas} 408 |
409 | 410 | 411 | 412 | 425 | 426 | 427 | 441 | 442 | 443 | 444 | {#if (selected && stanzaType && $providerSchemas[selected][stanzaType + "_schemas"])} 445 | {#each Object.keys($providerSchemas[selected][stanzaType + "_schemas"]) as rt} 446 | {#if (rt.includes(filter))} 447 | 448 | 449 | 450 | {/if} 451 | {/each} 452 | {/if} 453 | 454 |
413 |
414 | Provider 415 | 416 |
417 |
418 | 423 |
424 |
428 |
429 | 433 | 438 |
439 | 440 |
{rt}
455 |
456 | {/if} 457 |
458 |
459 | 460 | 461 | 462 | 530 | 616 | 692 | 746 |
747 | -------------------------------------------------------------------------------- /src/Editor.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 130 | 131 | 145 | 146 |
147 |

148 | {data.tf.type} 149 |

150 | {#if data.type !== 'provider'} 151 |
152 |
153 | 154 |
155 |
156 |
157 | 162 |
163 | {/if} 164 |
165 |
166 | {#if data.type !== 'provider'} 167 |
168 |
169 |

Meta-Arguments 170 | {#if showMeta} 171 | showMeta = !showMeta}> 172 | {:else} 173 | showMeta = !showMeta}> 174 | {/if} 175 |

176 |
177 |
178 | {#if showMeta} 179 |
180 | 181 |
182 | 183 |
184 |
185 |
186 | 187 |
188 | 189 |
190 |
191 |
192 | 193 |
194 | 195 |
196 |
197 |
198 | 199 |
200 | 201 |
202 |
203 |
204 | 205 |
206 | 207 |
208 |
209 | {/if} 210 | {/if} 211 |
212 |
213 |
214 | {#if requiredCount > 0} 215 |
216 |

Required


217 |
218 | {#each Object.keys(schema.attributes.required) as attribute} 219 | {#if schema.attributes.required[attribute].type === "bool"} 220 |
221 |
222 | 226 |
227 |
228 | {:else} 229 |
230 | 231 |
232 | 233 |
234 |
235 | {/if} 236 | {/each} 237 | {#each Object.keys(schema.block_types.required) as block_type} 238 |
239 |

{block_type}

240 | 245 |
246 | {#each (data.tf.config.blocks[block_type] ?? []) as _, i} 247 |
248 |
249 |
250 | 251 |
252 |
253 | {/each} 254 | {/each} 255 |
256 | {/if} 257 | {#if optionalCount > 0} 258 |
259 |

Optional


260 |
261 | {#each Object.keys(schema.attributes.optional) as attribute} 262 | {#if schema.attributes[attribute].type === "bool"} 263 |
264 |
265 | 269 |
270 |
271 | {:else} 272 |
273 | 274 |
275 | 276 |
277 |
278 | {/if} 279 | {/each} 280 | {#each Object.keys(schema.block_types.optional) as block_type} 281 |
282 |

{block_type}

283 | 288 |
289 | {#each (data.tf.config.blocks[block_type] ?? []) as _, i} 290 |
291 |
292 | 293 |
294 |
295 | {/each} 296 | {/each} 297 | {/if} 298 |
299 | -------------------------------------------------------------------------------- /src/design.js: -------------------------------------------------------------------------------- 1 | import { tfName } from "./utils"; 2 | import { resources, cy } from "./store"; 3 | 4 | export function parseDesignFile(f) { 5 | if (!f) { 6 | return 7 | } 8 | let fr = new FileReader(); 9 | 10 | fr.onload = function (e) { 11 | let data = JSON.parse(e.target.result); 12 | for (let i = 0; i < data.style.length; i++) { 13 | if (data.style[i].selector === "node") { 14 | data.style[i].style.label = tfName; 15 | break 16 | } 17 | } 18 | let cyObj; 19 | cy.subscribe(value => {cyObj = value}); 20 | cyObj.json(data); 21 | for (const node of data.elements.nodes) { 22 | let n = cyObj.$id(node.data.id) 23 | resources.update(r => [...r, n]); 24 | } 25 | } 26 | 27 | fr.readAsText(f.item(0)); 28 | } -------------------------------------------------------------------------------- /src/hcl.js: -------------------------------------------------------------------------------- 1 | import { 2 | computeEdges, 3 | createProviderBlockResource, 4 | createResourceOrDataBlockResource, 5 | createTerraformBlockResource, 6 | createVariableResource, 7 | createOutputResource, 8 | addLocalResource 9 | } from "./utils"; 10 | import {resources, cy, hclVariables, hclOutputs, hclLocals} from "./store"; 11 | 12 | export function exportHCL() { 13 | let hcl = ''; 14 | let res; 15 | let vars; 16 | let outs; 17 | let locals; 18 | resources.subscribe(value => res = value); 19 | hclVariables.subscribe(value => vars = value); 20 | hclOutputs.subscribe(value => outs = value); 21 | hclLocals.subscribe(value => locals = value); 22 | for (const r of res) { 23 | let data = r.data() 24 | let stanzaType; 25 | let stanzaName = ""; 26 | let type; 27 | if (data.tf.stanzaType === "resource") { 28 | stanzaType = "resource"; 29 | stanzaName = ' "'+data.tf.stanzaName+'"'; 30 | type = ' "'+data.tf.type+'"'; 31 | } else if (data.tf.stanzaType === "data_source") { 32 | stanzaType = "data_source"; 33 | stanzaName = ' "'+data.tf.stanzaName+'"'; 34 | type = ' "'+data.tf.type+'"'; 35 | } else if (data.tf.stanzaType === "provider") { 36 | stanzaType = "provider"; 37 | type = data.tf.type 38 | if (type === "terraform") { 39 | stanzaType = "terraform" 40 | type = "" 41 | } else { 42 | type = ' "'+type.split("/")[1]+'"'; 43 | } 44 | } 45 | hcl += 46 | `${stanzaType.replace("_source", "")}${type}${stanzaName} {${Object.keys(data.tf.config.attributes).map((key) => { 47 | if (typeof data.tf.config.attributes[key] === "string") { 48 | if (data.tf.config.attributes[key].startsWith("$")) { 49 | return ` 50 | ${key} = ${data.tf.config.attributes[key].slice(1)}` 51 | } else { 52 | return ` 53 | ${key} = ${data.tf.config.attributes[key]}` 54 | } 55 | } else { 56 | return ` 57 | ${key} = ${data.tf.config.attributes[key]}` 58 | } 59 | }).join('')}${Object.keys(data.tf.config.blocks).map((key) => { 60 | if (typeof data.tf.config.blocks[key] === "string") { 61 | return ` 62 | ${key} ${data.tf.config.blocks[key].replace("$", "")}` 63 | } else { 64 | let retVar = ``; 65 | for (const block of data.tf.config.blocks[key]) { 66 | retVar += ` 67 | 68 | ${key} ${block.replace("$", "")}` 69 | } 70 | return retVar 71 | } 72 | }).join('')} 73 | } 74 | ` 75 | } 76 | for (const v of vars) { 77 | // {name: "", default: "", type: "", description: "", validation: "", sensitive: false} 78 | let out = {...v}; 79 | delete out.name; 80 | hcl += ` 81 | variable ${v.name} { 82 | ` 83 | for (const a in out) { 84 | if (out[a]) { 85 | hcl += ` ${a} = ${out[a]} 86 | ` 87 | } 88 | } 89 | hcl += `}` 90 | } 91 | for (const o of outs) { 92 | // {name: "", value: "", description: "", sensitive: false, depends_on: ""} 93 | let out = {...o}; 94 | delete out.name; 95 | hcl += ` 96 | output ${o.name} { 97 | ` 98 | for (const a in out) { 99 | if (out[a]) { 100 | hcl += ` ${a} = ${out[a]} 101 | ` 102 | } 103 | } 104 | hcl += `}` 105 | } 106 | // locals 107 | hcl += ` 108 | locals { 109 | ` 110 | for (const l of locals) { 111 | if (l.value) { 112 | hcl += ` ${l.name} = ${l.value} 113 | ` 114 | } 115 | } 116 | hcl += `}` 117 | let file = new File([hcl], "terraforge.tf", { 118 | type: "text/plain", 119 | }); 120 | const link = document.createElement("a"); 121 | link.style.display = "none"; 122 | link.href = URL.createObjectURL(file); 123 | link.download = file.name; 124 | document.body.appendChild(link); 125 | link.click(); 126 | setTimeout(() => { 127 | URL.revokeObjectURL(link.href); 128 | link.parentNode.removeChild(link); 129 | }, 0); 130 | } 131 | 132 | const resourcePattern = /(?locals|output|variable|data|resource|provider|terraform)\s*(?"\w+")?\s*(?"\w+")?\s*(?{}|{[\s\S]*?^})/gm; 133 | const providerPattern = /(?\w+)\s+=\s+{[\s\S]+?source\s+=\s+"(?\w+\/\w+)"[\s\S]+?}/gm; 134 | const linkPattern = /[^"]\b(\w+(?:\.\w+)+)\b(?:[^"]|$)/gm; 135 | export function importHCL(f) { 136 | if (!f) { 137 | return 138 | } 139 | let fr = new FileReader(); 140 | 141 | fr.onload = function (e) { 142 | let config = e.target.result; 143 | let hclProviderMap = {}; 144 | const pro = [...config.matchAll(providerPattern)]; 145 | for (const p of pro) { 146 | hclProviderMap[p.groups.name] = p.groups.fullname; 147 | } 148 | let res = [...config.matchAll(resourcePattern)]; 149 | // find all interconnections between stanzas 150 | for (let i = 0; i < res.length; i++) { 151 | let links = [...res[i].groups.stanzaConfig.matchAll(linkPattern)]; 152 | let linkMatches = []; 153 | for (let i = 0; i < links.length; i++) { 154 | if (linkMatches.includes(links[i][1])) { 155 | links.splice(i, 1); 156 | i--; 157 | } else { 158 | linkMatches.push(links[i][1]) 159 | } 160 | } 161 | for (const l of links) { 162 | let linkPieces = l[1].split("."); 163 | if (linkPieces[0] !== "data") { 164 | linkPieces.splice(0, 0, "resource") 165 | } 166 | let setLink = false; 167 | for (const r of res) { 168 | if (r.groups.blockType === "terraform" || r.groups.blockType === "provider") { 169 | continue 170 | } 171 | if (linkPieces[0] === r.groups.blockType.replaceAll('"', "") && 172 | linkPieces[1] === r.groups.resourceType.replaceAll('"', "") && 173 | linkPieces[2] === r.groups.stanzaName.replaceAll('"', "")) { 174 | setLink = true; 175 | } 176 | } 177 | if (setLink) { 178 | res[i].groups.stanzaConfig = res[i].groups.stanzaConfig.replaceAll(l[1], `$${l[1]}`); 179 | } 180 | } 181 | } 182 | // create resource objects from stanzas 183 | for (const r of res) { 184 | let bt = r.groups.blockType; 185 | if (bt === "terraform") { 186 | createTerraformBlockResource(r); 187 | } else if (bt === "provider") { 188 | createProviderBlockResource(r, hclProviderMap); 189 | } else if (bt === "resource" || bt === "data") { 190 | createResourceOrDataBlockResource(r, hclProviderMap); 191 | } else if (bt === "variable") { 192 | createVariableResource(r); 193 | } else if (bt === "output") { 194 | createOutputResource(r); 195 | } else if (bt === "locals") { 196 | addLocalResource(r); 197 | } 198 | } 199 | let cyto; 200 | cy.subscribe(value => cyto = value); 201 | resources.subscribe(value => res = value); 202 | computeEdges(res, cyto); 203 | } 204 | 205 | fr.readAsText(f.item(0)); 206 | } -------------------------------------------------------------------------------- /src/klay.js: -------------------------------------------------------------------------------- 1 | export var options = { 2 | name: 'klay', 3 | nodeDimensionsIncludeLabels: false, // Boolean which changes whether label dimensions are included when calculating node dimensions 4 | fit: true, // Whether to fit 5 | padding: 20, // Padding on fit 6 | animate: false, // Whether to transition the node positions 7 | animateFilter: function( node, i ){ return true; }, // Whether to animate specific nodes when animation is on; non-animated nodes immediately go to their final positions 8 | animationDuration: 500, // Duration of animation in ms if enabled 9 | animationEasing: undefined, // Easing of animation if enabled 10 | transform: function( node, pos ){ return pos; }, // A function that applies a transform to the final node position 11 | ready: undefined, // Callback on layoutready 12 | stop: undefined, // Callback on layoutstop 13 | klay: { 14 | // Following descriptions taken from http://layout.rtsys.informatik.uni-kiel.de:9444/Providedlayout.html?algorithm=de.cau.cs.kieler.klay.layered 15 | addUnnecessaryBendpoints: false, // Adds bend points even if an edge does not change direction. 16 | aspectRatio: 1.6, // The aimed aspect ratio of the drawing, that is the quotient of width by height 17 | borderSpacing: 20, // Minimal amount of space to be left to the border 18 | compactComponents: false, // Tries to further compact components (disconnected sub-graphs). 19 | crossingMinimization: 'LAYER_SWEEP', // Strategy for crossing minimization. 20 | /* LAYER_SWEEP The layer sweep algorithm iterates multiple times over the layers, trying to find node orderings that minimize the number of crossings. The algorithm uses randomization to increase the odds of finding a good result. To improve its results, consider increasing the Thoroughness option, which influences the number of iterations done. The Randomization seed also influences results. 21 | INTERACTIVE Orders the nodes of each layer by comparing their positions before the layout algorithm was started. The idea is that the relative order of nodes as it was before layout was applied is not changed. This of course requires valid positions for all nodes to have been set on the input graph before calling the layout algorithm. The interactive layer sweep algorithm uses the Interactive Reference Point option to determine which reference point of nodes are used to compare positions. */ 22 | cycleBreaking: 'GREEDY', // Strategy for cycle breaking. Cycle breaking looks for cycles in the graph and determines which edges to reverse to break the cycles. Reversed edges will end up pointing to the opposite direction of regular edges (that is, reversed edges will point left if edges usually point right). 23 | /* GREEDY This algorithm reverses edges greedily. The algorithm tries to avoid edges that have the Priority property set. 24 | INTERACTIVE The interactive algorithm tries to reverse edges that already pointed leftwards in the input graph. This requires node and port coordinates to have been set to sensible values.*/ 25 | direction: 'UNDEFINED', // Overall direction of edges: horizontal (right / left) or vertical (down / up) 26 | /* UNDEFINED, RIGHT, LEFT, DOWN, UP */ 27 | edgeRouting: 'ORTHOGONAL', // Defines how edges are routed (POLYLINE, ORTHOGONAL, SPLINES) 28 | edgeSpacingFactor: 0.5, // Factor by which the object spacing is multiplied to arrive at the minimal spacing between edges. 29 | feedbackEdges: false, // Whether feedback edges should be highlighted by routing around the nodes. 30 | fixedAlignment: 'NONE', // Tells the BK node placer to use a certain alignment instead of taking the optimal result. This option should usually be left alone. 31 | /* NONE Chooses the smallest layout from the four possible candidates. 32 | LEFTUP Chooses the left-up candidate from the four possible candidates. 33 | RIGHTUP Chooses the right-up candidate from the four possible candidates. 34 | LEFTDOWN Chooses the left-down candidate from the four possible candidates. 35 | RIGHTDOWN Chooses the right-down candidate from the four possible candidates. 36 | BALANCED Creates a balanced layout from the four possible candidates. */ 37 | inLayerSpacingFactor: 1.0, // Factor by which the usual spacing is multiplied to determine the in-layer spacing between objects. 38 | layoutHierarchy: false, // Whether the selected layouter should consider the full hierarchy 39 | linearSegmentsDeflectionDampening: 0.3, // Dampens the movement of nodes to keep the diagram from getting too large. 40 | mergeEdges: false, // Edges that have no ports are merged so they touch the connected nodes at the same points. 41 | mergeHierarchyCrossingEdges: true, // If hierarchical layout is active, hierarchy-crossing edges use as few hierarchical ports as possible. 42 | nodeLayering:'NETWORK_SIMPLEX', // Strategy for node layering. 43 | /* NETWORK_SIMPLEX This algorithm tries to minimize the length of edges. This is the most computationally intensive algorithm. The number of iterations after which it aborts if it hasn't found a result yet can be set with the Maximal Iterations option. 44 | LONGEST_PATH A very simple algorithm that distributes nodes along their longest path to a sink node. 45 | INTERACTIVE Distributes the nodes into layers by comparing their positions before the layout algorithm was started. The idea is that the relative horizontal order of nodes as it was before layout was applied is not changed. This of course requires valid positions for all nodes to have been set on the input graph before calling the layout algorithm. The interactive node layering algorithm uses the Interactive Reference Point option to determine which reference point of nodes are used to compare positions. */ 46 | nodePlacement:'BRANDES_KOEPF', // Strategy for Node Placement 47 | /* BRANDES_KOEPF Minimizes the number of edge bends at the expense of diagram size: diagrams drawn with this algorithm are usually higher than diagrams drawn with other algorithms. 48 | LINEAR_SEGMENTS Computes a balanced placement. 49 | INTERACTIVE Tries to keep the preset y coordinates of nodes from the original layout. For dummy nodes, a guess is made to infer their coordinates. Requires the other interactive phase implementations to have run as well. 50 | SIMPLE Minimizes the area at the expense of... well, pretty much everything else. */ 51 | randomizationSeed: 1, // Seed used for pseudo-random number generators to control the layout algorithm; 0 means a new seed is generated 52 | routeSelfLoopInside: false, // Whether a self-loop is routed around or inside its node. 53 | separateConnectedComponents: true, // Whether each connected component should be processed separately 54 | spacing: 20, // Overall setting for the minimal amount of space to be left between objects 55 | thoroughness: 7 // How much effort should be spent to produce a nice layout.. 56 | }, 57 | priority: function( edge ){ return null; }, // Edges with a non-nil value are skipped when greedy edge cycle breaking is enabled 58 | }; -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 5 | */ 6 | 7 | import App from './App.svelte'; 8 | 9 | const app = new App({ 10 | target: document.body, 11 | props: { 12 | 13 | } 14 | }); 15 | 16 | export default app; -------------------------------------------------------------------------------- /src/main.scss: -------------------------------------------------------------------------------- 1 | /*! bulmaswatch v0.8.1 | MIT License */ 2 | @import "../node_modules/bulmaswatch/slate/_variables.scss"; 3 | @import "../node_modules/bulma/bulma.sass"; 4 | @import "../node_modules/bulmaswatch/slate/_overrides.scss"; 5 | 6 | html { 7 | overflow-y: auto; 8 | } 9 | 10 | .cy-panzoom { 11 | position: absolute; 12 | font-size: 12px; 13 | color: #fff; 14 | font-family: arial, helvetica, sans-serif; 15 | line-height: 1; 16 | color: #666; 17 | font-size: 11px; 18 | z-index: 99999; 19 | box-sizing: content-box; 20 | } 21 | 22 | .cy-panzoom-zoom-button { 23 | cursor: pointer; 24 | padding: 3px; 25 | text-align: center; 26 | position: absolute; 27 | border-radius: 3px; 28 | width: 10px; 29 | height: 10px; 30 | left: 16px; 31 | background: #fff; 32 | border: 1px solid #999; 33 | margin-left: -1px; 34 | margin-top: -1px; 35 | z-index: 1; 36 | box-sizing: content-box; 37 | } 38 | 39 | .cy-panzoom-zoom-button:active, 40 | .cy-panzoom-slider-handle:active, 41 | .cy-panzoom-slider-handle.active { 42 | background: #ddd; 43 | box-sizing: content-box; 44 | } 45 | 46 | .cy-panzoom-pan-button { 47 | position: absolute; 48 | z-index: 1; 49 | height: 16px; 50 | width: 16px; 51 | box-sizing: content-box; 52 | } 53 | 54 | .cy-panzoom-reset { 55 | top: 55px; 56 | box-sizing: content-box; 57 | } 58 | 59 | .cy-panzoom-zoom-in { 60 | top: 80px; 61 | box-sizing: content-box; 62 | } 63 | 64 | .cy-panzoom-zoom-out { 65 | top: 197px; 66 | box-sizing: content-box; 67 | } 68 | 69 | .cy-panzoom-pan-up { 70 | top: 0; 71 | left: 50%; 72 | margin-left: -5px; 73 | width: 0; 74 | height: 0; 75 | border-left: 5px solid transparent; 76 | border-right: 5px solid transparent; 77 | border-bottom: 5px solid #666; 78 | box-sizing: content-box; 79 | } 80 | 81 | .cy-panzoom-pan-down { 82 | bottom: 0; 83 | left: 50%; 84 | margin-left: -5px; 85 | width: 0; 86 | height: 0; 87 | border-left: 5px solid transparent; 88 | border-right: 5px solid transparent; 89 | border-top: 5px solid #666; 90 | box-sizing: content-box; 91 | } 92 | 93 | .cy-panzoom-pan-left { 94 | top: 50%; 95 | left: 0; 96 | margin-top: -5px; 97 | width: 0; 98 | height: 0; 99 | border-top: 5px solid transparent; 100 | border-bottom: 5px solid transparent; 101 | border-right: 5px solid #666; 102 | box-sizing: content-box; 103 | } 104 | 105 | .cy-panzoom-pan-right { 106 | top: 50%; 107 | right: 0; 108 | margin-top: -5px; 109 | width: 0; 110 | height: 0; 111 | border-top: 5px solid transparent; 112 | border-bottom: 5px solid transparent; 113 | border-left: 5px solid #666; 114 | box-sizing: content-box; 115 | } 116 | 117 | .cy-panzoom-pan-indicator { 118 | position: absolute; 119 | left: 0; 120 | top: 0; 121 | width: 8px; 122 | height: 8px; 123 | border-radius: 8px; 124 | background: #000; 125 | border-radius: 8px; 126 | margin-left: -5px; 127 | margin-top: -5px; 128 | display: none; 129 | z-index: 999; 130 | opacity: 0.6; 131 | box-sizing: content-box; 132 | } 133 | 134 | .cy-panzoom-slider { 135 | position: absolute; 136 | top: 97px; 137 | left: 17px; 138 | height: 100px; 139 | width: 15px; 140 | box-sizing: content-box; 141 | } 142 | 143 | .cy-panzoom-slider-background { 144 | position: absolute; 145 | top: 0; 146 | width: 2px; 147 | height: 100px; 148 | left: 5px; 149 | background: #fff; 150 | border-left: 1px solid #999; 151 | border-right: 1px solid #999; 152 | box-sizing: content-box; 153 | } 154 | 155 | .cy-panzoom-slider-handle { 156 | position: absolute; 157 | width: 16px; 158 | height: 8px; 159 | background: #fff; 160 | border: 1px solid #999; 161 | border-radius: 2px; 162 | margin-left: -2px; 163 | z-index: 999; 164 | line-height: 8px; 165 | cursor: default; 166 | box-sizing: content-box; 167 | } 168 | 169 | .cy-panzoom-slider-handle .icon { 170 | margin: 0 4px; 171 | line-height: 10px; 172 | box-sizing: content-box; 173 | } 174 | 175 | .cy-panzoom-no-zoom-tick { 176 | position: absolute; 177 | background: #666; 178 | border: 1px solid #fff; 179 | border-radius: 2px; 180 | margin-left: -1px; 181 | width: 8px; 182 | height: 2px; 183 | left: 3px; 184 | z-index: 1; 185 | margin-top: 3px; 186 | box-sizing: content-box; 187 | } 188 | 189 | .cy-panzoom-panner { 190 | position: absolute; 191 | left: 5px; 192 | top: 5px; 193 | height: 40px; 194 | width: 40px; 195 | background: #fff; 196 | border: 1px solid #999; 197 | border-radius: 40px; 198 | margin-left: -1px; 199 | box-sizing: content-box; 200 | } 201 | 202 | .cy-panzoom-panner-handle { 203 | position: absolute; 204 | left: 0; 205 | top: 0; 206 | outline: none; 207 | height: 40px; 208 | width: 40px; 209 | position: absolute; 210 | z-index: 999; 211 | box-sizing: content-box; 212 | } 213 | 214 | .cy-panzoom-zoom-only .cy-panzoom-slider, 215 | .cy-panzoom-zoom-only .cy-panzoom-panner { 216 | display: none; 217 | } 218 | 219 | .cy-panzoom-zoom-only .cy-panzoom-reset { 220 | top: 20px; 221 | } 222 | 223 | .cy-panzoom-zoom-only .cy-panzoom-zoom-in { 224 | top: 45px; 225 | } 226 | 227 | .cy-panzoom-zoom-only .cy-panzoom-zoom-out { 228 | top: 70px; 229 | } 230 | 231 | .icon { 232 | width: unset; 233 | height: unset; 234 | } -------------------------------------------------------------------------------- /src/prevent_navigation.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 5 | */ 6 | 7 | import { unsaved } from "./store"; 8 | import { get } from "svelte/store"; 9 | 10 | export default function (eventName = "input", message = "Changes you made may not be saved. Are you sure?") { 11 | // the action 12 | function action(node) { 13 | function markUnsaved() { 14 | unsaved.set(true); 15 | } 16 | function checkNavigation(e) { 17 | if (get(unsaved)) { 18 | if (!confirm(message)) { 19 | e.preventDefault(); 20 | if (e.type === "beforeunload") { 21 | e.returnValue = ""; 22 | } 23 | } 24 | } 25 | } 26 | for (let a of document.querySelectorAll("a[href]")) { 27 | a.addEventListener("click", checkNavigation); 28 | } 29 | window.addEventListener("beforeunload", checkNavigation); 30 | node.addEventListener(eventName, markUnsaved); 31 | return { 32 | destory() { 33 | node.removeEventListener("input", markUnsaved); 34 | for (let a of document.querySelectorAll("a[href]")) { 35 | a.removeEventListener("click", checkNavigation); 36 | } 37 | window.removeEventListener("beforeunload", checkNavigation); 38 | }, 39 | }; 40 | } 41 | return { action }; 42 | } -------------------------------------------------------------------------------- /src/providers.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 5 | */ 6 | 7 | import { providerSchemas } from "./store"; 8 | import {tfSchema} from "./tfSchema"; 9 | 10 | export async function getProviders(providerChoices) { 11 | let official = await fetch("https://raw.githubusercontent.com/badarsebard/terraform-schemas/main/schemas/manifest.official.txt").then(r => response2array(r)); 12 | let partner = await fetch("https://raw.githubusercontent.com/badarsebard/terraform-schemas/main/schemas/manifest.partner.txt").then(r => response2array(r)); 13 | let community = await fetch("https://raw.githubusercontent.com/badarsebard/terraform-schemas/main/schemas/manifest.community.txt").then(r => response2array(r)); 14 | for (const p of official) { 15 | let pId = generateUID(); 16 | let gitName = p.replace("/", "_") 17 | let name = p.split("/")[1] 18 | providerChoices[pId] = {gitname: gitName, type: "official", fullname: p, name: name}; 19 | } 20 | for (const p of partner) { 21 | let pId = generateUID(); 22 | let gitName = p.replace("/", "_") 23 | let name = p.split("/")[1] 24 | providerChoices[pId] = {gitname: gitName, type: "partner", fullname: p, name: name}; 25 | } 26 | for (const p of community) { 27 | let pId = generateUID(); 28 | let gitName = p.replace("/", "_") 29 | let name = p.split("/")[1] 30 | providerChoices[pId] = {gitname: gitName, type: "community", fullname: p, name: name}; 31 | } 32 | // providerChoices.sort((f, s) => {if (f.name < s.name){return -1} else {return 1}}) 33 | } 34 | function generateUID() { 35 | let firstPart = (Math.random() * 46656) | 0; 36 | let secondPart = (Math.random() * 46656) | 0; 37 | firstPart = ("000" + firstPart.toString(36)).slice(-3); 38 | secondPart = ("000" + secondPart.toString(36)).slice(-3); 39 | return firstPart + secondPart; 40 | } 41 | async function response2array(r) { 42 | let ret = await r.blob(); 43 | ret = await ret.text(); 44 | ret = await ret.trim(); 45 | ret = await ret.split("\n") 46 | return ret 47 | } 48 | export function parseProviderSchema(data) { 49 | for (const pr in data.provider_schemas) { 50 | let p = pr.replace("registry.terraform.io/", ""); 51 | providerSchemas.update(n => { 52 | let x = {...n}; 53 | x[p] = { 54 | provider: data.provider_schemas[pr].provider, 55 | resource_schemas: data.provider_schemas[pr].resource_schemas, 56 | data_source_schemas: data.provider_schemas[pr].data_source_schemas 57 | }; 58 | return x 59 | }); 60 | } 61 | } 62 | 63 | export async function setProviders(s, sp, pc) { 64 | providerSchemas.set({ 65 | terraform: { 66 | provider: { 67 | block: tfSchema 68 | } 69 | } 70 | }); 71 | s = undefined; 72 | // create json frame 73 | let data = { 74 | format_version: "0.2", 75 | provider_schemas: {} 76 | } 77 | // iterate through selected providerSchemas 78 | for (const p of sp) { 79 | // grab the schema from github 80 | let pChoice = pc[p] 81 | let schema = await fetch(`https://raw.githubusercontent.com/badarsebard/terraform-schemas/main/schemas/${pChoice.type}/${pChoice.gitname}.json`).then(r => r.json()) 82 | // attach to frame 83 | data.provider_schemas[`registry.terraform.io/${pChoice.fullname}`] = schema.provider_schemas[`registry.terraform.io/${pChoice.fullname}`]; 84 | } 85 | parseProviderSchema(data); 86 | } 87 | -------------------------------------------------------------------------------- /src/store.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 5 | */ 6 | 7 | import { writable } from 'svelte/store'; 8 | import {tfSchema} from "./tfSchema"; 9 | export let resources = writable([]); 10 | export let providerSchemas = writable({ 11 | terraform: { 12 | provider: { 13 | block: tfSchema 14 | } 15 | } 16 | }); 17 | export let unsaved = writable(false); 18 | export let editNode = writable(); 19 | export let editorOn = writable(false); 20 | export let cy = writable(); 21 | export let hclVariables = writable([]); 22 | export let hclOutputs = writable([]); 23 | export let hclLocals = writable([]); -------------------------------------------------------------------------------- /src/tfSchema.js: -------------------------------------------------------------------------------- 1 | export const tfSchema = { 2 | attributes: { 3 | required_version: { 4 | type: "string", 5 | description_kind: "plain", 6 | optional: true 7 | }, 8 | experiments: { 9 | type: [ 10 | "list", 11 | "string" 12 | ], 13 | description_kind: "plain", 14 | optional: true 15 | } 16 | }, 17 | block_types: { 18 | backend: { 19 | nesting_mode: "single", 20 | block: { 21 | max_items: 1 22 | } 23 | }, 24 | required_providers: { 25 | nesting_mode: "single", 26 | block: { 27 | max_items: 1 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 5 | */ 6 | 7 | import {resources, unsaved, editorOn, editNode, cy, providerSchemas, hclVariables, hclOutputs, hclLocals} from "./store"; 8 | import cytoscape from "cytoscape"; 9 | import panzoom from 'cytoscape-panzoom'; 10 | import {options} from "./klay"; 11 | 12 | function pushMatches(matches, nodeIdMap, node, edgeIds, edges) { 13 | for (const match of matches) { 14 | let source = nodeIdMap[match[1]]; 15 | if (source) { 16 | let edgeId = source+"|"+node.id(); 17 | let edge = { 18 | group: 'edges', 19 | data: { 20 | source: source, 21 | target: node.id() 22 | } 23 | }; 24 | if (!edgeIds.includes(edgeId)){ 25 | edgeIds.push(edgeId); 26 | edges.push(edge); 27 | } 28 | } 29 | } 30 | } 31 | 32 | export async function computeEdges(r) { 33 | let edges = []; 34 | let edgeIds = []; 35 | let nodeIdMap = {}; 36 | const regexp = /\$((?:data.\w+|\w+)\.\w+)/gm; 37 | for (const node of r) { 38 | let data = node.data(); 39 | if (data.type === "provider") { 40 | continue 41 | } 42 | let dataPrefix = data.tf.stanzaType === "resource" ? "" : "data." 43 | if (data) { 44 | nodeIdMap[`${dataPrefix}${data.tf.type}.${data.tf.stanzaName}`] = node.id(); 45 | } 46 | } 47 | for (const node of r) { 48 | let data = node.data(); 49 | if (data.type === "provider") { 50 | continue 51 | } 52 | let config = data.tf.config 53 | for (const attr in config.attributes) { 54 | const matches = [...config.attributes[attr].matchAll(regexp)]; 55 | pushMatches(matches, nodeIdMap, node, edgeIds, edges) 56 | } 57 | for (const block in config.blocks) { 58 | switch (typeof config.blocks[block]) { 59 | case "string": 60 | const matches = [...config.blocks[block].matchAll(regexp)]; 61 | pushMatches(matches, nodeIdMap, node, edgeIds, edges) 62 | break; 63 | case "object": 64 | switch (Array.isArray(config.blocks[block])) { 65 | case true: 66 | for (const blocki of config.blocks[block]) { 67 | const matches = [...blocki.matchAll(regexp)]; 68 | pushMatches(matches, nodeIdMap, node, edgeIds, edges) 69 | } 70 | break; 71 | 72 | case false: 73 | for (const block_name in config.blocks[block]) { 74 | const matches = [...config.blocks[block][block_name].matchAll(regexp)] 75 | pushMatches(matches, nodeIdMap, node, edgeIds, edges) 76 | } 77 | break; 78 | } 79 | break; 80 | } 81 | } 82 | } 83 | let cyObj; 84 | cy.subscribe(value => cyObj = value); 85 | cyObj.remove("edge"); 86 | cyObj.add(edges); 87 | } 88 | 89 | export function saveDesign() { 90 | let cyObj; 91 | cy.subscribe(value => cyObj = value); 92 | let data = JSON.stringify(cyObj.json()); 93 | let file = new File([data], "terraforge.json", { 94 | type: "application/json", 95 | }); 96 | const link = document.createElement("a"); 97 | link.style.display = "none"; 98 | link.href = URL.createObjectURL(file); 99 | link.download = file.name; 100 | document.body.appendChild(link); 101 | link.click(); 102 | setTimeout(() => { 103 | URL.revokeObjectURL(link.href); 104 | link.parentNode.removeChild(link); 105 | }, 0); 106 | unsaved.set(false); 107 | } 108 | 109 | export function startCy() { 110 | // the default values of each option are outlined below: 111 | let defaults = { 112 | zoomFactor: 0.05, // zoom factor per zoom tick 113 | zoomDelay: 45, // how many ms between zoom ticks 114 | minZoom: 0.1, // min zoom level 115 | maxZoom: 10, // max zoom level 116 | fitPadding: 50, // padding when fitting 117 | panSpeed: 10, // how many ms in between pan ticks 118 | panDistance: 10, // max pan distance per tick 119 | panDragAreaSize: 75, // the length of the pan drag box in which the vector for panning is calculated (bigger = finer control of pan speed and direction) 120 | panMinPercentSpeed: 0.25, // the slowest speed we can pan by (as a percent of panSpeed) 121 | panInactiveArea: 8, // radius of inactive area in pan drag box 122 | panIndicatorMinOpacity: 0.5, // min opacity of pan indicator (the draggable nib); scales from this to 1.0 123 | zoomOnly: false, // a minimal version of the ui only with zooming (useful on systems with bad mousewheel resolution) 124 | fitSelector: undefined, // selector of elements to fit 125 | animateOnFit: function(){ // whether to animate on fit 126 | return false; 127 | }, 128 | fitAnimationDuration: 1000, // duration of animation on fit 129 | 130 | // icon class names 131 | sliderHandleIcon: 'fa fa-minus', 132 | zoomInIcon: 'fa fa-plus', 133 | zoomOutIcon: 'fa fa-minus', 134 | resetIcon: 'fa fa-expand' 135 | }; 136 | panzoom( cytoscape ); 137 | let cyto = cytoscape({ 138 | container: document.getElementById('cy'), 139 | layout: {name: 'klay'}, 140 | style: [ 141 | { 142 | selector: 'node', 143 | style: { 144 | label: tfName, 145 | 'text-halign': 'center', 146 | 'text-valign': 'bottom', 147 | 'background-color': '#81007B', 148 | 'color': '#aaa' 149 | } 150 | }, 151 | { 152 | selector: 'node[type = "provider"]', 153 | style: { 154 | 'display': 'none' 155 | } 156 | }, 157 | { 158 | selector: 'edge', 159 | style: { 160 | 'target-arrow-shape': 'triangle', 161 | 'curve-style': 'bezier', 162 | 'line-color': '#81007B', 163 | 'target-arrow-color': '#81007B' 164 | } 165 | }, 166 | { 167 | selector: ':selected', 168 | style: { 169 | 'background-color': 'blue' 170 | } 171 | } 172 | ] 173 | }); 174 | cyto.panzoom( defaults ); 175 | cyto.on('tap', 'node', function (evt) { 176 | editNode.set(evt.target); 177 | editorOn.set(true); 178 | let res; 179 | resources.subscribe(value => res = value) 180 | computeEdges(res, cyto); 181 | }); 182 | cyto.on('data', 'node', function () { 183 | let res; 184 | resources.subscribe(value => res = value) 185 | computeEdges(res, cyto); 186 | }); 187 | cyto.on('tap', function (event) { 188 | let evtTarget = event.target; 189 | if (evtTarget === cyto) { 190 | editorOn.set(false); 191 | editNode.set(null); 192 | } 193 | }); 194 | return cyto 195 | } 196 | 197 | export function createResource(r) { 198 | // { 199 | // type: stanzaType, 200 | // tf: { 201 | // provider: providerName, 202 | // stanzaType: stanzaType, 203 | // type: resourceType, 204 | // config: { 205 | // attributes: {}, 206 | // blocks: {} 207 | // }, 208 | // stanzaName: "" 209 | // } 210 | // } 211 | let cyObj; 212 | cy.subscribe(value => cyObj = value); 213 | if (r.type === 'provider') { 214 | r['id'] = r.tf.provider; 215 | } 216 | let n = cyObj.add({ 217 | group: "nodes", 218 | data: r, 219 | }); 220 | resources.update(r => [...r, n[0]]); 221 | cyObj.layout(options).run(); 222 | } 223 | 224 | const attributePattern = /(?(?\w+) (?{[\s\S]+?^ {2}}))|(?(?\w+)\s+=\s+(?{[\s\S]+?}|[\S ]+))/gm; 225 | export function createTerraformBlockResource(r) { 226 | let schemas; 227 | providerSchemas.subscribe(value => schemas = value); 228 | let rr = { 229 | type: 'provider', 230 | tf: { 231 | provider: "terraform", 232 | stanzaType: "provider", 233 | type: "terraform", 234 | config: { 235 | attributes: {}, 236 | blocks: {} 237 | }, 238 | stanzaName: "" 239 | } 240 | } 241 | const attr = [...r.groups.stanzaConfig.matchAll(attributePattern)] 242 | for (const a of attr) { 243 | if (a.groups.block) { 244 | let aSchema = schemas.terraform.provider.block.block_types[a.groups.blockName]; 245 | let nm = aSchema.nesting_mode; 246 | if (nm === "single") { 247 | rr.tf.config.blocks[a.groups.blockName] = [a.groups.blockConfig]; 248 | } else if (nm === 'list' || nm === 'set') { 249 | rr.tf.config.blocks[a.groups.blockName] ??= []; 250 | if (rr.tf.config.blocks[a.groups.blockName].length < aSchema.max_items) { 251 | rr.tf.config.blocks[a.groups.blockName] = rr.tf.config.blocks[a.groups.blockName].concat([a.groups.blockConfig]); 252 | } 253 | } 254 | } else { 255 | rr.tf.config.attributes[a.groups.attributeName] = a.groups.attributeValue; 256 | } 257 | } 258 | createResource(rr); 259 | } 260 | export function createProviderBlockResource(r, hclProviderMap) { 261 | let schemas; 262 | providerSchemas.subscribe(value => schemas = value); 263 | let provider = r.groups.resourceType.replaceAll('"', "") 264 | let fullprovider = hclProviderMap[provider]; 265 | let rr = { 266 | type: 'provider', 267 | tf: { 268 | provider: fullprovider, 269 | stanzaType: "provider", 270 | type: fullprovider, 271 | config: { 272 | attributes: {}, 273 | blocks: {} 274 | }, 275 | stanzaName: "" 276 | } 277 | } 278 | const attr = [...r.groups.stanzaConfig.matchAll(attributePattern)] 279 | for (const a of attr) { 280 | if (a.groups.block) { 281 | let aSchema = schemas[fullprovider].provider.block.block_types[a.groups.blockName]; 282 | let nm = aSchema.nesting_mode 283 | if (nm === "single") { 284 | rr.tf.config.blocks[a.groups.blockName] = [a.groups.blockConfig] 285 | } else if (nm === 'list' || nm === 'set') { 286 | rr.tf.config.blocks[a.groups.blockName] ??= []; 287 | if (rr.tf.config.blocks[a.groups.blockName].length < aSchema.max_items) { 288 | rr.tf.config.blocks[a.groups.blockName] = rr.tf.config.blocks[a.groups.blockName].concat([a.groups.blockConfig]); 289 | } 290 | } 291 | } else { 292 | rr.tf.config.attributes[a.groups.attributeName] = a.groups.attributeValue; 293 | } 294 | } 295 | createResource(rr); 296 | } 297 | export function createVariableResource(r) { 298 | const attr = [...r.groups.stanzaConfig.matchAll(attributePattern)] 299 | let v = {name: r.groups.resourceType, default: "", type: "", description: "", validation: "", sensitive: false} 300 | for (const a of attr) { 301 | if (a.groups.block) { 302 | if (a.groups.blockName === "validation") { 303 | v.validation = a.groups.blockConfig 304 | } 305 | } else { 306 | v[a.groups.attributeName] = a.groups.attributeValue; 307 | } 308 | } 309 | hclVariables.update(r => [...r, v]); 310 | } 311 | export function createOutputResource(r) { 312 | const attr = [...r.groups.stanzaConfig.matchAll(attributePattern)] 313 | // {name: "", value: "", description: "", sensitive: false, depends_on: ""} 314 | let o = {name: r.groups.resourceType, value: "", description: "", sensitive: false, depends_on: ""} 315 | for (const a of attr) { 316 | o[a.groups.attributeName] = a.groups.attributeValue; 317 | } 318 | hclOutputs.update(r => [...r, o]); 319 | } 320 | 321 | export function addLocalResource(r) { 322 | const attr = [...r.groups.stanzaConfig.matchAll(attributePattern)] 323 | for (const a of attr) { 324 | hclLocals.update(r => [...r, {name: a.groups.attributeName, value: a.groups.attributeValue}]); 325 | } 326 | } 327 | 328 | export function createResourceOrDataBlockResource(r, hclProviderMap) { 329 | let schemas; 330 | providerSchemas.subscribe(value => schemas = value); 331 | let provider = r.groups.resourceType.split("_")[0].replaceAll('"', "") 332 | let fullprovider = hclProviderMap[provider]; 333 | let blockType = r.groups.blockType === "resource" ? "resource" : "data_source"; 334 | let resourceType = r.groups.resourceType.replaceAll('"', ""); 335 | let stanzaName = r.groups.stanzaName.replaceAll('"', ""); 336 | let rr = { 337 | type: blockType, 338 | tf: { 339 | provider: fullprovider, 340 | stanzaType: blockType, 341 | type: resourceType, 342 | config: { 343 | attributes: {}, 344 | blocks: {} 345 | }, 346 | stanzaName: stanzaName 347 | } 348 | } 349 | const attr = [...r.groups.stanzaConfig.matchAll(attributePattern)] 350 | let schemaName = blockType === "resource" ? "resource_schemas" : "data_source_schemas"; 351 | for (const a of attr) { 352 | if (a.groups.block) { 353 | let blockName = a.groups.blockName; 354 | let blockConfig = a.groups.blockConfig 355 | let aSchema = schemas[fullprovider][schemaName][resourceType].block.block_types[blockName]; 356 | let nm = aSchema.nesting_mode 357 | if (nm === "single") { 358 | rr.tf.config.blocks[blockName] = [blockConfig] 359 | } else if (nm === 'list' || nm === 'set') { 360 | rr.tf.config.blocks[blockName] ??= []; 361 | if (rr.tf.config.blocks[blockName].length < aSchema.max_items) { 362 | rr.tf.config.blocks[blockName] = rr.tf.config.blocks[blockName].concat([blockConfig]); 363 | } 364 | } 365 | } else { 366 | rr.tf.config.attributes[a.groups.attributeName] = a.groups.attributeValue; 367 | } 368 | } 369 | createResource(rr); 370 | } 371 | 372 | export function tfName(ele) { 373 | let data = ele.data(); 374 | let type = data.tf.type; 375 | let stanzaType = data.tf.stanzaType; 376 | let stanzaName = data.tf.stanzaName; 377 | if (stanzaName === "") { 378 | return stanzaType === "resource" ? type : `data.${type}` 379 | } else { 380 | return stanzaType === "resource" ? `${type}.${stanzaName}` : `data.${type}.${stanzaName}` 381 | } 382 | } --------------------------------------------------------------------------------