Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

.terraspace-cache folder doesn't contain the module template file #138

Closed
pie-r opened this issue Sep 21, 2021 · 3 comments · Fixed by #142
Closed

.terraspace-cache folder doesn't contain the module template file #138

pie-r opened this issue Sep 21, 2021 · 3 comments · Fixed by #142
Labels
bug Something isn't working

Comments

@pie-r
Copy link

pie-r commented Sep 21, 2021

terraspace version:

bundle exec terraspace version
0.6.13

I have a module like this, with a test_ssh folder and a .tpl file on it:

  infra
   ├── app
    │   ├── modules
    │   │   └── ec2
    │   │       ├── ec2.tf
    │   │       ├── iam.tf
    │   │       ├── output.tf
    │   │       ├── test_ssh
    │   │       │   └── user_data.tpl. --> this file is missing in .terraspace-cache
    │   │       ├── variables.tf
    │   │       └── versions.tf

But in the .terraspace-cache folder there isn't the template file after the plan:

└── infra
    ├── .gitignore
    ├── .terraspace-cache
    │   └── eu-central-1
    │       └── sandbox
    │           ├── modules
    │           │   └── ec2
    │           │       ├── ec2.tf
    │           │       ├── iam.tf
    │           │       ├── output.tf
    │           │       ├── variables.tf
    │           │       └── versions.tf

In Fact, I tried with:

resource "null_resource" "temporary" {
  triggers = {
    path = "${path.module}/test_ssh/user_data.tpl",
    path1 = "${path.cwd}/test_ssh/user_data.tpl",
    path2 = "${path.root}/test_ssh/user_data.tpl"
  }

}

The plan is:

  # module.ec2-mice-instance.null_resource.temporary will be created
  + resource "null_resource" "temporary" {
      + id       = (known after apply)
      + triggers = {
          + "path"  = "../../modules/ec2/test_ssh/user_data.tpl"
          + "path1" = "/Users/xxx/projects/git/terraform-services/terraspace/infra/.terraspace-cache/eu-central-1/sandbox/stacks/mice-service/test_ssh/user_data.tpl"
          + "path2" = "./test_ssh/user_data.tpl"
        }
    }

The template example I'm working on is:

data "template_file" "test_user_data" {
  # No way to fix it
  template = file("${path.module}/test_ssh/user_data.tpl")
}

If I use ${path.module} I get:

│ Error: Invalid function argument
│ 
│   on ../../modules/ec2/ec2.tf line 3, in data "template_file" "test_user_data":
│    3:   template = file("${path.module}/test_ssh/user_data.tpl")
│     ├────────────────
│     │ path.module is "../../modules/ec2"
│ 
│ Invalid value for "path" parameter: no file exists at
│ ../../modules/ec2/test_ssh/user_data.tpl; this function works only with
│ files that are distributed as part of the configuration source code, so if
│ this file will be created by a resource in this configuration you must
│ instead obtain this result from an attribute of that resource.

With the full original path ("/Users/xxx/projects/git/terraform-services/terraspace/infra/.terraspace-cache/eu-central-1/sandbox/stacks/mice-service/test_ssh/user_data.tpl") outside the .terraspace-cache folder, it works.

@pie-r pie-r added the bug Something isn't working label Sep 21, 2021
@tongueroo
Copy link
Contributor

tongueroo commented Oct 1, 2021

This might be because terraspace cleans up the .terraspace-cache folder between commands. You can turn off this behavior with build.clean_cache = false

config/app.rb

Terraspace.configure do |config|
  ...
  config.build.clean_cache = false
end

Thinking that may be it. Am considering changing the default from true to false.

@pie-r
Copy link
Author

pie-r commented Oct 2, 2021

Hi, no I already tested this flag without a good effect. I found this flag from another issue but in this case it doesn't fix the problem. I'd like to contribute if you can put me in the right path.

OT: I'm comparing terraspace and terragrunt in 4 articles, the next one will be terraspace, are you interested to review it before the release?
https://medium.com/geekculture/from-terralith-to-terraservice-with-terraform-acf990e65578

@tongueroo
Copy link
Contributor

Figured out what's going on. The builder was checking for any path with the word test in it. The test_ssh folder was being skipped. Fixed #142 and released in 0.6.17

RE: article

Very cool! Can read it after its published. Hope it's good. Good luck with the article! 🎉

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants