hi, I would like to start VMs with "reserved IPs" ...
# azure
k
hi, I would like to start VMs with "reserved IPs" but I can't find a way to retreive those IPs nor how I should use then via pulumi ? https://github.com/pulumi/pulumi/discussions/14301
b
I'm guessing you have the IP resource outside of pulumi. Then just use the
network.get_public_ip_address()
function, and associate it with the NIC
this is part of my code, which doesn't use reserved IPs, just creates a new public IP before creating the NIC:
Copy code
# Create public IP if we need to
    if vm_data["public_ip"]:
        public_ip = network.PublicIPAddress(
            resource_name=f"{current_stack_name}_{vm_data['name']}_public_ip",
            public_ip_address_name=f"{vm_data['name']}_restore_public_ip",
            resource_group_name=resource_groups[vm_data["resource_group"]],
            tags=tags,
        )
    else:
        public_ip = None
    # Create a network interface for our VM
    network_interface = network.NetworkInterface(
        f"{current_stack_name}_{vm_data['name']}_nic",
        resource_group_name=resource_groups[vm_data["resource_group"]],
        ip_configurations=[
            network.NetworkInterfaceIPConfigurationArgs(
                name=f"{current_stack_name}_{vm_data['name']}_ipconfig",
                subnet=network.SubnetArgs(id=subnet.id),
                private_ip_allocation_method=network.IPAllocationMethod.DYNAMIC,
                public_ip_address=network.PublicIPAddressArgs(id=public_ip.id)
                if vm_data["public_ip"]
                else None,
            )
        ],
        enable_ip_forwarding=True if vm_data["public_ip"] else False,
        tags=tags,
    )
k
thanks for the tip. I ended up creating a manual resource group with IPs that I reference in a fully declarative resource group. One issue I have is that pulumi always complains that the resource group exists
b
there should be a getResourceGroup function, with which you can use the manually created group without having to manage it with pulumi. afaik there are 3 ways pulumi can use resources: 1. creates them, and so manages them (pulumi destroy deletes them) 2. one time import, but then pulumi manages them (pulumi destroy deletes them) 3. get* function, which just queries it's properties, and can be used as parameters/arguments creating other resources (pulumi destroy doesn't delete them)
k
usually pulumi can recognize when a resource was already created by pulumi and just skips to the next resource. For some reason it doesn't appear to be for resource groups, even though it was created by the same script, pulumi still complains and that surprises me
b
Yup that's weird. In my case the weird behavior was when I tried to get the address value of the created IP. The address property of the IPaddress resourve was always null, but if I did a getIpAddress query on the newly created resource, that contained the proper address value... so now my code creates and IPAddres resource, and then runs a getIpAddress() function against it to get the actual value.