I have a dynamic block in a resource
dynamic "ip_configuration" {
for_each = var.nic_ip_configuration
content {
gateway_load_balancer_frontend_ip_configuration_id = <DATA_SOURCE>
public_ip_address_id = <DATA_SOURCE>
}
}
The variable nic_ip_configuration
would be a list of objects
[
{
ip_configuration_name = "1"
gateway_load_balancer_frontend_ip_configuration_name = "abc"
public_ip_address_name = "def"
},
{
ip_configuration_name = "2"
gateway_load_balancer_frontend_ip_configuration_name = "ghi"
public_ip_address_name = "jkl"
}
]
I would like to be able to use the public_ip_address_name
in each object and pass that to a data block to get the ID, and then use the ID value from the data source when iterating through each object in the dynamic block. This way I’d only need to know the IP address name in my configuration.
I am not sure what the best approach is here.
In my data source where I retrieve the ID value would I want to create a key-value mapping where ip_configuration_name
is the key and ID is the value
data "azurerm_public_ip" "example" {
for_each = { for item in var.nic_ip_configuration: item.name => item }
name = each.value.public_ip_address_name
I was testing with an output like this to see what the end result looks like from the data block
output "test_public_ip" {
value = { for k,v in data.azurerm_public_ip.example: k => {public_ip_address_id = v.id} }
}
This does get me close to where the output result is
test_public_ip = {
"1" = {
public_ip_address_id = "<ID_STRING>"
}
}
Would I want to move that output logic to a local value, and then attempt to merge that object back into nic_ip_configuration
based on the ip_configuration_name
being a key for the merge?
What if I also wanted to do the same for the gateway load balancer IP and get that merged in?