resource "azurerm_public_ip" "instance_public_ip" {
count = var.assign_public_ip == "true" ? 1 : 0
name = "${var.name}-public-ip"
location = var.location
resource_group_name = var.resource_group_name
allocation_method = "Dynamic"
}
resource "azurerm_network_interface" "main" {
name = "${var.name}-nic"
location = var.location
resource_group_name = var.resource_group_name
ip_configuration {
name = "${var.name}-NIC-Configuration"
subnet_id = var.subnet_id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.instance_public_ip.id
}
}
This is my problem I only want to set public_ip_address_id attribute if the azure_rm_public_ip resource is created is this possible?
I’m not sure if this is possible.
2
Answers
There are several methods to accomplish this, but the easiest is probably with the
try
function:What I would probably do is the following, since you are using the
count
meta-argument to create theazurerm_public_ip
resource: