Creating different state files for each environment

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?

This is a good article … I have used method two and it works great. There is a small amount of duplication and you have to be careful where you run your command from but it’s easy and fits into most gitop models.