Saturday, May 27, 2023
HomeSoftware EngineeringFind out how to use a Backend-Config File for Terraform S3 State...

Find out how to use a Backend-Config File for Terraform S3 State Configuration


If you’re utilizing S3 because the backend on your state administration in Terraform, then you may create surroundings particular configuration information the place you retailer the bucket, area amongst different issues to be pulled in routinely 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 may init your Terraform with the brand new config file.

You’ll be able to simply change the dev.conf to be prod.conf or whichever surroundings you specify.

terraform init -backend-config=dev.conf
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments