Is there a way to convert `pulumi.StringOutput` to...
# golang
f
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
Copy code
natGatewayName := "natgw" + publicSubnets[0].AvailabilityZone
b
@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:
Copy code
natGatewayName := pulumi.Sprintf("natgw+ %s", publicSubnets[0].AvailabilityZone)
f
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,
Copy code
ec2.NewNatGateway(ctx, natGatewayName, ... )
wont work
b
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
Ahh that makes sense.