https://pulumi.com logo
Title
f

fancy-spoon-7206

06/17/2022, 4:01 PM
Is there a way to convert
pulumi.StringOutput
to
string
? Its becoming weirdly difficult for me to get the tags right with all the custom types that don't seem to have a straight forward way to convert to string. The below does not work as
natgw
is a string and
publicSubnets[0].AvailabilityZone
is a StringOutput
natGatewayName := "natgw" + publicSubnets[0].AvailabilityZone
b

billowy-army-68599

06/17/2022, 4:16 PM
@fancy-spoon-7206 no, you can't convert an output to a string. you can only resolve the output and then use the string value. see here for an explanation as to why: https://leebriggs.co.uk/blog/2021/05/09/pulumi-apply
for your specific example though, you can do:
natGatewayName := pulumi.Sprintf("natgw+ %s", publicSubnets[0].AvailabilityZone)
f

fancy-spoon-7206

06/17/2022, 4:25 PM
If I do that, then natGatewayName is of type StringOutput and I cannot give that as an input to any function as a string. For example,
ec2.NewNatGateway(ctx, natGatewayName, ... )
wont work
b

billowy-army-68599

06/17/2022, 4:39 PM
you cannot use an output as a resource name, unfortunately. it needs to be known at run time. if you want to do what you're trying to do, you'd have to do it inside an
ApplyT
but then your previews wouldn't be valid
f

fancy-spoon-7206

06/17/2022, 4:43 PM
Ahh that makes sense.