./init-terraform-remote-backend.sh your-terraform-name
terraform init -backend-config ./dev-backend-config.tfvars
Last active
February 7, 2019 16:06
-
-
Save lukasz-kaniowski/e3772561e0955c72a2020f09574788a7 to your computer and use it in GitHub Desktop.
Init s3 bucket and dynamodb as lock for new environment
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
terraform { | |
backend "s3" {} | |
} |
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
region = "eu-west-1" | |
bucket = "your-terraform-bucket" | |
key = "terraform.tfstate" | |
dynamodb_table = "your-terraform-dynamodb-table" | |
encrypt = true |
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
#!/usr/bin/env bash | |
if [[ "$1" == "" ]]; then | |
echo "Environment parameter missing. Usage: ./init-terraform-remote-backend.sh NAME" | |
exit 1 | |
fi | |
NAME=$1 | |
echo "About to create s3 bucket" | |
aws s3api create-bucket --bucket ${NAME} --region eu-west-1 --create-bucket-configuration LocationConstraint=eu-west-1 | |
aws s3api put-bucket-versioning --bucket ${NAME} --versioning-configuration Status=Enabled | |
echo "About to create dynamodb table" | |
aws dynamodb create-table \ | |
--region eu-west-1 \ | |
--table-name ${NAME} \ | |
--attribute-definitions AttributeName=LockID,AttributeType=S \ | |
--key-schema AttributeName=LockID,KeyType=HASH \ | |
--provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment