'terraform provider plugin symlink creation to plugin fails in Unix
- OS: Unix
- .terraform.rc file content: plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"
- I have placed aws provider plugin to "$HOME/.terraform.d/plugin-cache". So, when I run "terraform init", it copies plugin from above plugin_cache_dir to current directory under .terrform directory. Plugin size is around 240MB for aws version 4.13. This helps to skip download each time running "terraform init". content of "$HOME/.terraform.d/plugin-cache" as below.
[root@localhost plugin-cache]# ls -lrt total 224972 -rwxr-xr-x. 1 root root 230371328 May 5 15:51 terraform-provider-aws_v4.13.0_x5 drwxr-xr-x. 3 root root 23 May 7 22:22 registry.terraform.io
Issue: I ran command "TF_LOG=TRACE terraform init" and I see that it fails to create symlink to plugin file for aws provider. See below snippet from output as root cause. How do I fix so it creates symlink instead of doing local copy from above "plugin_cache_dir" to current init directory?
2022-05-12T10:36:49.601-0400 [TRACE] providercache.fillMetaCache: scanning directory .terraform/providers 2022-05-12T10:36:49.601-0400 [TRACE] getproviders.SearchLocalDirectory: failed to resolve symlinks for .terraform/providers: lstat .terraform: no such file or directory 2022-05-12T10:36:49.601-0400 [TRACE] providercache.fillMetaCache: error while scanning directory .terraform/providers: cannot search .terraform/providers: lstat .terraform/providers: no such file or directory 2022-05-12T10:36:49.601-0400 [TRACE] providercache.fillMetaCache: scanning directory /root/.terraform.d/plugin-cache 2022-05-12T10:36:49.601-0400 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/aws v4.13.0 for linux_amd64 at /root/.terraform.d/plugin-cache/registry.terraform.io/hashicorp/aws/4.13.0/linux_amd64 2022-05-12T10:36:49.601-0400 [TRACE] providercache.fillMetaCache: including /root/.terraform.d/plugin-cache/registry.terraform.io/hashicorp/aws/4.13.0/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/aws 4.13.0
Solution 1:[1]
Terraform's behavior for the local cache directory is to try to create a symbolic link from the local .terraform
directory to the cache, but to fall back on creating a full copy of the symbolic link fails for any reason.
Some reasons the symbolic link could fail include:
You are on a Unix system but you are using a non-Unix filesystem which cannot store symbolic links.
You are on a Windows Vista or later system and your administrator hasn't granted you access to create symbolic links.
(You would need the "Create Symbolic Link" privilege As the Microsoft documentation suggests, legacy Windows applications often don't handle symbolic links well and so administrators will often not grant that permission to avoid poor interactions with that legacy software. Terraform itself correctly handles symbolic links, though.)
If either of the above situations are true, Terraform will be forced to create a copy instead of a symbolic link.
Someone reported in that GitHub issue that enabling "Developer Mode" in is one way to get permission to create symbolic links on a Windows 10 or later system, although I don't routinely use Windows so I cannot confirm that myself.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Martin Atkins |