aws-terraform-generator

module
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2024 License: MIT

README

AWS Terraform Generator

GitHub tag Go Report Card Code coverage

Made with Golang Using Terraform Using Diagrams

BuyMeACoffee

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

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
    • Kinesis streams
    • Lambda
    • Restful API
    • SNS
    • SQS with DLQ
    • S3

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, feel free to create an issue. 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:



                 ██████╗ ██████╗ ██████╗ ███████╗     ██████╗ ███████╗███╗   ██╗
                ██╔════╝██╔═══██╗██╔══██╗██╔════╝    ██╔════╝ ██╔════╝████╗  ██║
                ██║     ██║   ██║██║  ██║█████╗      ██║  ███╗█████╗  ██╔██╗ ██║
                ██║     ██║   ██║██║  ██║██╔══╝      ██║   ██║██╔══╝  ██║╚██╗██║
                ╚██████╗╚██████╔╝██████╔╝███████╗    ╚██████╔╝███████╗██║ ╚████║
                 ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝     ╚═════╝ ╚══════╝╚═╝  ╚═══╝


? 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:

  1. Navigate to the desired stack/environment folder.
  2. Customize the Terraform files (main.tf, vars.tf, etc.) according to your requirements.
  3. Run commands to manage the infrastructure.
$ aws-terraform-generator diagram -s mystack -c examples/diagram.config.yaml -d examples/diagram.drawio.xml -o examples/mystack.yaml
$ aws-terraform-generator structure -c examples/structure.yaml -o ./output
$ aws-terraform-generator apigateway -c examples/mystack.yaml -o ./output
$ aws-terraform-generator lambda -c examples/mystack.yaml -o ./output/mystack
$ aws-terraform-generator kinesis -c examples/mystack.yaml -o output/mystack
$ aws-terraform-generator s3 -c examples/mystack.yaml -o output/mystack
$ aws-terraform-generator sns -c examples/mystack.yaml -o output/mystack
$ aws-terraform-generator sqs -c examples/mystack.yaml -o output/mystack
$ aws-terraform-generator --workdir ./examples

Configuration

All you need know regarding configuration you can find in the configuration section.

open - Configuration

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

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.

License

This project is licensed under the MIT License.

Directories

Path Synopsis
cmd
internal
drawio
package drawio provides functionality to parse resources from a draw.io XML file.
package drawio provides functionality to parse resources from a draw.io XML file.
survey
Package survey is a generated GoMock package.
Package survey is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL