How to use a Backend-Config File for Terraform S3 State Configuration
If you are using S3 as the backend for your state management in Terraform, then you can create environment specific configuration files where you store the bucket
, region
among other things to be pulled in automatically when switching environments.
Step 1 – Create environment specific configs
Create a dev.conf
file with the following content:
Step 2 – Set the terraform
backend
In your main.tf
, providers.tf
or state.tf
file, specify the following:
Step 3 – Run init with backend-config
Now you can init your Terraform with the new config file.
You can easily change the dev.conf
to be prod.conf
or whichever environment you specify.
|
|