Instead of creating and managing my backends manually I prefer to keep it in a custom module.
This module creates an S3 bucket for the TF statefiles and DyanmoDB table for the statelocks.
-
Ensure you're able to authenticate to AWS and verify with for eg.
aws sts get-caller-identity
. -
Go to your working directory where you'll be running your TF code.
-
Copy
base-s3-backend.tf
andbase-s3-backend.tfbackend
from example dir, and don't forget to change the bucket name since they are globally unique. -
Initialise the TF env.
terraform init
-
Uncomment
backend "s3" {}
inbase-s3-backend.tf
. -
Initialise the TF env but this time specifying the S3 backend parameters.
terraform init -backend-config base-s3-backend.tfbackend
-
Verify you're in full sync with the remote S3 state by checking no additinal changes are planned.
terraform plan
By default loggin is no enabled on the bucket created by the module however to change this override the var.s3_logging_bucket which is passed down to the module.
In order to prevent indefinetly storage of objects and specifically versions I've set the limit to 14 days.
Abbreviation | Expanded | Description |
---|---|---|
TF | Terraform | |
env | Environment | |
dir | Directory |