terramate icon indicating copy to clipboard operation
terramate copied to clipboard

[BUG] `generate_hcl` doesn't detect dotted files

Open waxb opened this issue 1 year ago • 3 comments

Describe the bug If generate_hcl's label starts with a dot the files are always generated and if the condition is unmet the files are remaining also. Seems like Terramate isn't aware of these files at all hence the generation always.

On the other side generate_file behaves exactly as expected.

To Reproduce

waxb@mbp:terramate-bug$ tree -a
.
├── stack.tm.hcl
├── terramate.tm.hcl
└── test.tm.hcl

1 directory, 3 files
waxb@mbp:terramate-bug$ cat test.tm.hcl 
globals {
  to_generate = true
}

generate_hcl ".file.hcl" {
  condition = global.to_generate
  content {}
}

generate_hcl ".directory/file.hcl" {
  condition = global.to_generate
  content {}
}

generate_file ".file" {
  condition = global.to_generate
  content = ""
}

generate_file ".directory/file" {
  condition = global.to_generate
  content = ""
}
waxb@mbp:terramate-bug$ terramate generate 
Code generation report

Successes:

- /
	[+] .directory/file
	[+] .directory/file.hcl
	[+] .file
	[+] .file.hcl

Hint: '+', '~' and '-' mean the file was created, changed and deleted, respectively.
waxb@mbp:terramate-bug$ tree -a
.
├── .directory
│   ├── file
│   └── file.hcl
├── .file
├── .file.hcl
├── stack.tm.hcl
├── terramate.tm.hcl
└── test.tm.hcl

2 directories, 7 files
waxb@mbp:terramate-bug$ terramate generate 
Code generation report

Successes:

- /
	[+] .directory/file.hcl
	[+] .file.hcl

Hint: '+', '~' and '-' mean the file was created, changed and deleted, respectively.
waxb@mbp:terramate-bug$ terramate generate 
Code generation report

Successes:

- /
	[+] .directory/file.hcl
	[+] .file.hcl

Hint: '+', '~' and '-' mean the file was created, changed and deleted, respectively.
waxb@mbp:terramate-bug$ tree -a
.
├── .directory
│   ├── file
│   └── file.hcl
├── .file
├── .file.hcl
├── stack.tm.hcl
├── terramate.tm.hcl
└── test.tm.hcl

2 directories, 7 files
waxb@mbp:terramate-bug$ sed -i 's/true/false/' test.tm.hcl 
waxb@mbp:terramate-bug$ terramate experimental get-config-value global.to_generate
false
waxb@mbp:terramate-bug$ terramate generate 
Code generation report

Successes:

- /
	[-] .directory/file
	[-] .file

Hint: '+', '~' and '-' mean the file was created, changed and deleted, respectively.
waxb@mbp:terramate-bug$ terramate generate 
Nothing to do, generated code is up to date
waxb@mbp:terramate-bug$ tree -a
.
├── .directory
│   └── file.hcl
├── .file.hcl
├── stack.tm.hcl
├── terramate.tm.hcl
└── test.tm.hcl

2 directories, 5 files

Expected behavior Generation of hcl files starting with a dot.

Environment (please complete the following information):

  • OS: macOS
  • OS Version: Ventura 13.5
  • Git Version: 2.42.0
  • Terramate Version: 0.4.3 🎂

waxb avatar Nov 24 '23 14:11 waxb

Thank you for the detailed report. We’re looking at this and will get back to you with some more information soon.

vtimd avatar Nov 29 '23 15:11 vtimd

This fix needs to be reverted because it introduces some issues with downloaded modules with generated files. A better solution will be provided soon. Sorry for the inconvenience.

i4ki avatar Dec 28 '23 12:12 i4ki

Hey @waxb

The #1539 is the second attempt at fixing this issue but beware that in the next major release we will disallow generate_hcl inside dotdirs (check #1538). Generating dotfiles will continue to work.

i4ki avatar Mar 12 '24 00:03 i4ki