https://pulumi.com logo
Title
b

big-restaurant-51338

03/23/2020, 12:12 PM
hi! how do I retrieve the internal IP of a newly created
compute.Instance
? I tried this, but I get a KeyError
# actual vm creation
instance = compute.Instance("instance",
        machine_type=config.require('type'),
        boot_disk={
            "initializeParams": {
                "image": config.require('image')
                }
            },
        network_interfaces=[
            {
                "subnetwork": parentStack.get_output('subnet_id'),
                }
            ],
        # metadata={
        #     "startup-script": init_script
        #     },
        zone = config.require('zone'),
        tags = ["mytags"]
        )
# Register the DNS record
dns_name = parentStack.get_output('private_dns_zone').apply(lambda a: f"instance.{a}")
instance_recordset = dns.RecordSet("instance-recordset",
        managed_zone = parentStack.get_output('private_dns_name'),
        name = dns_name,
        rrdatas = [ instance.network_interfaces[0]['networkIp'] ],
        ttl = 3600,
        type = "A",
        opts=pulumi.ResourceOptions(depends_on=[instance]))
w

white-balloon-205

03/24/2020, 12:03 AM
I expect this is only an issue during the initial preview? I believe it is likely ultimately due to the same issue as https://github.com/pulumi/pulumi-azure/issues/192, and see also https://github.com/pulumi/pulumi/issues/4040. I believe you can workaround that with:
rrdatas = [ instance.network_interfaces[0].apply(lambda nic: nic.get('networkIp', 'unknown') ],