how to convert a pulumi.StringOutput into regular ...
# general
r
how to convert a pulumi.StringOutput into regular string? this doesn't work
fmt.Print(string(githubPAT.Value()))
p
Have you tried asking https://www.pulumi.com/ai ?
r
will try 🙂
Copy code
strgithubPAT := githubPAT.Value().ToStringOutput().ApplyT(func(s string) (string, error) {
		// Now you can work with 's' as a standard Go string
		// Here we're just passing it through
		return s, nil
	}).(pulumi.StringOutput)

	// Export the string
	ctx.Export("outputS", strgithubPAT)
how can i pass it to this?
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s",  strgithubPAT))
m
You can’t. This is often a bit surprising, see here for the reason. You need to do whatever you need to do with the string inside
ApplyT
.
p
Just to mention, there's also
pulumi.Sprintf()
instead of
fmt.Sprintf()
r
it doesn't like the
pulumi.Sprintf
bcoz
Set
requires a string?
it doesn't complain with
fmt.Sprintf
but preview shows Unauthorized meaning something off with the conversion of pulumi string to regular go string.
Copy code
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", githubPAT.Value().ApplyT(func(value string) string {
		return value
	})))
p
I'm sorry to say that I'm no expert on this myself. I usually ask the AI to provide a solution and test it out, but I haven't been using Pulumi or Go for that matter long enough to provide expert help here 😞
r
no worries. will share it too once i figured it out :)