Use var in a dynamic block in a module

Hi there, I’m trying to write a module that accepts an object as a variable, however when I try to reference that variable in a dynamic block, terraform validate says that “var” isn’t defined…

resource "azurerm_frontdoor_firewall_policy" "fd_waf_policy" {
    name =
    resource_group_name = var.resource_group_name
    location = var.location

    dynamic "custom_rule" {
        for_each = var.policy
        content {

The error is this:

│ Error: Unknown variable

│ on modules\fd-waf\ line 11, in resource “azurerm_frontdoor_firewall_policy” “fd_waf_policy”:
│ 11: for_each = var.policy

│ There is no variable named “var”.

I’m using TF 1.2.1 on Windows

1 Like

There is no var. here - either the Terraform error message is incorrectly quoting your code (seems unlikely?), or your code isn’t actually the same as the code you posted in the code block in your post!

Yup I pasted the wrong output… I will edit original