Is there a way to control the location of the .terraform directory?
If not, it would be helpful to have a setting or env var like VAGRANT_DOTFILE_PATH for terraform.
Hi @gamename - it doesn't look like this is currently possible, but it's a good idea! Tagged as an enhancement.
Allow me to add a :+1: to this idea. This would add a lot of flexibility in terms of scripting. I am even willing to go as far as one should be able to terraform plan and then apply such generated plan on a readonly volume of a terraform-able git-root somehow.
In some other issue @mitchellh commented about adding a terraform block to the config to contain top-level Terraform settings.
It'd be nice if we could support something like this:
terraform {
// (not sure "data_dir" is the best name here, but not really sure how Terraform calls this)
data_dir = "${path.module}/${var.environment}"
}
...which is to say that the directory can be controlled by interpolating variables and paths, rather than becoming just another random separate setting for the user to keep straight.
+1
+1
+1
It seems to me like this problem is already solved by the TF_DATA_DIR environment variable:
https://www.terraform.io/docs/configuration/environment-variables.html#tf_data_dir
It might be nice to add that configuration to the CLI configuration file:
https://www.terraform.io/docs/commands/cli-config.html
Or to allow it to be configured on a per project basis by adding it to the terraform block as was mentioned earlier in the thread.
I'd be happy to take on adding it to one of those places, but only if this still has value. It seems to me this is a problem that can be solved with env vars as originally specified in the issue.
It does indeed seem like TF_DATA_DIR addressed this in the meantime, but we neglected to close this out. Putting the .terraform directory in a different place is a pretty rare need, and tends to be something driven by implementation details of a particular execution environment rather than something that should travel along with the configuration, so it doesn't seem justified to introduce other ways to get the same effect.
If you have a need that isn't met by the existence of that environment variable then please feel free to open a new enhancement request issue for it and complete the new issue template so we can consider it. Due to the age of this issue, and the multi-year silence here, I'm going to close this out. Thanks!
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
In some other issue @mitchellh commented about adding a
terraformblock to the config to contain top-level Terraform settings.It'd be nice if we could support something like this:
...which is to say that the directory can be controlled by interpolating variables and paths, rather than becoming just another random separate setting for the user to keep straight.