Any1 know how to get the value of a public IP addr...
# azure
b
Any1 know how to get the value of a public IP address? I get
<null>
anywhere I check, private IP of VMs/IP configurations work fine, all public IP related stuff is null. This is the output of the created PublicIP resource:
Copy code
{
    "ddos_settings": null,
    "delete_option": null,
    "dns_settings": null,
    "etag": "W/\"...\"",
    "extended_location": null,
    "id": "/subscriptions/.../resourceGroups/.../providers/Microsoft.Network/publicIPAddresses/...",
    "idle_timeout_in_minutes": 4,
    "ip_address": null,
    "ip_configuration": null,
    "ip_tags": [],
    "linked_public_ip_address": null,
    "location": "...",
    "migration_phase": null,
    "name": "...",
    "nat_gateway": null,
    "provisioning_state": "Succeeded",
    "public_ip_address_name": null,
    "public_ip_address_version": "IPv4",
    "public_ip_allocation_method": "Dynamic",
    "public_ip_prefix": null,
    "resource_group_name": null,
    "resource_guid": "...",
    "service_public_ip_address": null,
    "sku": {
        "name": "Basic",
        "tier": "Regional"
    },
    "tags": {
        ...
    },
    "type": "Microsoft.Network/publicIPAddresses",
    "urn": "urn:pulumi:...::...::azure-native:network:PublicIPAddress::...",
    "zones": null
}
if I do an
az network public-ip show -n <name> -g <group>
command, then the public address shows up
well, I found a hacky workaround: If I do a
network.get_public_ip_address()
on the created resource, I get back the public IP value.
problem is the
get_
function doesn't respect the parent child relation (which is understandable, it is meant to pull in outside resources). So if I try to create the stack from scratch, it errors out with a
ResourceNotFound
exception.
so far I came up with this code:
Copy code
if vm_data["public_ip"]:
        # exporting the created public IP resource gives back <null>, we need to do a get_, to retrieve the actual value
        # try-except block is a hack to let the code run when creating it from scratch
        # otherwise the code raises a generic Exception while running the preview
        try:
            public_ip2 = network.get_public_ip_address(
                public_ip_address_name=public_ip.name,
                resource_group_name=resource_groups[vm_data["resource_group"]],
            )
            pulumi.export(f"{vm_data['name']} public IP: ", public_ip2.ip_address)
        except Exception as e:
            pass
problem with the above code is the get runs before the actual resource is created, so for the first
pulumi up
it doesn't give back anything. On a subsequent run it correctly returns the public IP.