Any tips on decoding a kubeconfig (golang)? The eq...
# kubernetes
l
Any tips on decoding a kubeconfig (golang)? The equivalent to this in TF:
Copy code
kube_config_decoded = base64decode(k8s_resource.k8s_resource_name.kubeconfig)
I apologize if this isn't the right channel. This one kinda sits on the fence between #CRFURDVQB and #CCWP5TJ5U .
Maybe I'm overthinking, but it seems otherwise I have to convert
pulumi.StringOutput
to
string
,
base64 decode
, then back to
pulumi.StringOutput
for it to work with
kubernetes.NewProvider()
?
m
Not familiar enough with Go to know whether there's a shorter way of implementing it, but this Pulumi AI snippet that handles the decoding through
apply
on the output looks like the canonical Pulumi approach to me:
Copy code
decodedKubeconfig := resourceA.Kubeconfig.ApplyT(func(kubeconfig string) (string, error) {
			decoded, err := base64.StdEncoding.DecodeString(kubeconfig)
			if err != nil {
				return "", err
			}
			return string(decoded), nil
		}).(pulumi.StringOutput)
I think this is what you described in your comment as well?
l
Yeah this is what I'm looking for. Giving it a shot now...
m
Pulumi kind of flips the order compared to TF:
resource.output.apply(base64decode)
rather than
base64decode(resource.output)
l
Magnificent―that did it. simple smile Turns out the base64 encoding actually isn't the cause of the issue I'm having, but I needed to decode this anyways for some stuff downstream. Thanks for the help!
s
In general, you use
apply()
to get to the raw value (whenever it's ready), and then return another Pulumi output to use somewhere else in your program.