Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Would love to assign a dynamic block's contents as a whole, without specifying the details #25025

Open
vfab opened this issue May 24, 2020 · 4 comments

Comments

@vfab
Copy link

vfab commented May 24, 2020

Is there any way to assign the contents of a dynamic block by passing in a single variable that defines its contents? For example, with an Azure App Service there is a site_config block, which has a lot of arguments. I would like to declare a variable named site_config of type any and set the contents of the dynamic block to equal my variable.
Instead of

  dynamic site_config {
    for_each = coalesce(var.site_config, [])
    content {
      app_command_line          = lookup(each.value, "app_command_line", null)
      auto_swap_slot_name       = lookup(each.value, "auto_swap_slot_name", null)
      . . .
    }

I would like to do something like

  dynamic site_config {
    for_each = coalesce(var.site_config, [])
    content = var.site_config
   }

If this isn't currently possible I think this would be a great enhancement. But if it is possible please share some sample code.

Thanks!

@dvishniakov
Copy link

I have a similar annoying experience with AWS WAFv2, which changed their resource definitions and instead of being able to set a simple interpolated value for the default action property now we have to define a nested block.

I don't know the syntax which will allow to interpolate the name of the block which could make that simple. In WAFv2 that's 'allow' or 'block'. I've found a workaround but it's ugly. It requires 6 lines (for 2 possible values) instead of 1 interpolated line.
What probably was an improvement over how final JSON looks and simplify it a bit resulted in a burden in Terraform code.

@dvishniakov
Copy link

Regarding author's enhancement - may be to shorten the syntax even more and to get contents of the blocks directly from the variable?

dynamic site_config {
  interpolated_content = var.site_config # or local.site_config
}

@kingindanord
Copy link

1+

@jarekmisz
Copy link

I have the same frustrating experience with site_config in Azure function app service. I'd need to assign a dynamic map to the content. The syntax proposed by dvishniakov is an elegant and simple solution.
Generally, this seems to be a serious limitation of the block construct. I wonder why there are just a few people tracking this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants