Hi all, Can someone help me with Pulumi and golang...
# general
c
Hi all, Can someone help me with Pulumi and golang? How can I marshal
pulumi.StringOutput
and then use it in
ctx.Export
?
m
Hi, you should be able to use the
StringOutput
as is. An example with an S3 bucket,
Region
is a `StringOutput`:
Copy code
ctx.Export("bucketRegion", bucket.Region)
c
If I need to export map of objects, I get the error:
Copy code
./main.go:65:27: cannot use pairResources (variable of type map[pulumi.String]KeyPairExport) as pulumi.Input value in argument to ctx.Export: map[pulumi.String]KeyPairExport does not implement pulumi.Input (missing method ElementType)
or
Copy code
error: an unhandled error occurred: program failed:
waiting for RPCs: json: error calling MarshalJSON for type pulumi.StringOutput: Outputs can not be marshaled to JSON
m
Well, that’s different from StringOutput 🙂 What’s KeyPairExport? You might use
pulumi.Output()
on your map, or you might need to
range
over the map and export the elements.
c
This is the example what I try to do:
Copy code
type KeyPairExport struct {
	KeyName pulumi.StringOutput `pulumi:"key_name"`
	Id      pulumi.StringOutput `pulumi:"id"`
}

		pairResources := make(map[pulumi.String]KeyPairExport)
		for _, kp := range keyPairs {
			nkp, _ := ec2.NewKeyPair(ctx, kp.Name, &ec2.KeyPairArgs{
				KeyName:   pulumi.String(environment + "-key-pair-" + kp.Name),
				PublicKey: pulumi.String("ssh-rsa key"),
				Tags:      tags,
			})
			pairResources[pulumi.String(kp.Name)] = KeyPairExport{
				KeyName: nkp.KeyName,
				Id:      nkp.KeyPairId,
			}

		}

		ctx.Export("key-pairs", pairResources)
Is it possible to make it workable. That I can use dict of keys in other projects.
m
I believe
ctx.Export("key-pairs", pulumi.ToOutput(pairResources))
should work.
c
Thank you. I'll check.
Nope, the same 😞
Copy code
error: an unhandled error occurred: program failed:
waiting for RPCs: cannot marshal an input of type pulumi.StringOutput with element type string as a value of type pulumi.StringOutput
If comment
.Export
- it works.