-1

I have the following list of objects defined as a local:

 agw_configs = [
    {
      env                     = "dev"
      function                = "events"
      backend_pool_fqdn       = "dev.servicebus.windows.net"
      cookie_based_affinity   = "Enabled"
      https_listener_hostname = "ingestiondev.co.uk"

    },
    {
      env                     = "test"
      function                = "events"
      backend_pool_fqdn       = "test.servicebus.windows.net"
      cookie_based_affinity   = "Enabled"
      https_listener_hostname = "ingestiontest.co.uk"
    }
  ]

I now want to use multiple dynamic blocks within an Azure application gateway resource to create various settings for each environment. However I cannot figure out how to do this and keep getting undeclared resource errors. Here is my current config:

resource "azurerm_application_gateway" "application_gateway" {
  name                = local.application_gateway_name
  resource_group_name = var.resource_group_name
  location            = var.location

  sku {
    name     = var.sku.size
    tier     = var.sku.tier
    capacity = var.sku.capacity
  }

 ...

  dynamic "backend_address_pool" {
    for_each = local.agw_configs
    content {
      name  = "${var.region}-${agw_configs.value.env}-${agw_configs.value.function}-beap"
      fqdns = [agw_configs.value.backend_pool_fqdn]
    }
  }

Feels like i am almost there but not sure where I am going wrong

  • I think you want `backend_address_pool` followed by the variable keys, e.g., instead of `${var.region}-${agw_configs.value.env}-${agw_configs.value.function}-beap` try `${var.region}-${backend_address_pool.value.env}-${backend_address_pool.value.function}-beap`. – Marko E Nov 24 '22 at 21:43
  • What errors do you get? – Marcin Nov 24 '22 at 22:26

1 Answers1

0

See an example that it works: 1/ Define the variable - with the

variable "backend_pools" {
  type = map(string({
    fqdn           = string
    ip_addresses   = string
  }))
  #Define default value
  default = {
    "Pool1" = {
      fqdns = "fqdns1"
      ip_addresses = "10.0.0.0"
    }
    "pool2" = {
      fqdns = "fqdns1"
      ip_addresses = "10.10.0.0"
    }

Then you can use the var from dynamic block into your azurerm_application_gateway block:

dynamic "backend_address_pool" {
    for_each = var.backend_pools

    content {
      fqdns = backend_address_pool.value.fqdn
      ip_addresses = backend_address_pool.value.ip_addresses
    }
  }