kind-needle-67381
10/23/2023, 7:59 AMbumpy-glass-30283
10/24/2023, 8:23 AMnetwork.get_public_ip_address()
function, and associate it with the NIC# 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,
)