hcledit
hcledit copied to clipboard
Remove nested blocks
Consider following input:
test.hcl:
b1 {
b2 l1 {
}
}
Get nested block - works as expected
$ cat test.hcl | hcledit block get b1.b2.l1
b2 l1 {
}
Removal of nested block
Expected output:
b1 {
}
Actual output:
b1 {
b2 l1 {
}
}
Issue is present for single and multiple nested blocks. Use Case: Removal of all terraform.before_hook.*
and terraform.after_hook.*
in a terragrunt configuration before running it in automation in order to prevent execution of scripts on CI/CD agent host.
I tried to add the findLongestMatchingBlocks
to unformattedBlockRemoveFilter
and got the matching block. However, I would need a hint on how to remove those longest matching blocks from the resulting file: https://github.com/minamijoyo/hcledit/blob/397e5f46bda35b45501b36b841afd8b9d683a0f4/editor/filter_block_remove.go#L47
@mhennecke Thank you for reporting this!
It should work as you expect, but it seems not. I think we cannot reuse the findLongestMatchingBlocks
method as it is because removing a block needs a body which the block belongs to.