https://pulumi.com logo
#general
Title
# general
s

sparse-state-34229

04/12/2020, 7:37 AM
neither
str(vpc.cidr_block[0]['resourceRecordValue'])
nor
str(vpc.cidr_block[0].resource_record_value)
work
unless
resource_record_value
is a route53 thing. if so, it would be helpful to use more general examples
b

big-piano-35669

04/12/2020, 4:00 PM
Lifting doesn't allow the object to masquerade as the underlying value in all cases -- only for basic property accesses. And even then the result of the lifting itself is an "output". The
apply
function is generally what you want here:
Copy code
def dothing(vpc):
    vpc.cidr_block.apply(do_thing)
A bit more detail here: https://www.pulumi.com/docs/intro/concepts/programming-model/#apply. The reason for this is that the value for a given resource property isn't always known until actually provisioning the resource.
s

sparse-state-34229

04/12/2020, 6:51 PM
thanks…i tried that but it’s still returning an
Output
which is causing an issue for L4 and L22 here
(the print isn’t a big deal - just trying to validate that it’s actually a string)
if L2 is e.g.
vpc_network = ip_network('10.0.0.0/8')
it works fine
f

faint-table-42725

04/13/2020, 5:36 AM
i replied in a separate thread as well, but
apply
will return an
Output
you should think of
Output
as a promise or async task
so we don’t know necessarily know the value and so we must deal with that in an async way
in the gist you provided,
vpc_network
is still an
Output
— if you want to print it, L3 should be
vpc_network.network_address.apply(print)
— you’re able to reference
network_address
through lifting; the more literal way to write this would be
vpc_network.apply(lambda v: print(v.network_address))
s

sparse-state-34229

04/15/2020, 7:19 AM
thanks, I get what you’re saying but in practice it doesn’t make sense. if I try
vpc_name = Output.all(tags).apply(lambda x: x[0].get('Name'))
then
vpc_name
is still an Output, but according to the docs that is lifting?
when I try to use
vpc_name
later in a formatted string it doesn’t work
e.g.
awsec2SecurityGroup (<pulumi.output.Output object at 0x10ed737c0>-bastion-ingress):
error: Error creating Security Group: InvalidParameterValue: Invalid security group name. Valid names are non-empty strings less than 256 characters from the following set: a-zA-Z0-9. _-:/()#,@[]+=&;{}!$*
status code: 400, request id: 210d586d-f079-45cd-9450-637c32c0f324
I’m either not sufficiently explaining what I want to do or it is just not possible
the call that causes that error is
Copy code
vpc_name = Output.all(tags).apply(lambda x: x[0].get('Name')) # tags are a pulumi_aws.ec2.Vpc object tags
        name = f'{vpc_name}-bastion-ingress' 
        bastion_ingress = ec2.SecurityGroup(name,
                                            name=name,
even if i use apply when assigning
name
it is an output
which causes an exception on the name parameter to
ec2.SecurityGroup