Overview
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
Install
$ go install github.com/joselitofilho/aws-terraform-generator@latest
- graphviz: Graphviz is open source graph visualization software. Graph visualization is a way of representing structural information as diagrams of abstract graphs and networks.
- terraform: Terraform is an infrastructure as code tool that lets you build, change, and version cloud and on-prem resources safely and efficiently.
Features:
- Generate initial stack infrastructure folders.
- Generate GoLang code and Terraform files.
- Diagrams integration: Generate everything based on the exported XML diagram.
- Customization Options: Tailor generated code to your specific requirements using customizable templates and configuration parameters.
- Best Practices: Adhere to AWS and Terraform best practices with automatically generated code that follows industry standards.
- Supported resources:
- APIGateway
- Cron
- Database
- Google BigQuery
- Kinesis streams
- Lambda
- Restful API
- SNS
- SQS with DLQ
- S3
- Generate a diagram based on terraform files.
- Compare and show the difference between two diagrams.
- Everything is customizable.
Code generator
$ aws-terraform-generator --workdir ./example
Generate diagram from code
$ aws-terraform-generator draw -c ./example/draw.config.yaml --workdir ./output/mystack -o .
Compare diagrams
$ aws-terraform-generator diff -l ./example/diagram_original.yaml -r ./example/diagram.yaml
How it works
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.
Recommended step by step
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
Usage
To use these configurations:
- Navigate to the desired stack/environment folder.
- Customize the Terraform files (
main.tf
, vars.tf
, etc.) according to your requirements.
- Run commands to manage the infrastructure.
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
Configuration
All you need know regarding configuration you can find in the configuration section.

Template
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.

Contributing
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.

License
This project is licensed under the MIT License.