How the generate bock get parsed ?
Hi, I have a fairly technical question about terragrunt. I am currently playing with it and I noticed a behavior that I am not sure if it is intended or not. So I have this terragrunt file. I am not going to post it all, just the relevant part. ``` locals { project_id = "my-cool-project" } generate "main_providers" { path = "0001-providers.tf" if_exists = "overwrite" contents = <<EOF provider "google" { project = local.project_id } EOF } ``` When I use a file like that, I get this error : ``` │ Error: Reference to undeclared local value │ │ on 0001-providers.tf line 3, in provider "google": │ 3: project = local.project_id │ │ A local value with the name "project_id" has not been declared. ``` Which make kind of sense, local.project_id does not exist yet when terragrunt parse it. However, if I change the offending line from `local.project_id` to `"${local.project_id}"`, the file correctly get generated using the local variable value. Is this an intended behavior and is it documented somewhere ? Thanks! --- <ins datetime="2022-07-25T17:19:56Z"> <p><a href="https://support.gruntwork.io/hc/requests/109050">Tracked in ticket #109050</a></p> </ins>
This is intended behavior. It's sort of documented in that the `contents` is interpreted as a `string`, and in HCL, you need to interpolate values with `${}` to have it render values available in the `terragrunt` context. So it's more a feature/quirk of the HCL language and not necessarily specific to Terragrunt. But I can totally see that being confusing to beginners of Terragrunt. If you have a suggestion on where it would make the most sense to highlight this in the Terragrunt docs, we can definitely update it to include some information about the templating aspects of `generate`!