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

miniature-library-50162

01/05/2024, 12:24 PM
What is the right way to convert pulumi.StringOutput to a native string in Go?
h

handsome-businessperson-23021

01/05/2024, 4:41 PM
try this:
.ElementType().String()
b

billowy-army-68599

01/05/2024, 5:34 PM
you can’t convert a string output to a string
what you can do, is resolve the value and then use it as a string. You do that with
ApplyT
m

miniature-library-50162

01/05/2024, 5:37 PM
I have created an ipv6 address with the hcloud provider, to create a rdns record for it I need to append a 1 (for the first real ip address), how should this be done? With ApplyT the result is still an Output type.
b

billowy-army-68599

01/05/2024, 5:38 PM
use
pulumi.Sprintf
m

miniature-library-50162

01/05/2024, 5:40 PM
Like this?
Copy code
&hcloud.RdnsArgs{
			PrimaryIpId: ipv6.ID().ApplyT(strconv.Atoi).(pulumi.IntOutput),
			IpAddress:   pulumi.Sprintf("%s:1", ipv6.IpAddress),
			DnsPtr: pulumi.String(strings.Join([]string{
				stack.config.Name,
				stack.config.Domain,
			}, ".")),
		},
b

billowy-army-68599

01/05/2024, 5:41 PM
should work
m

miniature-library-50162

01/05/2024, 5:42 PM
Yay... That worked...
Is something like
ipv6.ID().ApplyT(strconv.Atoi).(pulumi.IntOutput)
really the pulumi way to go to get the numeric ID of another created resource?
b

billowy-army-68599

01/05/2024, 5:44 PM
that’s likely a bug in the provider tbh, but yes that’s the canonical way
m

miniature-library-50162

01/05/2024, 5:44 PM
Great, thanks for the help. I have alrrady found an issue on the provider repository where somebody mentioned this as a possible solution.
2 Views