The AWS Terraform Generator is a powerful tool designed to simplify and streamline the process of creating Terraform configurations for AWS infrastructure. With this tool, you can quickly generate Terraform code to provision AWS resources such as EC2 instances, S3 buckets, RDS databases, Lambda functions, API Gateways, and much more.
Table of contents
$ go install github.com/joselitofilho/aws-terraform-generator@latest
$ aws-terraform-generator --workdir ./example
$ aws-terraform-generator draw -c ./example/draw.config.yaml --workdir ./output/mystack -o .
$ aws-terraform-generator diff -l ./example/diagram_original.yaml -r ./example/diagram.yaml
The code generator already comes with some pre-configured templates for generating Terraform and GoLang files. All generator configuration is based on YAML files, making it easy to customize the available resources and templates.
The first step is to write the configuration file specified here. You can also use this example as a reference.
There you go! Now you can generate the structure of your project or the files based on the configured resources. You can execute the commands in any order.
If you're using Diagrams, you can also generate the initial configuration file based on the XML generated by the tool.
If you have any questions or suggestions, go to the Contributing section. Your contribution is much appreciated.
Step 1: Create a folder to organize the diagram and configuration files, ideally named after your stack.
$ mkdir mystack
Step 2: Create your diagram using Diagrams. If you have already created one, proceed to the next step.
Step 3: Export and download your diagram as an XML file (file name suggestion: diagram.xml
).
You can find instructions on how to do that at this link: https://www.drawio.com/doc/faq/export-to-xml.
Move the file to the folder created in the Step 1.
$ mv ~/Downloads/diagram.xml mystack/diagram.xml
Step 4: Create the diagram configuration file.
Suggestion diagram.config.yaml:
$ cp ./example/diagram.config.yaml mystack/diagram.config.yaml
Change the values according to your project.
Step 5: Create the structure configuration file.
Suggestion structure.config.yaml:
$ cp ./example/structure.config.yaml mystack/structure.config.yaml
Step 6: Run the generator guide to assist you.
$ aws-terraform-generator --workdir mystack
Output:
██████╗ ██████╗ ██████╗ ███████╗ ██████╗ ███████╗███╗ ██╗
██╔════╝██╔═══██╗██╔══██╗██╔════╝ ██╔════╝ ██╔════╝████╗ ██║
██║ ██║ ██║██║ ██║█████╗ ██║ ███╗█████╗ ██╔██╗ ██║
██║ ██║ ██║██║ ██║██╔══╝ ██║ ██║██╔══╝ ██║╚██╗██║
╚██████╗╚██████╔╝██████╔╝███████╗ ╚██████╔╝███████╗██║ ╚████║
╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝
AWS
? What would you like to do? [Use arrows to move, type to filter]
> Generate a diagram config file
Generate the initial structure
Generate code
Exit
To use these configurations:
main.tf
, vars.tf
, etc.) according to your requirements.User guide:
$ aws-terraform-generator --workdir ./example
Or use commands:
$ aws-terraform-generator diagram -c ./example/diagram.config.yaml -d ./example/diagram.xml -o ./example/diagram.yaml
$ aws-terraform-generator structure -c ./example/structure.config.yaml -o ./output
$ aws-terraform-generator apigateway -c ./example/diagram.yaml -o ./output
$ aws-terraform-generator lambda -c ./example/diagram.yaml -o ./output/mystack
$ aws-terraform-generator kinesis -c ./example/diagram.yaml -o ./output/mystack
$ aws-terraform-generator sqs -c ./example/diagram.yaml -o ./output/mystack
$ aws-terraform-generator s3 -c ./example/diagram.yaml -o ./output/mystack
All you need know regarding configuration you can find in the configuration section.
For code generation, we are using the standard Golang library text/template. Further details about the available variables and the definition of some added utility functions can be found in the template section.
Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to create an issue or submit a pull request. Your contribution is much appreciated. See Contributing.
This project is licensed under the MIT License.