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.
![Start Here](https://img.shields.io/badge/start%20here-blue?style=for-the-badge)
Table of contents
Install
$ go install github.com/joselitofilho/aws-terraform-generator/cmd/aws-terraform-generator@latest
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:
██████╗ ██████╗ ██████╗ ███████╗ ██████╗ ███████╗███╗ ██╗
██╔════╝██╔═══██╗██╔══██╗██╔════╝ ██╔════╝ ██╔════╝████╗ ██║
██║ ██║ ██║██║ ██║█████╗ ██║ ███╗█████╗ ██╔██╗ ██║
██║ ██║ ██║██║ ██║██╔══╝ ██║ ██║██╔══╝ ██║╚██╗██║
╚██████╗╚██████╔╝██████╔╝███████╗ ╚██████╔╝███████╗██║ ╚████║
╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝
? 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 -s mystack -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.
![open - Configuration](https://img.shields.io/badge/open-configuration-blue?style=for-the-badge)
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.
![open - Template](https://img.shields.io/badge/open-template-blue?style=for-the-badge)
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.