A sample AWS project managed by Terraform
This repo is set up to contain everything in a single AWS account.
The top level structure of the repo should look something like the tree below
with each "project" containing some application of shared infrastructure.
Besides the project directories there are a few special ones;
common, which houses code that should be common to every projectmodules, where client-specific modules keptbin, where scripts are kept
repo
│
└───common
│ │ common.tf
│ │ global.auto.tfvars
│
└───modules
│
└───project
│ │ main.tf
| | outputs.tf
│ │ variables.tf
|
| .gitignore
| .pre-commit.yml
| .terraform-version
| README.md
There is a handy setup script at bin/setup.sh which will create a
terraform s3 backend
with locking via DynamoDB and add it's resources to your remote state.
To all the DevOps engineers out there with bosses to impress it's easy to do just follow these steps:
- Install the prerequisites
gitterraform(We use tfenv to manageterraformversions)pre-commitGNUMake
- provide authentication for the aws provider
- Clone the repo:
git clone https://github.com/rhythmictech/sample-aws-project.git terraform-aws-rhythmictech - Update the values for the backend in
account/backend.auto.tfvars - Run the setup with
make setup
To bootsrap the addition of new projects there is a handy shell script,
bin/new-project.sh that does everything needed besides write the code;
- gets the backend variables from the backend
account/backend.auto.tfvarsfile - creates the new folder with a backend, readme, and makefile
- symlinks everything in
commonto the new folder
Once you've made your changes to the terraform code
and want to make those changes in your actual infrastructure you can use make apply to generate
a plan. It will then prompt you to type yes to apply the proposed changes or type literally anything other than yes to exit without applying.