Windows environment variables in terraform.rc plugin_cache_dir

I’m attempting to set my plugin_cache_dir in my %APPDATA%\terraform.rc config file as follows, and it fails to correctly evaluate the %APPDATA% environment variable.

I’m escaping \ as \\, without this it complains during terraform init.

plugin_cache_dir = "%APPDATA%\\terraform.d\\plugin-cache"

Result: %APPDATA% is evaluated literally, and a new directory is created inside the current working directory where terraform init was executed, literally .terraform\%APPDATA%\terraform.d\plugin-cache

Is this a known issue? Is there a way I should be specifying a Windows environment variable differently?

Thanks

Hi @JohnDelisle,

In the places where the CLI configuration accepts environment variable substitutions, the expected syntax is either $APPDATA or ${APPDATA}. I think the following should work the way you intended:

plugin_cache_dir = "$APPDATA/terraform.d/plugin-cache"

It should accept either slashes or backslashes as the directory separators, and so I generally prefer using slashes to avoid the need for escaping that makes the file harder to read.

1 Like

Thanks Martin, I’ll give that a go.

That did it, thanks!