sparse-intern-71089
11/04/2022, 2:29 PMpolite-ocean-13631
11/04/2022, 2:41 PMcache.host
will only be available as a string within the function being run by Output.apply
, so instead of trying to get a string out of it, you'll need to move the assignment (and whatever you wanted to do with the assignment) into it. If you have multiple Output
-wrapped values that you need at the same time, you can use Output.all
.purple-minister-96588
11/04/2022, 2:44 PMcache = redis_factory.create_redis(resource_name=name,
project=base_project,
tier=tier,
memory_size_gb=memory_size_gb,
region=region,
authorized_network=authorized_network,
display_name=name,
read_replicas_mode=read_replicas_mode,
connect_mode=connect_mode,
replica_count=replica_count,
redis_version=redis_version
)
host = cache.host.apply(lambda k: k)
dns_records.append(DnsRecord(name,
managed_zone=zone,
dns_type="A",
ttl=300,
routing_policy="simple",
data=host,
name=name))
So on this do I do
host = cache.host.Output.apply(lambda k: k)
Sorry this is basically my first week with Pulumi so I am obviously missing something.purple-minister-96588
11/04/2022, 2:45 PMcache = gcp.redis.Instance(...)
return cache
purple-minister-96588
11/04/2022, 2:47 PMurl = Output.all(hostname, port).apply(lambda l: f"http://{l[0]}:{l[1]}/")
So is that an Output.all(host).apply(lambda k: k) rather than try and tie it to the cache object?polite-ocean-13631
11/04/2022, 2:47 PMdef create_dns_record(host: str):
DnsRecord(
name,
managed_zone=zone,
dns_type="A",
ttl=300,
routing_policy="simple",
data=host,
name=name,
)
cache.host.apply(create_dns_record)
Maybe something like this would work? I assume this DnsRecord
class doesn't accept Output
-wrapped objects as arguments.polite-ocean-13631
11/04/2022, 2:49 PMOutput.all
is only useful when you want to do an Output.apply
on multiple Output
-wrapped values at once. so in the above code block if you also needed to pass in an output wrapped routing_policy
in addition to host
you could do something like:
Output.all(cache.host, routing_policy).apply(create_dns_record)
With create_dns_record
updated to take a list of strings instead of a single one.purple-minister-96588
11/04/2022, 2:55 PMdef create_dns_record(host: str, dns_record: DnsRecord, shared_project: str):
dns_factory = DnsFactory()
dns_factory.create_a_record(shared_project,
resource_name=dns_record.resource_name,
managed_zone=dns_record.managed_zone,
dns_type=dns_record.dns_type,
ttl=dns_record.ttl,
routing_policy=dns_record.routing_policy,
data=host,
name=dns_record.name
)
for dns_record in dns_records:
cache.host.apply(create_dns_record(cache.host,dns_record, shared_project))
Does this sound right?polite-ocean-13631
11/04/2022, 2:57 PMcache.host.apply
must be a function with a single str
parameter. You'll need to use
cache.host.apply(lambda host: create_dns_record(host, dns_record, shared_project))
Or functools.partial
purple-minister-96588
11/04/2022, 3:07 PMcache.host.apply(lambda host: create_dns_records(host, dns_records, shared_project))
def create_dns_records(host: str, dns_records: list, shared_project: str):
for dns_record in dns_records:
dns_factory = DnsFactory()
dns_factory.create_a_record(shared_project,
resource_name=dns_record.resource_name,
managed_zone=dns_record.managed_zone,
dns_type=dns_record.dns_type,
ttl=dns_record.ttl,
routing_policy=dns_record.routing_policy,
data=host,
name=dns_record.name
)
Thank you so much! This appears to be workingpolite-ocean-13631
11/04/2022, 3:07 PMpurple-minister-96588
11/04/2022, 3:08 PMechoing-dinner-19531
11/04/2022, 3:48 PMoutput.apply(x: x)
is basically a no op, so if you ever find yourself with that you can simplify to just output
.
One of our architects wrote a pretty good blog post about it a while ago: https://leebriggs.co.uk/blog/2021/05/09/pulumi-apply
Might help get your head around it.No matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.
Powered by