Skip to content

Latest commit

 

History

History
65 lines (40 loc) · 2.62 KB

Setup-Via-Terraform.md

File metadata and controls

65 lines (40 loc) · 2.62 KB

S3 backend setup via Terraform

Setup and customize the Terraform S3 backend through Terraform itself. This method is best suited for when you wish to manage all infrastructure via Terraform.

Customizable Parameters

There are a small number of parameters that let you customize your S3 backend deployment. These parameters may be set on the command line with the -var flag. Multiple parameters may be specified by repeated use of -var. See the Input Variables topic in the Terraform documentation.

For example;

terraform apply -var 's3_bucket_name=MyCustomBucketName' -var 'dynamo_table_name=my-table-name'

S3 Bucket Name

-var "s3_bucket_name=MyCustomBucketName"

When left empty this will cause a new S3 bucket to be created with a somewhat random, but unique name.

S3 State Prefix

-var "s3_key_prefix=my/custom/S3/key/prefix"

Overrides the default key prefix in the S3 bucket which stores your Terraform state objects. Set to /terraform-state by default. Take care to the omitted the leading /.

DynamoDB Lock Table Name

-var "dynamo_table_name=my-table-name"

Specify to override the default DynamoDB table name, which is terraform-locking.

IAM Policy Name

-var "iam_policy_name=my-policy-name"

Specify to override the default IAM policy name, which is Terraform-S3-Backend.

SSM Parameter Store Prefix

-var "parameter_prefix=my/param/prefix"

Override the prefix of the SSM Parameter Store values that are created to store the S3 bucket name and DynamoDB table. Set to /terraform by default. Take care to the omitted the leading /.

Migration into the S3 backend

When setting up the S3 backend using Terraform the state is stored locally and must be migrated into the backend afterwards (unless you wish to store the backend's state locally).

Once your backend configuration has been setup (see the project README for more information) you may then run the following to migrate your local state into the S3 backend:

terraform init -migrate-state

You will be prompted for confirmation by Terraform, the backend will be initialized, and your local state will be copied into the new backend.