Any way to Fetch computed value

Hello,

For Azure, Private Endpoint resource , private_ip_address is a computed value.

For Private DNS A Record , only IP address is allowed.

Is there a way that I can fetch the computed value(private_ip_address) and use it in Private DNS A Record .
(records = [azurerm_private_endpoint.example.private_ip_address])

If i try to use it like an attribute , I get an error.
Object does not have an attribute named private_ip_address.


Hi @sam,

The error you saw here is not an error related to computed values. It seems like something else is going on here, but I can’t say what it would be without seeing your full configuration. Can you share what you’ve written in a comment here (you can use the “<>” icon in the editor toolbar to mark it as code so it’ll be readable) and also share the full text of the error message you saw, so it’s obvious exactly which part of the configuration the error is referring to?

I am looping a list of Private Endpoints. Trying to create both a private endpoint and add a DNS A Record.
Key is the private endpoint name.
Also I am able to access the id parameter but not private_ip_address.
I have edited the text a bit. Let me know if you need any more clarifications

Below is the error message

Error: Unsupported attribute

records = [azurerm_private_endpoint.apre[each.key].private_ip_address]

azurerm_private_endpoint.apre is an object with 1 attribute "priv_endpt_nm"
each.key is "priv_endpt_nm"

This object does not have an attribute named "private_ip_address"
resource "azurerm_private_endpoint" "apre" {
  foreach = {for k in private_endpoint_list : k.pe_name => k}
  name                = each.key
  location            = each.value.location            
  resource_group_name = each.value.resource_group_name 
  subnet_id           = each.value.subnet_id

  private_service_connection {
    name                           = each.value.psc_name
    private_connection_resource_id = each.value.private_connection_resource_id 
    is_manual_connection           = false
  }
}

resource "azurerm_private_dns_a_record" "adar" {
  foreach =  {for k in private_endpoint_list : k.pe_name => k}
  name                = each.value.dns_name
  zone_name           = each.value.zone_name
  resource_group_name = each.value.resource_group_name 
  ttl                 = 300
  records             = [azurerm_private_endpoint.apre[each.key].private_ip_address]
}

Hi again, @sam! Thanks for the additional context.

I must admit that I’m not at all familar with these AzureRM provider features, so I’m guessing a bit here. With that said, I’m looking at the azurerm_private_endpoint documentation and it seems like private_ip_address is an attribute belonging to nested private_service_connection blocks rather than directly to the resource instance object, so I think to access it you will need to traverse to that block first:

azurerm_private_endpoint.apre[each.key].private_service_connection[0].private_ip_address

What a silly miss !! :expressionless:
Thank you so much for pointing it out ! :slightly_smiling_face: