Skip to content

An example repo using Make, Docker and Docker Compose to build, test and deploy an S3 bucket in AWS using Terraform and Terraform-Compliance.

Notifications You must be signed in to change notification settings

psymmetry/make-docker-compose-terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

♻️ Make, Docker-Compose and Terraform


image

A simple pattern that uses make, docker-compose and terraform to deploy "most of the things" to the cloud. The idea is that this pattern can be modified or extended to include extra steps to build/pack application code as well. terraform is just a flavour but this could be subbed out for a script or awscli etc, assuming you have the docker container to support that action.

This pattern is used to minimise the dependencies and reliance on external systems so that cicd steps used in different environments can be replicated exactly the same way locally (or your chosen cicd system), decreasing complexity as a result.


✔️ Prerequisites

Make is native to MacOS and all the different flavours of linux so no installation is required.

MacOS/Linux:

Windows:


⚡ TLDR Example

The below make command downloads the official python docker container from dockerhub, then mounts to the host file system and runs the scripts/hello.py script. Making use of the same pattern of make > docker-compose > script/terraform/etc

make hello

💻 Setup

  1. Before running make commands, you'll first need to authenticate to the cloud provider you're using when running commands locally. AWS is being used in this example to build an S3 bucket. There are a few open source tools such as awsume that can perform this task quite well, especially when switching between multiple accounts.

  2. The ./infra/config/dev/dev.tfvars file and ./infra/config/dev/dev.backend file both need to be updated before running make commands. Below is an example of dev environment variables being used. The same pattern can be applied for other environments.

./infra/config/dev/dev.backend Terraform state bucket and region:

bucket = "my-terraform-state-bucket-dev"
region = "ap-southeast-2"

./infra/config/dev/dev.tfvars Terraform infrastructure variables:

environment = "dev"
region = "ap-southeast-2"
bucket = "my-example-bucket-dev"

📣 Usage

All make commands can be found within the Makeile if required to run certain functions individually. Below is an example of building a terraform plan, running compliance tests against that plan and then deploying to a "dev" AWS environment. The default value for $ENVIRONMENT is "dev" so this variable would need updating when deploying to other environments, for example: make plan ENVIRONMENT="prod".

  • Run a step that performs a terraform init to the backend and terraform plan :
make plan
make comply
  • Run a step that performs a terraform apply step to deploy terraform plan to AWS:
make apply

🚀 Demo

image


📑 References:

About

An example repo using Make, Docker and Docker Compose to build, test and deploy an S3 bucket in AWS using Terraform and Terraform-Compliance.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published