Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save spencershepard/05bc6e9f0bff01e4486793e0136eb73c to your computer and use it in GitHub Desktop.
Save spencershepard/05bc6e9f0bff01e4486793e0136eb73c to your computer and use it in GitHub Desktop.

Revisions

  1. spencershepard created this gist Jul 30, 2025.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    TF_STATE_BUCKET="your-bucket-name"
    TF_STATE_TABLE="your-dynamodb-table"
    BUCKET_FOLDER="terraform"
    AWS_REGION="your-aws-region"

    aws s3api create-bucket --bucket $TF_STATE_BUCKET --region $AWS_REGION || echo "Bucket already exists"

    aws dynamodb create-table \
    --table-name $TF_STATE_TABLE \
    --attribute-definitions AttributeName=LockID,AttributeType=S \
    --key-schema AttributeName=LockID,KeyType=HASH \
    --billing-mode PAY_PER_REQUEST \
    --region $AWS_REGION || echo "Table already exists"

    terraform init \
    -backend-config="bucket=$TF_STATE_BUCKET" \
    -backend-config="region=$AWS_REGION" \
    -backend-config="dynamodb_table=$TF_STATE_TABLE" \
    -backend-config="key=$BUCKET_FOLDER/terraform.tfstate" \
    -backend-config="encrypt=true"