6 ms·
There are definitely some oddities in HCL. Regarding the dynamic blocks, it gets weirder. If you have a dynamic block inside of a resource that is using for_eac
by sali0 6y ago
There are definitely some oddities in HCL. Regarding the dynamic blocks, it gets weirder. If you have a dynamic block inside of a resource that is using for_each, you can still reference the 'each' value alongside the value that the 'dynamic' block is looking at.
resource "example_resource" {
for_each = example_map
dynamic "foo" {
for_each = bar
content {
example_setting = each.value.setting
new_baz = foo.baz
}
}
}
The original for_each is referencing its object as 'each', while the for_each inside the dynamic is referencing the iteration as 'foo'. Why not just name the for_each inside the dynamic block as something else?
With that said, I absolutely love Terraform, and it is IMO the most powerful tool I've had the pleasure to work with. I also am a fan of DSLs if they are thoughtfully done. I think with some improvements, like some of the ones the author suggests, HCL could be a great language to work with.