How can I convert a pulumi.StringOutput to string ...
# golang
c
How can I convert a pulumi.StringOutput to string ? I am provisioning an AWS codebuild, when trying to create a policy document some of the fields are for example
Resources
require a slice of string ([]string) , I wan to pass some values here that I am creating in the pulumi code as well. Is there any way to do this ? I can just put the string value there since resource arn format is pre determined, but is there any better way ?
b
You can't convert the value, only resolve it. To build your policy document you'd do it inside an ApplyT https://leebriggs.co.uk/blog/2021/05/09/pulumi-apply.html
f
@cold-orange-37453 Put an example here and I can try and help.
c
Copy code
codepipelineIAMPolicyDocument, err := piam.GetPolicyDocument(ctx, &piam.GetPolicyDocumentArgs{
		Statements: []piam.GetPolicyDocumentStatement{
			{
				Sid:     util.StringPtr("ECSLambdaInvokePermissions"),
				Effect:  &effectAllow,
				Actions: []string{"lambda:InvokeFunction"},
				Resources: []string{
					config.TaskDefLambdaArn,
					config.DeployLambdaArn,
				},
			},
		},
	}, pulumi.Parent(component))
For example here , Resources block requires a string of slice I am getting these values via the Getter method analogous to data block in terraform Example of one getter func
Copy code
gitCommitStatusLambda, err := plambda.GetFunction(ctx, "git-commit-status-lambda", pulumi.ID("git-commit-status"), nil)
	if err != nil {
		log.WithError(err).Error("failed to git commit status lambda")
		return err
	}
	z.GitCommitStatusLambda = gitCommitStatusLambda.ID().ToStringOutput()
this returns to me a pulumi.StringOutput , I want to be able to pass this value directly to the Resources block above , but it requires strings @fancy-spoon-7206 I guess in pulumi Getters can not depend on outputs , correct me if I am wrong
f
c
@fancy-spoon-7206 but here the return type is still pulumi.Output and I want the return type to be string instead
f
Inside the
apply
function the value is a string so you can
apply
where ever you need the value to be string.
c
got it, I have changed my getter functions to populate the result asynchronously
Copy code
wg.Add(1)
	gitCommitStatusLambda, err := plambda.GetFunction(ctx, "git-commit-status-lambda", pulumi.ID("git-commit-status"), nil)
	if err != nil {
		log.WithError(err).Error("failed to git commit status lambda")
		return err
	}
	gitCommitStatusLambda.ID().ToStringOutput().ApplyT(func (v string) {
		z.GitCommitStatusLambda = v
	})
Working for me now, IMO it would have been better if all the Getter functions could take args of the pulumi.Output type as well
Thanks!
b
@cold-orange-37453 there are GetFunctionOutput types which can take inputs/outputs
c
Ah got it, yes this would work perfectly for me. Thanks @billowy-army-68599!!!