- Clone this gist and change directory to it
- Rename run-2nd.tf to an alternative file ending to prevent it being run.
terraform init
- Normally you would plan and save to a file but for this example we're going to just apply directly
terraform apply
- Rename run-2nd.tf back to it's original name
- The backend has changed so requires a new
terraform init
terraform apply
-
-
Save DavidPesticcio/bbfbe68af7807363e7ea824752c32332 to your computer and use it in GitHub Desktop.
Terraform S3 Backend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This uses Terraform to configure the resources required for remote state | |
provider "aws" { | |
region = "us-east-1" | |
} | |
resource "aws_s3_bucket" "state" { | |
bucket = "rowleyaj-tf-state-demo" | |
tags { | |
Name = "rowleyaj-tf-state-demo" | |
Environment = "testing" | |
} | |
} | |
resource "aws_dynamodb_table" "state" { | |
name = "rowleyaj-terraform-state-lock" | |
read_capacity = 5 | |
write_capacity = 5 | |
hash_key = "LockID" | |
attribute { | |
name = "LockID" | |
type = "S" | |
} | |
tags { | |
Name = "rowleyaj-terraform-state-lock" | |
Environment = "testing" | |
} | |
} | |
resource "null_resource" "sleep" { | |
provisioner "local-exec" { | |
command = "sleep 10" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This doesn't need to be it's own file but I've seperated it out to show the | |
# process used during this test. Either add this as separate file or append | |
# to the file above and re-run | |
terraform { | |
required_version = "~> 0.10" | |
backend "s3" { | |
bucket = "rowleyaj-tf-state-demo" | |
key = "v1/terraform-remote-state-example" | |
region = "us-east-1" | |
encrypt = true | |
dynamodb_table = "rowleyaj-terraform-state-lock" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment