terraform get -update deletes module source files

377 views
Skip to first unread message

Suriyanto Lee

unread,
Dec 20, 2016, 2:01:51 PM12/20/16
to Terraform
I have Terraform modules and is using it from the other Terraform file. When I freshly get the source, terraform get -update was run and returns error:

Error loading Terraform: Error downloading modules: module vpc: No Terraform configuration files found in directory: .terraform\modules\12c22033ac495924c1ada27c3415ca0f

After the error occured, I realized that all the source files in the modules directory where referenced was also deleted.

Is that expected behavior when error occured? I am using Terragrunt and when terragrunt plan is run, terraform get -update was run and my whole module is destroyed.

A bit frustrated here as I have just lost a day worth of work.

Suriyanto

David Adams

unread,
Dec 20, 2016, 2:32:53 PM12/20/16
to terrafo...@googlegroups.com
I've never had terraform delete anything for me, including stuff in `.terraform`. But I'm guessing you are on Windows based on the backslashes in the path you listed. On Windows there is an issue with file links in which deleting the link can sometimes (always?) delete the file itself. So that's my gut instinct of what might have happened. It's a common problem mixing tools developed on Unix into a Windows environment.

I did some digging with strace and found that while `terraform get` does not delete anything, `terraform get -update` does call `unlink` to remove the existing symlinks before recreating them from scratch (even tho they point to the same place with the same ID) (see transcript below).

I don't have a Windows box on which to verify, but I'm guessing this is likely. I would say it's _not_ the expected behavior, but since the development and most of the use is done on Unix-like systems, the Windows gotchas probably rarely come up.

Sorry you lost your work. :(

----
Transcript:
$ terraform get
Get: file:///home/dave/working/tf/module/sub
Get: file:///home/dave/working/tf/module/sub2

$ strace -fo get.txt terraform get
Get: file:///home/dave/working/tf/module/sub
Get: file:///home/dave/working/tf/module/sub2

$ strace -fo get-update.txt terraform get -update
Get: file:///home/dave/working/tf/module/sub (update)
Get: file:///home/dave/working/tf/module/sub2 (update)

$ ls .terraform/modules/
39a9878006aae1874bee6f7da5632511  4d6ccdb0a67f0fa9a0657704b48d5967

$ grep 39a987 get.txt
13317 stat(".terraform/modules/39a9878006aae1874bee6f7da5632511",  <unfinished ...>
13317 stat(".terraform/modules/39a9878006aae1874bee6f7da5632511",  <unfinished ...>
13317 openat(AT_FDCWD, ".terraform/modules/39a9878006aae1874bee6f7da5632511", O_RDONLY|O_CLOEXEC <unfinished ...>
13317 lstat(".terraform/modules/39a9878006aae1874bee6f7da5632511/main.tf",  <unfinished ...>
13317 openat(AT_FDCWD, ".terraform/modules/39a9878006aae1874bee6f7da5632511/main.tf", O_RDONLY|O_CLOEXEC <unfinished ...>

$ grep 39a987 get-update.txt
13346 lstat(".terraform/modules/39a9878006aae1874bee6f7da5632511",  <unfinished ...>
13346 unlinkat(AT_FDCWD, ".terraform/modules/39a9878006aae1874bee6f7da5632511", 0 <unfinished ...>
13346 symlinkat("/home/dave/working/tf/module/sub", AT_FDCWD, ".terraform/modules/39a9878006aae1874bee6f7da5632511") = 0
13346 stat(".terraform/modules/39a9878006aae1874bee6f7da5632511",  <unfinished ...>
13346 openat(AT_FDCWD, ".terraform/modules/39a9878006aae1874bee6f7da5632511", O_RDONLY|O_CLOEXEC <unfinished ...>
13346 lstat(".terraform/modules/39a9878006aae1874bee6f7da5632511/main.tf", {st_mode=S_IFREG|0644, st_size=202, ...}) = 0
13346 openat(AT_FDCWD, ".terraform/modules/39a9878006aae1874bee6f7da5632511/main.tf", O_RDONLY|O_CLOEXEC) = 6


eg, see that in a `terraform get` with existing modules, "unlink" is never called, but `terraform get -update` does trigger an `unlinkat` call. Whatever equivalent happens on Windows may be at fault here.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/f843867c-065a-47a9-92cc-f469b1a3631c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages