Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jottenlips/terraform-state-s3-backend-example
🌀 terraform your terraform s3 backend
https://github.com/jottenlips/terraform-state-s3-backend-example
aws backend devops iac s3 terraform terraform-backend terraform-backend-s3
Last synced: about 2 months ago
JSON representation
🌀 terraform your terraform s3 backend
- Host: GitHub
- URL: https://github.com/jottenlips/terraform-state-s3-backend-example
- Owner: jottenlips
- Created: 2022-08-03T19:09:02.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-19T16:33:41.000Z (about 2 years ago)
- Last Synced: 2024-10-15T03:06:51.898Z (3 months ago)
- Topics: aws, backend, devops, iac, s3, terraform, terraform-backend, terraform-backend-s3
- Language: HCL
- Homepage:
- Size: 15.6 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Getting started with Terraform state, using an s3 backend
## Chicken or Egg?
In order to use terraform to keep track of your infrastructure, you need a terraform backend. A terraform backend on AWS requires a dynamodb table and an s3 bucket. You could spin up these resources in the console or the aws cli, but what if you want these resources under terraform as well? These 3 steps will get your terraform state under terraform.
1. comment out the terraform backend to deploy bucket and dynamodb, deploy
```
terraform init
terraform plan
terraform apply
```2. uncomment terraform backend, import dynamodb and s3_bucket that were created, deploy
```
terraform import aws_dynamodb_table.terraform_state_lock "tf-lock-table"
terraform import aws_s3_bucket.terraform_states "tf-states-s3backend"
terraform plan
terraform apply
```You now have a terraform backend on s3!
3. Use terraform state in other repos for you aws account
```
terraform {
backend "s3" {
bucket = "tf-states-s3backend"
key = "environments/develop/network.tfstate"
region = "us-east-1"
encrypt = true
profile = "default"
dynamodb_table = "tf-lock-table"
shared_credentials_file = "$HOME/.aws/credentials"
}
}
```