How to use the pulumi.StringPtrOutput value as a pulumi string input for another resource? #8939
-
I need to use the I need the autogenerated configmap name for HPA, Roles, and Deployment, but not sure how to get the pointer value as a pulumi.String for it to be used to correctly reference the configmap that was created. I couldn't find any other examples than the https://github.com/pulumi/examples/blob/64631b889938d7cfdf7a35016c989c898fe4b070/kubernetes-go-configmap-rollout/main.go#L39 example, which doesn't show any type of conversion taking place. Any tips? Example CodeCreating configmap. func ConfigMap(ctx *pulumi.Context, prov *kubernetes.Provider, configData *MyConfig) (generatedConfigMapName pulumi.StringPtrOutput, err error) {
// configData.ServiceConfigMapName() = "myexternalapi-project-dev-configmap"
configMapCreated, err := corev1.NewConfigMap(ctx, configData.ServiceConfigMapName(), &corev1.ConfigMapArgs{
Metadata: &metav1.ObjectMetaArgs{
Labels: configData.AppPulumiStringMap(), // labels are set from configstruct.
},
Data: configMapped,
}, pulumi.Provider(prov))
return generatedConfigMapName, nil
} Now I want to pass that into the deployment like this: err = Deployment(ctx, renderProvider, &configData, configMapName)
if err != nil {
return err
} And inside use it: func Deployment(ctx *pulumi.Context, prov *kubernetes.Provider, configData *MyConfig, configMapName pulumi.StringPtrOutput) error {
// ... lots of label/annotation code
// under podspec args:
Volumes: corev1.VolumeArray{
&corev1.VolumeArgs{
Name: pulumi.String(configData.ServiceConfigDataVolumeName()),
ConfigMap: &corev1.ConfigMapVolumeSourceArgs{
Name: configMapName, // 👈 This doesn't work as an input
},
},
} EDIT: I mostly have them working except for the volume assignment now: &rbacv1.PolicyRuleArgs{
ApiGroups: pulumi.StringArray{
pulumi.String(""),
},
Resources: pulumi.StringArray{
pulumi.String("configmaps"),
},
ResourceNames: pulumi.StringArray{
cfgMap.Metadata.Name(), // 👈 THIS cannot use cfgMap.Metadata.Name() (value of type pulumi.StringPtrOutput) as pulumi.StringInput value in array or slice literal: missing method ToStringOutput
},
Verbs: pulumi.StringArray{
pulumi.String("get"),
pulumi.String("watch"),
pulumi.String("list"),
},
},
}, The error for the last item is:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For the last volume, the way to properly reference the resource is: ResourceNames: pulumi.StringArray{
// CfgMap.Metadata.Name(),. won't work
cfgMap.Metadata.Name().Elem(), // 👈 DID WORK
}, Thanks to @itay for the help. |
Beta Was this translation helpful? Give feedback.
For the last volume, the way to properly reference the resource is:
Thanks to @itay for the help.
It was mentioned that this is where the Go type system gets in the way for just working, but with this fix, I'm good to go for now. Thanks! 💯