The docs for TF_DATA_DIR say:
TF_DATA_DIRchanges the location where Terraform keeps its per-working-directory data, such as the current remote backend configuration.
By default this data is written into a
.terraformsubdirectory of the current directory, but the path given in
TF_DATA_DIRwill be used instead if non-empty.
In most cases it should not be necessary to set this variable, but it may be useful to do so if e.g. the working directory is not writable.
This is exactly what I’m looking for - the folder where I am executing terraform is not writable so I’d like the data to be written to a separate folder. However, I’d also like to use workspaces, but when I try to create a new workspace with TF_DATA_DIR set I get the error:
mkdir terraform.tfstate.d: read-only file system
Is there a way to make workspaces use TF_DATA_DIR to write their data too?