Skip to content

berendjan/tf-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tf-backend

Terraform / OpenTofu AWS S3 backend module with DynamoDB for lock file.

Prerequisites

Ensure aws api credentials are in ~/.aws/credentials

[default]
aws_access_key_id = AWS_ACCESS_KEY_ID
aws_secret_access_key = AWS_SECRET_ACCESS_KEY

or as env AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.

Usage

Using AWS S3 as a backend requires a 4-step process.

  1. Replace REGION and PROJECT_NAME in example.main.tf

    REGION=eu-west-2 && 
    PROJECT_NAME=tf-backend && 
    sed "s/REGION/$REGION/g; s/PROJECT_NAME/$PROJECT_NAME/g" main.tf.template > main.tf
  2. Create resources with local tfstate with tofu init && tofu apply.

  3. Uncomment terraform backend "s3" block.

  4. Run tofu init to switch to S3 backend.

Destruction

Removing all resources is again a 4-step process.

  1. Comment out terraform backend "s3" block.
  2. Run tofu init -migrate-state to switch to local backend.
  3. Comment out prevent-destroy = true in the bucket block.
  4. Run tofu destroy -auto-approve to retire resources.

About

terraform / opentofu AWS S3 backend

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published