Hey all. I'm having some issues with outputters. I...
# general
p
Hey all. I'm having some issues with outputters. I'm working with the GCP provider and python. Essentially, I'm trying to gather the results of an instance create (pulumi_gcp.compute.Instance()), then proceed to reserve the address of that instance via the results/output. I'm not looking to export the output of this but for the sake of troubleshooting, I'm able to export the network interfaces via result.network_interfaces. As this is a list of dicts, I can also export result.network_interfaces[0]. Once I try to access the keys in the dictionaries, I hit issues. No matter what key I try to reference, I get a key error. If I try to access the key as if it's an attribute, I get dict has no attribute 'networkIp'. Is there something I'm missing here?
So, after a few hours of fiddling, I was able to extract the IP address of the first interface. I'm not sure if this is intended behaviour or not. Please let me know if I should file a bug report for this. Essentially, I had to apply the property I wanted. I couldn't just retrieve them though.
# This results in a key error
result.network_interfaces[0].apply(lambda net: net['networkIp'])
# This successfully retrieves the key
result.network_interfaces[0].apply(lambda net: net.get('networkIp'))
I've only tested this with exports so far. I'll try actually using this output as the input for create addresses in GCP
As an FYI, this solution works for retrieving the required keys. It's a bit odd though... in my opinion.