{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/16322","repository_url":"https://api.github.com/repos/hashicorp/terraform","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/16322/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/16322/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/16322/events","html_url":"https://github.com/hashicorp/terraform/issues/16322","id":264937620,"number":16322,"title":"Error Handling of Symbolic Links in Modules","user":{"login":"afritzler","id":1922939,"avatar_url":"https://avatars2.githubusercontent.com/u/1922939?v=4","gravatar_id":"","url":"https://api.github.com/users/afritzler","html_url":"https://github.com/afritzler","followers_url":"https://api.github.com/users/afritzler/followers","following_url":"https://api.github.com/users/afritzler/following{/other_user}","gists_url":"https://api.github.com/users/afritzler/gists{/gist_id}","starred_url":"https://api.github.com/users/afritzler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afritzler/subscriptions","organizations_url":"https://api.github.com/users/afritzler/orgs","repos_url":"https://api.github.com/users/afritzler/repos","events_url":"https://api.github.com/users/afritzler/events{/privacy}","received_events_url":"https://api.github.com/users/afritzler/received_events","type":"User","site_admin":false},"labels":[{"id":85946957,"url":"https://api.github.com/repos/hashicorp/terraform/labels/bug","name":"bug","color":"f7c6c7","default":true},{"id":127939292,"url":"https://api.github.com/repos/hashicorp/terraform/labels/core","name":"core","color":"cccccc","default":false},{"id":693557404,"url":"https://api.github.com/repos/hashicorp/terraform/labels/modules","name":"modules","color":"f9d0c4","default":false},{"id":470086981,"url":"https://api.github.com/repos/hashicorp/terraform/labels/regression","name":"regression","color":"e11d21","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-10-12T13:14:55Z","updated_at":"2017-10-19T19:47:21Z","closed_at":null,"author_association":"NONE","body":"Hi there,\r\n\r\n\r\n\r\n### Terraform Version\r\n0.10.5-0.10.7\r\n\r\n### Terraform Configuration Files\r\nSee tar file - unpack it under `/tmp/terraform/tftest`\r\n\r\n[modules.tar.gz](https://github.com/hashicorp/terraform/files/1379364/modules.tar.gz)\r\n\r\n### Debug Output\r\nExecute `terraform init k8s/variants/current` in `/tmp/terraform/tftest`\r\n\r\n```\r\n$ terraform init k8s/variants/current\r\n2017/10/12 15:02:45 [INFO] Terraform version: 0.10.7\r\n2017/10/12 15:02:45 [INFO] Go runtime version: go1.9\r\n2017/10/12 15:02:45 [INFO] CLI args: []string{\"/usr/local/Cellar/terraform/0.10.7/bin/terraform\", \"init\", \"k8s/variants/current\"}\r\n2017/10/12 15:02:45 [DEBUG] Attempting to open CLI config file: /Users/i820491/.terraformrc\r\n2017/10/12 15:02:45 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.\r\n2017/10/12 15:02:45 [DEBUG] CLI Config is main.Config{Providers:map[string]string{}, Provisioners:map[string]string{}, DisableCheckpoint:false, DisableCheckpointSignature:false, PluginCacheDir:\"\"}\r\n2017/10/12 15:02:45 [INFO] CLI command args: []string{\"init\", \"k8s/variants/current\"}\r\n2017/10/12 15:02:45 [DEBUG] command: loading backend config file: /tmp/terraform/tftest/k8s/variants/current\r\nDownloading modules...\r\n2017/10/12 15:02:45 [TRACE] module source \"../..\"\r\n2017/10/12 15:02:45 [TRACE] module source: \"../..\"\r\n2017/10/12 15:02:45 [TRACE] detected module source \"file:///private/tmp/terraform/tftest/k8s\"\r\n2017/10/12 15:02:45 [TRACE] getting module source \"file:///private/tmp/terraform/tftest/k8s\"\r\nGet: file:///private/tmp/terraform/tftest/k8s\r\n2017/10/12 15:02:45 [TRACE] module source \"variants/current/modules/vms\"\r\n2017/10/12 15:02:45 [TRACE] module source: \"variants/current/modules/vms\"\r\n2017/10/12 15:02:45 [TRACE] detected module source \"file:///private/tmp/terraform/tftest/k8s/variants/current/modules/vms\"\r\n2017/10/12 15:02:45 [TRACE] getting module source \"file:///private/tmp/terraform/tftest/k8s/variants/current/modules/vms\"\r\nGet: file:///private/tmp/terraform/tftest/k8s/variants/current/modules/vms\r\n2017/10/12 15:02:45 [TRACE] module source \"variants/current/modules/vms2\"\r\n2017/10/12 15:02:45 [TRACE] module source: \"variants/current/modules/vms2\"\r\n2017/10/12 15:02:45 [TRACE] detected module source \"file:///private/tmp/terraform/tftest/k8s/variants/current/modules/vms2\"\r\n2017/10/12 15:02:45 [TRACE] getting module source \"file:///private/tmp/terraform/tftest/k8s/variants/current/modules/vms2\"\r\nGet: file:///private/tmp/terraform/tftest/k8s/variants/current/modules/vms2\r\n2017/10/12 15:02:45 [TRACE] module source \"../../../../modules/flag\"\r\n2017/10/12 15:02:45 [TRACE] module source: \"../../../../modules/flag\"\r\n2017/10/12 15:02:45 [TRACE] detected module source \"file:///private/tmp/terraform/tftest/k8s/modules/flag\"\r\n2017/10/12 15:02:45 [TRACE] getting module source \"file:///private/tmp/terraform/tftest/k8s/modules/flag\"\r\nGet: file:///private/tmp/terraform/tftest/k8s/modules/flag\r\n2017/10/12 15:02:45 [TRACE] module source \"../../../../modules/flag\"\r\n2017/10/12 15:02:45 [TRACE] module source: \"../../../../modules/flag\"\r\n2017/10/12 15:02:45 [DEBUG] plugin: waiting for all plugin processes to complete...\r\nError downloading modules: Error loading modules: module link: lstat /private/tmp/terraform/platforms: no such file or directory\r\n```\r\n\r\n### Expected Behavior\r\nShould load the `flag` module from `modules/vms2/` which is a symbolic link.\r\n\r\n### Actual Behavior\r\nIf the module is no symbolic link (`modules/vms`) everything works fine. For `vms2` however we get the error shown above regardless of the path specified in the source path the module call in `fips.tf`\r\n\r\n### Steps to Reproduce\r\nPlease list the full steps required to reproduce the issue, for example:\r\n1. `terraform init k8s/variants/current`\r\n\r\n### Important Factoids\r\nThe module `vms2` is loaded correctly but any module call from inside this module leads to the described `lstat` error (see code snipped of function `Detect` below) which is independent of the source path of the called sub-module. So it must result from the path remembered for the loaded module.\r\n\r\nThis issue is not occurring with Terraform version <= 0.10.4. It looks like the problem was introduced with https://github.com/hashicorp/terraform/pull/16099\r\n\r\nLooks like this was the breaking change:\r\n```\r\nif fi, err := os.Lstat(pwd); !os.IsNotExist(err) {\r\n \t\t\tif err != nil {\r\n  \t\t\t\treturn \"\", true, err\r\n  \t\t\t}\r\n  \t\t\tif fi.Mode()&os.ModeSymlink != 0 {\r\n -\t\t\t\tpwd, err = os.Readlink(pwd)\r\n +\t\t\t\tpwd, err = filepath.EvalSymlinks(pwd)\r\n  \t\t\t\tif err != nil {\r\n  \t\t\t\t\treturn \"\", true, err\r\n  \t\t\t\t}\r\n```\r\n\r\n### References\r\n- #16099 \r\n"},"comment":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/comments/338016776","html_url":"https://github.com/hashicorp/terraform/issues/16322#issuecomment-338016776","issue_url":"https://api.github.com/repos/hashicorp/terraform/issues/16322","id":338016776,"user":{"login":"jbardin","id":35067,"avatar_url":"https://avatars2.githubusercontent.com/u/35067?v=4","gravatar_id":"","url":"https://api.github.com/users/jbardin","html_url":"https://github.com/jbardin","followers_url":"https://api.github.com/users/jbardin/followers","following_url":"https://api.github.com/users/jbardin/following{/other_user}","gists_url":"https://api.github.com/users/jbardin/gists{/gist_id}","starred_url":"https://api.github.com/users/jbardin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbardin/subscriptions","organizations_url":"https://api.github.com/users/jbardin/orgs","repos_url":"https://api.github.com/users/jbardin/repos","events_url":"https://api.github.com/users/jbardin/events{/privacy}","received_events_url":"https://api.github.com/users/jbardin/received_events","type":"User","site_admin":false},"created_at":"2017-10-19T19:47:21Z","updated_at":"2017-10-19T19:47:21Z","author_association":"CONTRIBUTOR","body":"Wow, thanks for the reproduction case here @afritzler.\r\n\r\nIt turns out that the change you listed isn't the culprit, or at least it isn't on its own. Reverting to that version results in other errors when building the module tree, for the reasons stated in that commit. I have a feeling that you had the modules initialized, and over time modified the link structure in place but hadn't ever done a clean `init` from scratch. Trying earlier versions of terraform on your test case also fail.\r\n\r\nEven if this isn't a regression, it is likely an edge case that should be covered. I'm undecided whether this is a Go bug or not, because it turns out `EvalSymlinks` doesn't expand the double symlink in the path like a shell. \r\n\r\nFor example, while I can `ls k8s/variants/current/modules/vms2` and see `fips.tf`, `EvalSymlinks(\"k8s/variants/current/modules/vms2\")` returns an error. It does work as expected if I expand the intermediate parts first, i.e. `k8s/variants/../../k8s/variants/openstack/modules/vms2`."}}
{"actor":{"display_login":"jbardin"}}