bumpy-bear-61087
10/27/2021, 8:48 AMstring
from Output
? I'd like to get the string from containerDefaultSA.Email
, but I don't get the docs at https://www.pulumi.com/docs/intro/concepts/inputs-outputs/
containerDefaultSA, _ := projects.NewServiceIdentity(p.ctx, "hcSa", &projects.ServiceIdentityArgs{
Project: pulumi.String(p.projectID),
Service: pulumi.String("<http://container.googleapis.com|container.googleapis.com>"),
})
kmsIAM, err := organizations.LookupIAMPolicy(p.ctx, &organizations.LookupIAMPolicyArgs{
Bindings: []organizations.GetIAMPolicyBinding{{
Role: "roles/cloudkms.cryptoKeyEncrypterDecrypter",
Members: []string{
pulumi.Sprintf("serviceAccount:%s", containerDefaultSA.Email),
}},
},
}, nil)
busy-insurance-52853
10/27/2021, 12:58 PMbumpy-bear-61087
10/27/2021, 1:15 PMstring
from an StringOutput
, not the other way around.busy-insurance-52853
10/27/2021, 2:13 PMlimited-rainbow-51650
10/27/2021, 2:23 PMstring
? Out of experience (mainly in Typescript), you have to change how you look at the problem and write your code differently. Have a look at the Apply
function here: https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#apply
In the example, click on the Go
language selector just above the source code.bumpy-bear-61087
10/27/2021, 2:24 PMkmsIAM, err := organizations.LookupIAMPolicy(ctx, &organizations.LookupIAMPolicyArgs{
Bindings: []organizations.GetIAMPolicyBinding{{
Role: "roles/cloudkms.cryptoKeyEncrypterDecrypter",
Members: []string{
fmt.Sprintf("serviceAccount:%s", containerDefaultSA.Email),
}},
},
}, nil)
So it's basically a text operation I need to do on an attribute of another object.limited-rainbow-51650
10/27/2021, 2:27 PMorganizations
is this? AWS? Do you have a pointer to the docs for me on this?bumpy-bear-61087
10/27/2021, 2:28 PMlimited-rainbow-51650
10/27/2021, 2:51 PMApply
function. Here is my best attempt on rewriting your snippet using `Apply`:
containerDefaultSA.Email.ApplyT(func(email string) (*return type, err) {
return organizations.LookupIAMPolicy(ctx, &organizations.LookupIAMPolicyArgs{
Bindings: []organizations.GetIAMPolicyBinding{{
Role: "roles/cloudkms.cryptoKeyEncrypterDecrypter",
Members: []string{
fmt.Sprintf("serviceAccount:%s", email),
}},
},
}, nil)
return kmsIAM
}).(cast to pulumi.Output of correct type)
First line is your pulumi.StringOutput
where you apply a function on the raw value (email
) and the return value is again wrapped in an output. You should cast to the right type on the last line, but that I don't know how to write in Golang.Output
that way: a bucket which can contain a value at a certain point in time and where you apply a transformation function on. The transformed value (or struct) is again contained in another bucket (Output
).bumpy-bear-61087
10/27/2021, 2:59 PMerror
and something else in a cast. 🤔
containerDefaultSA.Email.ApplyT(func(email string) (*organizations.LookupIAMPolicyResult, error){
kmsIAM, err = organizations.LookupIAMPolicy(p.ctx, &organizations.LookupIAMPolicyArgs{
Bindings: []organizations.GetIAMPolicyBinding{{
Role: "roles/cloudkms.cryptoKeyEncrypterDecrypter",
Members: []string{
fmt.Sprintf("serviceAccount:%s", email),
}},
},
}, nil); if err != nil {
return nil, errors.Wrap(err, "could not get IAM policy")
}
return kmsIAM, nil
}).(*organizations.LookupIAMPolicyResult, error)
limited-rainbow-51650
10/27/2021, 3:01 PMbumpy-bear-61087
10/27/2021, 3:02 PMlimited-rainbow-51650
10/27/2021, 3:02 PMbillowy-army-68599
bumpy-bear-61087
10/27/2021, 9:14 PM