To run terraform scripts locally you should use your own AD account, so that accountability is visualised in resource activity logs. Otherwise use service accounts (likely with different permission models per stack) in CI/CD environemt of your choice.
To use this repository you just need Docker and Docker Compose although it's possible to run commands within a local context of Terraform.
-
Either run
make setup
or:- Create
.env
file from.env.dist
- Create
docker-compose.local.yml
file fromdocker-compose.local.yml.dist
- Create
-
Populate
.env
file with basic values:ENVIRONMENT
: name of the environment to be deployed/managedARM_SUBSCRIPTION_ID
: subscription ID where the environment will be deployedARM_TENANT_ID
: AAD Tenant ID
-
Run
make
ormake build
to build Docker image, which includes Terraform and Azure cli -
Login to Azure cli:
make az-login
-
Create or get storage account for holding state files:
make backend-create
-
Populate
.env
file with terraform backend values:TERRAFORM_STORAGE_ACCOUNT_NAME
: backend storage account nameTERRAFORM_RESOURCE_GROUP_NAME
: backed storage account resource group nameTERRAFORM_STORAGE_ACCOUNT_ACCESS_KEY
: access key used to connect to storage account
This repository contains a Makefile
, which main purpose is to wrap docker-compose
commands into single task.
Few tasks, that speed up development and testing:
make build
- build terraform docker image for local usagemake setup
- setup local repo for local usagemake az-login
- authenticate your personal account against Azuremake backend-destroy
- destroy backend for the state files
And wrapped terraform commands:
make init
- initialise stackmake plan
- plan changesmake apply
- apply changes
To run other terraform commands, which are not in Makefile
, please run:
docker-compose run --rm terraform [COMMAND]
- Please don't store any secrets in state files if possible.
- Tag resources as much as possible, but don't go crazy
- Don't make stacks complex. Create a new one to simplify management of resources and reference them in other stacks when required
- Don't use default values for variables too often