future-france-34957
09/21/2022, 6:36 PM~ hosted_zones: [
~ [0]: {
arn : "arn:aws:route53:::hostedzone/Z06813069DDF4BVP5B49"
comment : "Hosted Zone for <http://env.example.com|env.example.com>"
force_destroy : false
id : "Z06813069DDF4BVP5B49"
name : "<http://env.example.com|env.example.com>"
name_servers : [
[0]: "<http://ns-1074.awsdns-09.org|ns-1074.awsdns-09.org>"
[1]: "<http://ns-1944.awsdns-52.co.uk|ns-1944.awsdns-52.co.uk>"
[2]: "<http://ns-475.awsdns-53.com|ns-475.awsdns-53.com>"
[3]: "<http://ns-948.awsdns-52.net|ns-948.awsdns-52.net>"
]
tags_all : {
provisioner: "pulumi"
}
urn : "urn:pulumi:all::shared::aws:route53/zone:Zone::<http://env.example.com|env.example.com>"
zone_id : "Z06813069DDF4BVP5B49"
}
~ [1]: {
arn : "arn:aws:route53:::hostedzone/Z05663573HLFBZ66YBFM2"
comment : "Hosted Zone for env.example.link"
force_destroy : false
id : "Z05663573HLFBZ66YBFM2"
name : "env.example.link"
name_servers : [
[0]: "<http://ns-1311.awsdns-33.org|ns-1311.awsdns-33.org>"
[1]: "<http://ns-1733.awsdns-22.co.uk|ns-1733.awsdns-22.co.uk>"
[2]: "<http://ns-191.awsdns-21.com|ns-191.awsdns-21.com>"
[3]: "<http://ns-786.awsdns-36.net|ns-786.awsdns-36.net>"
]
tags_all : {
provisioner: "pulumi"
}
urn : "urn:pulumi:all::shared::aws:route53/zone:Zone::env.example.link"
zone_id : "Z05663573HLFBZ66YBFM2"
}
]
I want to get, for example, the zone_id
where name
= <http://env.example.com|env.example.com>
My thought was to search the array for the index, for example, where name
= <http://env.example.com|env.example.com>
, in this case [0]
and then get the the value of zone_id
at that index (similar to this https://stackoverflow.com/a/19868472)
However, since this is a Pulumi Output object, I can’t iterate it like that:
TypeError: 'Output' object is not iterable, consider iterating the underlying value inside an 'apply'
So I attempted to first convert the object to json, using a render function (which has worked for me when needing a Pulumi Output object as a string, like this https://stackoverflow.com/a/73558276/18101704) but that doesn’t work either:
def get_shared_hosted_zones_to_string(shared_hosted_zones):
return json.dumps(shared_hosted_zones)
def get_zone_index(shared_hosted_zones_string, name):
return next(index for index, element in enumerate(shared_hosted_zones_string)
if element["name"] == name)
# For each domain, create Hosted Zone
# i.e. (<http://uat.env.example.com|uat.env.example.com>, uat.env.example.link)
for domain, name in domains.items():
hosted_zone = route53.Zone(
resource_name=f"{env_stack}.{domain_prefix}.{name}",
name=f"{env_stack}.{domain_prefix}.{name}",
comment=f"Hosted Zone for {env_stack}.{domain_prefix}.{name}",
tags=TAGS,
opts=ResourceOptions(protect=True)
)
shared_hosted_zones_string = Output.all(shared_hosted_zones).apply(
lambda shared_hosted_zones: get_shared_hosted_zones_to_string(shared_hosted_zones))
# select the hosted zone id where shared_hosted_zones.[].name == domain name
# i.e. which object in the hosted_zones array has name : "<http://env.example.com|env.example.com>",
# because need to get that zone_id
shared_hosted_zone = shared_hosted_zones_string[get_zone_index(
shared_hosted_zones_string, domain_prefix + name)]
shared_hosted_zones_string
is of type Output though. I don’t fully understand how this works here, but not in this case?
Any ideas?billowy-army-68599
09/21/2022, 6:38 PMapply
future-france-34957
09/21/2022, 6:39 PMshared_hosted_zone_ids = Output.all(shared_hosted_zones).apply(
lambda shared_hosted_zones: zone["zone_id"] for zone in shared_hosted_zones if zone["name"] == f"{domain_prefix}.{name}")
but still get
TypeError: 'Output' object is not iterable, consider iterating the underlying value inside an 'apply'
billowy-army-68599
09/21/2022, 6:52 PMfuture-france-34957
09/21/2022, 9:52 PMbillowy-army-68599
09/21/2022, 9:57 PM