https://pulumi.com logo
#golang
Title
# golang
b

big-account-56668

10/05/2020, 11:22 AM
How am I supposed to handle a case where I need a resource attribute as a string? I've got a GCP project resource and want the default service account
Copy code
p := organizations.NewProject(ctx, "p", &organizations.ProjectArgs{
			ProjectId:      pulumi.Sprintf("%s-%s", petName.ID(), ctx.Stack()),
		})
		sa, err := compute.GetDefaultServiceAccount(ctx, &compute.GetDefaultServiceAccountArgs{
			Project: &p.Name, // Project is a *string
		})
but this clearly yields type error
cannot use p.Name (variable of type pulumi.StringOutput) as *string value in struct literal
. Reading docs I've not been able to find the way to achieve this using either apply, lifting or interpolation.
l

lemon-agent-27707

10/05/2020, 3:09 PM
Gets/Invokes are typically synchronous in the pulumi provider SKDs. This means that outputs wont be compatible. So to you output values with a sync invoke/get you'll need to unwrap the outputs via
All
and
Apply
https://www.pulumi.com/docs/intro/concepts/programming-model/#apply https://www.pulumi.com/docs/intro/concepts/programming-model/#all
something like:
Copy code
p.Name.Apply(func(n){
// do the GetDefaultServiceAcc call here
})
Whatever you return from that call will be a new output. Note that it's not advised to create resources from within applies as this can break the dependency graph, but reading like this should be fine.
b

big-account-56668

10/06/2020, 9:18 AM
Ah, I see that makes sense. I did not know that they were synchronous. Thanks!
3 Views