{"id":18401410,"url":"https://github.com/dozyio/terrastrap","last_synced_at":"2025-09-10T18:33:08.645Z","repository":{"id":118202594,"uuid":"340888961","full_name":"dozyio/terrastrap","owner":"dozyio","description":"Bootstrap a S3 and DynamoDB backend for Terraform","archived":false,"fork":false,"pushed_at":"2021-02-28T19:29:19.000Z","size":11,"stargazers_count":13,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-19T23:35:57.961Z","etag":null,"topics":["dynamodb","iac","iac-scripts","makefile","s3","terraform"],"latest_commit_sha":null,"homepage":"","language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dozyio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-21T11:51:43.000Z","updated_at":"2023-09-29T16:48:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"29409bfa-aadc-4855-ac61-51fb1eb1e50c","html_url":"https://github.com/dozyio/terrastrap","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dozyio%2Fterrastrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dozyio%2Fterrastrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dozyio%2Fterrastrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dozyio%2Fterrastrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dozyio","download_url":"https://codeload.github.com/dozyio/terrastrap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231312688,"owners_count":18356806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dynamodb","iac","iac-scripts","makefile","s3","terraform"],"created_at":"2024-11-06T02:38:44.726Z","updated_at":"2024-12-26T05:19:22.877Z","avatar_url":"https://github.com/dozyio.png","language":"Makefile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Terrastrap - Bootstrap a S3 and DynamoDB backend for Terraform\n\nSupports multiple AWS accounts for isolation.\n\n## Bootstrap environments\n\nCopy the example tfvar files and edit as appropriate.\n\n```\ncp env_vars/dev.tfvars.example env_vars/dev.tfvars\ncp env_vars/stage.tfvars.example env_vars/stage.tfvars\ncp env_vars/prod.tfvars.example env_vars/prod.tfvars\n```\n\n### Create dev backend\n```\nENV=dev make bootstrap\n```\n\n### Create stage backend\n```\nENV=stage make bootstrap\n```\n\n### Create prod backend\n```\nENV=prod make bootstrap\n```\n\n[![asciicast](https://asciinema.org/a/iftOoUzopjVCxVb7cvNDExmlX.svg)](https://asciinema.org/a/iftOoUzopjVCxVb7cvNDExmlX?autoplay=1)\n\n## Using S3 Backend in Terraform\nOnce the backend has been created, the Terraform outputs will show the S3 bucket\nand DyanmoDB table that you can use in your infrastructure.\n```\nOutputs:\n\nbucket = \"dev-dozyio-eu-west-2-tf-state\"\ndynamodb_table = \"dev-dozyio-eu-west-2-tf-lock\"\n```\n\nThese outputs can then be used as follows within your Terraform files\n```\nterraform {\n  required_version = \"0.14.7\"\n  backend \"s3\" {\n    bucket         = \"dev-dozyio-eu-west-2-tf-state\"\n    dynamodb_table = \"dev-dozyio-eu-west-2-tf-lock\"\n    key            = \"dev/dozyio/eu-west-2/terraform.tfstate\"\n    region         = \"eu-west-2\"\n    encrypt        = true\n  }\n}\n```\n\n\n## Create Additional Environments\n\ne.g. To bootstrap a uat environment, create a uat directory and uat.tfvars file\nand edit as appropriate.\n```\nmkdir uat\ncp env_vars/dev.tfvars.example env_vars/uat.tfvars\n$EDITOR env_var/uat.tfvars\n```\n\n## Destroy Bootstrap Environment\n\n### Destroy dev backend\n```\nENV=dev make bootstrap-destroy\n```\n\n### Destroy stage backend\n```\nENV=stage make bootstrap-destroy\n```\n\n### Destroy prod backend\n```\nENV=prod make bootstrap-destroy\n```\n\n### Destroy error\n\nWhen destroying a bootstrap, an error will occur as per below.\n```\nResource module.bootstrap.aws_s3_bucket.state_bucket has\nlifecycle.prevent_destroy set, but the plan calls for this resource to be\ndestroyed. To avoid this error and continue with the plan, either disable\nlifecycle.prevent_destroy or reduce the scope of the plan using the -target\nflag.\n```\n\nThis error is intended as a failsafe incase Terraform tries to delete the\nbucket. To delete the bootstrap bucket, change the following\nmodules/bootstrap/bootstrap_s3_bucket.tf\n\n```\n  lifecycle {\n    prevent_destroy = true\n  }\n```\n\n```\n  lifecycle {\n    #prevent_destroy = true\n  }\n```\n\n## View Bootstrap Plan\n\nTo view the Terraform plan of what would be created when bootstrapping, run the\nfollowing.\n\n```\nENV=dev make bootstrap-plan\n```\n\n## Changing Terraform Versions\n\nTerrastrap has support for TFENV in as much as it checks for the TFENV binary.\n\nIf you're not using TFENV, the Makefile checks your version of Terraform. At\ntime of writing this is pegged to version 0.14.7. To update, edit the Makefile\nand update the TERRAFORM_VERSION and md5 hash.\n\n```\nTERRAFORM:= $(shell command -v terraform 2\u003e /dev/null)\nTERRAFORM_VERSION:= \"0.14.7\"\n\nifeq ($(OS_X),true)\n    TERRAFORM_MD5:= $(shell md5 -q `which terraform`)\n    TERRAFORM_REQUIRED_MD5:= 952483b865874729a18cc6d00c664b8e\nelse\n    TERRAFORM_MD5:= $(shell md5sum - \u003c `which terraform` | tr -d ' -')\n    TERRAFORM_REQUIRED_MD5:= 5f1471a95776c2b1d8b09ac15a15eb00\nendif\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdozyio%2Fterrastrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdozyio%2Fterrastrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdozyio%2Fterrastrap/lists"}