https://pulumi.com logo
Title
b

better-actor-92669

11/24/2020, 5:13 PM
Hello. I use pulumi_gcp and examples below are going to be GCP related. I want to add a dns record with a value of some instance's IP address. If target instance has already been created, the reference below works perfectly (I use a list of instance objects):
#         rrdatas=[
#           dbs_instance_pulumi_objects[item].
#           network_interfaces[0]['networkIp'],
#         ],
But when you initiate the stack for the first time in a new project and all instances are yet to be created alongside DNS records, 
networkInterfaces
 only contains this
networkInterfaces     : [
            [0]: {
                subnetwork: output<string>
            }
        ]
When some instance is finally created, it becomes
networkInterfaces
[
  {
    "accessConfigs": [],
    "aliasIpRanges": [],
    "name": "nic0",
    "network": "<https://www.googleapis.com/compute/v1/projects/some-project/global/networks/vpc-network-default-b803ef2>",
    "networkIp": "10.122.0.3",
    "subnetwork": "<https://www.googleapis.com/compute/v1/projects/some-project/regions/europe-west1/subnetworks/vpc-subnetwork-default-bab788a>",
    "subnetworkProject": "some-subnetwork"
  }
]
How can I ask pulumi to wait for the value, even though the key is not present yet? Or how should I reference it properly?
w

witty-candle-66007

11/24/2020, 7:20 PM
When you say
initiate the stack
and then
when some instance is finally created
are you referring to the preview part of a
pulumi up
as that first bit and the actual deployment as the second bit? If so, pulumi preview is not able to show actual values for resource properties since it doesn’t know them yet. Once you let it deploy then it’s able to show the properties. Regardless, if you use outputs from one resource as inputs to another resource, Pulumi will manage the dependencies.
b

better-actor-92669

11/24/2020, 8:07 PM
Well, the problem is that the preview throws the error that ‘networkIp’ key is not found.
w

witty-candle-66007

11/24/2020, 9:17 PM
Oh, sorry I see what you’re saying now. Have you tried using
.apply()
to essentially tell Pulumi the answer is coming later: https://www.pulumi.com/docs/intro/concepts/programming-model/#outputs
b

better-actor-92669

11/24/2020, 9:48 PM
Yeah, I did. I tried something I do very often in my projects: Output.all(dbs_instance_pulumi_objects).apply(lambda x: x[0].network_interfaces[0][“networkIp”]), but it doesn’t work in this case, that’s why I brought up this topic. Sorry that I do not have a proper formatting, I am on my phone now.
For someone who has encountered the same issue:
backend_instance_pulumi_objects[item].network_interfaces.apply(
                lambda x: x[0].get('networkIp')
            ),
The Code snippet above worked for me in the end
For someone who has encountered the same issue:
backend_instance_pulumi_objects[item].network_interfaces.apply(
                lambda x: x[0].get('networkIp')
            ),
The Code snippet above worked for me in the end