This is an aws-cdk
app in typescript to create S3 buckets and DynamoDB tables for
storing terraform state and lock files.
required
AWS_ACCESS_KEY_ID="<your aws access key id>"
AWS_SECRET_ACCESS_KEY="<your aws secret access key>"
AWS_ACCOUNT="<your aws account id>"
(optional)
# default: us-east-1
AWS_REGION="us-east-1"
# default: a generated unique 30 characters name like "terraform-state-lock-xxxxxx..."
DYNAMODB_TABLE_NAMES="terraform-state-lock-1,terraform-state-lock-2, ..."
# default: a generated unique 63 characters name like "terraform-state-xxxxxxxxxxx....."
S3_BUCKET_NAMES="globally-unique-bucket-name-1,globally-unique-bucket-name-2, ..."
NOTE: make sure you have
node
andnpm
installed
# install dependencies
npm install
see
package.json
for more scripts
# lint, test, build
npm run build
# lint, test, build, bootstrap, synthesize, deploy
npm run deploy
# lint, test, build, bootstrap, synthesize, destroy
npm run destroy
to get the stack outputs (s3 bucket and dynamodb table names), use either aws management console or aws cli by running the following command:
replace
aws-cdk-terraform-backend
with your stack namereplace
us-east-1
with your region*stack name is the project tag set here (
src/config.ts
->stackTags.Project
)
aws cloudformation describe-stacks \
--region us-east-1 \
--stack-name aws-cdk-terraform-backend \
--query "Stacks[0].Outputs" \
| grep -E "ExportName|OutputValue"
MIT (see license)