I am configuring Azure Devops releases to create 3 different environment’s using Terraform (Test, Pre-prod and Prod) all my configuration is correct apart from the state file it uses.
I have created the below files for terraform:
main.tf
variables.tf
test.tfvars
prod.tfvars
preprod.tfvars
Within the main file I have specified a backend for my state file to point to Azure storage:
backend "azurerm" {
resource_group_name = "devops"
storage_account_name = "devopsstorage755"
container_name = "devopsstorageblob"
key = "terraform.tfstate"
I need to configure each of my environments to use my main.tf file for deployment and use the .tfvars files to dynamically change resource values for each environment. But as it uses only one state file, each time the deployment moves onto the next stage e.g. test>pre-prod, it destroys the old environment. Is there a way I can dynamically create a state file for each environment whilst still using the singular main.tf file?