I am using S3 for a remote state with Terraform.
When I use a Terraform workspace then the path for the state file for the environment ends up being s3://<bucket>/env:/<workspace>/<key> where <bucket> and key are specified in a terraform block. For example, with the below Terraform HCL:
terraform {
backend "s3" {
bucket = "devops"
key = "tf-state/abc/xyz.tfstate"
region = "us-east-1"
}
}
If we're using a Terraform workspace, like so:
$ terraform workspace new myapp-dev
$ terraform workspace select myapp-dev
$ terraform init
$ terraform apply
then we'll end up with the Terraform state file in the following path: s3://devops/env:/myapp-dev/tf-state/abc/xyz.tfstate
It seems that Terraform by default uses a subdirectory named env: under which it manages state files associated with workspaces. My question is can we add anything into the Terraform configuration that will allow us some control over the env: part of this?