https://pulumi.com logo
#azure
Title
# azure
k

kind-needle-67381

10/23/2023, 7:59 AM
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

bumpy-glass-30283

10/24/2023, 8:23 AM
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,
    )
2 Views