generator-terraform-environments v0.6.0
generator-terraform-environments

Scaffolding used to create infrastructure environments using Terraform
Installation
First, install Yeoman and generator-terraform-environments using npm (we assume you have pre-installed node.js).
npm install -g yo
npm install -g generator-terraform-environmentsThen generate your new project, answering the prompts as required:
yo terraform-environmentsUsage
After creating your scaffolding, you should have a folder structure similar to the following:
.
├── environments
│ ├── production
│ │ ├── compute
│ │ │ ├── compute.tf
│ │ │ ├── input.tf
│ │ │ ├── output.tf
│ │ │ └── terraform.tfvars
│ │ ├── core
│ │ │ ├── core.tf
│ │ │ ├── input.tf
│ │ │ ├── output.tf
│ │ │ └── terraform.tfvars
│ │ └── data
│ │ ├── data.tf
│ │ ├── input.tf
│ │ ├── output.tf
│ │ └── terraform.tfvars
│ └── test
│ ├── compute
│ │ ├── compute.tf
│ │ ├── input.tf
│ │ ├── output.tf
│ │ └── terraform.tfvars
│ ├── core
│ │ ├── core.tf
│ │ ├── input.tf
│ │ ├── output.tf
│ │ └── terraform.tfvars
│ └── data
│ ├── data.tf
│ ├── input.tf
│ ├── output.tf
│ └── terraform.tfvars
└── modules
├── compute
│ ├── compute.tf
│ ├── input.tf
│ └── output.tf
├── core
│ ├── core.tf
│ ├── input.tf
│ └── output.tf
└── data
├── data.tf
├── input.tf
└── output.tfThe above example assumes that there are two environments (production and test), as well as three separate components (core, compute and data)
To configure your component modules:
- Edit
modules/<component>/<component>.tfand add terraform resources, or references to other modules that you need. - Edit
modules/<component>/input.tfand add input parameters that the component module requires. - Edit
modules/<component>/output.tfand add output parameters that are used by other component modules.
To configure your environments:
- Edit
environment/<environment>/<component>/input.tfand add input parameters required by the component module - Edit
environment/<environment>/<component>/terraform.tfvarsand supply values here - Edit
environment/<environment>/<component>/output.tfand add output parameters that are used by other component modules.
To deploy the core component into the test environment:
cd ./environments/test/core
terraform init
terraform applyOnce the deployment is successful, you can rinse and repeat for all your other environments.
Remote State Backends
Currently this code generator supports the following remote state backends:
- s3
- consul
s3
For the s3 backend, you will be asked for the bucket name, a key prefix, as well as the AWS region for the bucket. The key prefix is especially useful if you have to share this bucket with other apps so the state files can be segregated off.
As a pattern, the state files will be stored in s3://<bucket_name>/<key_prefix>/<environment>/<component>/terraform.tfstate
Note: This code generator will not actually create the s3 bucket for you, and you will also need to provision permissions for the s3 bucket (via bucket policies and IAM users/roles) yourself.
Consul
For the consul backend, you will be asked for the consul address (defaults to localhost:8500), as well as the key prefix. The key prefix is especially useful if you have to share the Consul key-value store with other apps so the state files can be segregated off.
As a pattern, the state will be stored in key <key_prefix>/<environment>/<component>
Note: This code generator will not manage permissions such as authentication keys, nor ACLs. You will need to manage and provision the appropriate ACLs yourself.
License
MIT © William Tsoi