https://pulumi.com logo
Title
s

swift-agency-29333

03/28/2021, 3:47 PM
Can we convert pulumi.IDOutput to string and *string?
b

billowy-army-68599

03/28/2021, 6:54 PM
you'll need to use reflection and an apply to access the raw value. If you're willing to share some code, we might be able to help
s

swift-agency-29333

03/30/2021, 12:18 AM
@billowy-army-68599 Golang
Ec2_server, err = ec2.NewInstance(ctx, "fooInstance", &ec2.InstanceArgs{
			Ami:          pulumi.String("ami-005e54dee72cc1d00"),})

Ec2_server.ID() // this gives IDOutput type but I want this as string/*string.
l

little-cartoon-10569

03/30/2021, 12:35 AM
Where are you using that ID? If you're passing it to more Pulumi code, you can pass the output, you don't need the string. If you need the string version for something else, you have to use an ApplyT function, iirc.
w

white-balloon-205

03/30/2021, 1:33 AM
If you just need to convert
IDOutput
to
StringOutput
you can use
.ToStringOutput()
https://pkg.go.dev/github.com/pulumi/pulumi/sdk/v2@v2.23.2/go/pulumi#IDOutput.ToStringOutput
s

swift-agency-29333

03/30/2021, 2:50 PM
@little-cartoon-10569 @white-balloon-205 can you tell how to convert to string/*string in golang using applyT you are saying. I can’t figure that out new to pulumi as well as to golang.
@little-cartoon-10569 I am passing it to LookupInstance function which expects *string/string ID.
w

white-balloon-205

03/30/2021, 6:56 PM
I am passing it to LookupInstance function which expects *string/string ID.
You will need to call
LookupInstance
from inside the
.ApplyT
callback. Schematically
idoutput.ApplyT(func (id pulumi.ID) { return ec2.LookupInstance(... id ...).Ami })
.