Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

rhythmictech/sample-aws-project

Repository files navigation

sample-aws-project

tflint tfsec yamllint misspell pre-commit-check

A sample AWS project managed by Terraform

About

This repo is set up to contain everything in a single AWS account.

Structure

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 project
  • modules, where client-specific modules kept
  • bin, 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

Initial Setup

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:

  1. Install the prerequisites
    • git
    • terraform (We use tfenv to manage terraform versions)
    • pre-commit
    • GNUMake
  2. provide authentication for the aws provider
  3. Clone the repo: git clone https://github.com/rhythmictech/sample-aws-project.git terraform-aws-rhythmictech
  4. Update the values for the backend in account/backend.auto.tfvars
  5. Run the setup with make setup

Creating a new project

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.tfvars file
  • creates the new folder with a backend, readme, and makefile
  • symlinks everything in common to the new folder

Applying Changes

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.