Skip to content

Bootstrap Terraform State Bucket

Each environment needs an S3 bucket for Terraform state before terraform init can run. This is a one-time setup per environment, done by the person who applies Terraform (Ástþór, via an Infrastructure & Security issue and a pull request he reviews; see Terraform). The bucket name pattern below is the one every backend.tf expects.

Create the state bucket

Replace <environment> and <account-id> with the appropriate values: - Prod: prod / 759286286879 - Stage: stage / 258618559895

ENVIRONMENT=<environment>
ACCOUNT_ID=<account-id>
BUCKET="cookiehub-terraform-state-${ENVIRONMENT}-${ACCOUNT_ID}"

aws s3api create-bucket \
  --bucket "$BUCKET" \
  --region eu-central-1 \
  --create-bucket-configuration LocationConstraint=eu-central-1

aws s3api put-bucket-versioning \
  --bucket "$BUCKET" \
  --versioning-configuration Status=Enabled

aws s3api put-bucket-encryption \
  --bucket "$BUCKET" \
  --server-side-encryption-configuration '{
    "Rules": [{
      "ApplyServerSideEncryptionByDefault": {
        "SSEAlgorithm": "AES256"
      }
    }]
  }'

Verify

aws s3api head-bucket --bucket "$BUCKET"