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.
Make is native to MacOS and all the different flavours of linux so no installation is required.
MacOS/Linux:
Windows:
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
-
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. -
The
./infra/config/dev/dev.tfvars
file and./infra/config/dev/dev.backend
file both need to be updated before runningmake
commands. Below is an example ofdev
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"
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 andterraform plan
:
make plan
- Run a step that performs a terraform-compliance test against the
terraform plan
:
make comply
- Run a step that performs a
terraform apply
step to deployterraform plan
to AWS:
make apply