Tuesday, May 23, 2023
HomeSoftware Engineeringuse a Backend-Config File for Terraform S3 State Configuration

use a Backend-Config File for Terraform S3 State Configuration

If you’re utilizing S3 because the backend in your state administration in Terraform, then you’ll be able to create surroundings particular configuration recordsdata the place you retailer the bucket, area amongst different issues to be pulled in mechanically when switching environments.

Step 1 – Create surroundings particular configs

Create a dev.conf file with the next content material:

bucket = "your-bucket"
area = "your-aws-region"
key    = "path/to/key"

Step 2 – Set the terraform backend

In your foremost.tf, suppliers.tf or state.tf file, specify the next:

terraform {
  backend "s3" {
    // you needn't specify something right here

Step 3 – Run init with backend-config

Now you’ll be able to init your Terraform with the brand new config file.

You may simply change the dev.conf to be prod.conf or whichever surroundings you specify.

terraform init -backend-config=dev.conf


Please enter your comment!
Please enter your name here

Most Popular

Recent Comments