I used pulumi python to create multiple azure VMs.
Basically, I just put the example code from azure-py-webserver into a loop, of course, each resource has its unique name with the index of the loop. I expected the export
statement at the end of the loop would show me the public IPs of all VMs after they were created.
for i in range(2):
vm_name = f"sol{i}"
...
...
...
public_ip_addr = vm.id.apply(lambda _: network.get_public_ip_address_output(
public_ip_address_name=public_ip.name,
resource_group_name=resource_group.name))
export(f"{vm_name} IP", public_ip_addr.ip_address)
All resources were created successfully, but the export output always showed a same IP for all VMs as below.
Type Name Status
+ pulumi:pulumi:Stack azure-vms-dev created
+ ├─ azure-native:resources:ResourceGroup resource_group created
+ ├─ azure-native:network:VirtualNetwork sol_VNET created
+ ├─ azure-native:network:PublicIPAddress sol0_PublicIP created
+ ├─ azure-native:network:PublicIPAddress sol1_PublicIP created
+ ├─ azure-native:network:NetworkInterface sol0_Nic created
+ ├─ azure-native:network:NetworkInterface sol1_Nic created
+ ├─ azure-native:compute:VirtualMachine sol1 created
+ └─ azure-native:compute:VirtualMachine sol0 created
Outputs:
sol0 IP:: "20.239.154.16"
sol1 IP:: "20.239.154.16"
Resources:
+ 9 created
Duration: 1m55s
My question is, how could I export the public IPs of all VMs?