Quantcast
Channel: Terraform - HashiCorp Discuss
Viewing all articles
Browse latest Browse all 11529

Accessing output of child module that is enabled/disabled using count

$
0
0

Terraform verison: 0.12.24

AzureRm: 2.0.0

I am using “count” to enable/disable child module. When i am trying to feed the output of child module to the parent module, i am running into issues.

Child module:
Backend address pool creation resource block of the child module.

resource "azurerm_lb_backend_address_pool" "lb-backendpool" {
  count = var.enable_lb == true ? 1 : 0
  resource_group_name = var.rgname
  loadbalancer_id     = element(azurerm_lb.lb.*.id, count.index)
  name                = "BackEndAddressPool"
}

Output of child module:

output "modout_poolid" {
  value      = azurerm_lb_backend_address_pool.lb-backendpool.*.id
}

Parent module:

resource "azurerm_network_interface_backend_address_pool_association" "nic-lbpool" { 
  for_each                = var.enable_lb == true ? azurerm_network_interface.nic : {}
  network_interface_id    = each.value.id
  ip_configuration_name   = "ipconfig01"
  backend_address_pool_id = [module.azure_lb.modout_poolid]
}

Terraform plan


Error: Incorrect attribute value type

 main.tf line 47, in resource "azurerm_network_interface_backend_address_pool_association" "nic-lbpool":
  47:   backend_address_pool_id = [module.azure_lb.modout_poolid]

Inappropriate value for attribute "backend_address_pool_id": string required.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 11529

Trending Articles