sparse-intern-71089
08/01/2023, 2:42 PMfierce-ability-58936
08/02/2023, 12:01 AMmap is not an pulumi.Input
Also since you've got the keys of the map as strings why don't just use string?
Then to iterate over it after using pulumi.Map for the type and string for the key I get
util.go:110:28: cannot use KeyPairExport{…} (value of type KeyPairExport) as pulumi.Input value in assignment: KeyPairExport does not implement pulumi.Input (missing method ElementType)
As KeyPairExport again is not an Input , so maybe marshalling to json is acceptable? Not sure about a better way
type KeyPairExport struct {
KeyName pulumi.StringOutput `pulumi:"key_name"`
Id pulumi.StringOutput `pulumi:"id"`
}
pairResources := pulumi.Map{}
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"),
})
pairResources[kp.Name] = pulumi.JSONMarshal(KeyPairExport{
KeyName: nkp.KeyName,
Id: nkp.KeyPairId,
})
}
ctx.Export("key-pairs", pairResources)
at least this compiles.clever-kite-79772
08/02/2023, 8:11 AMclever-kite-79772
08/02/2023, 9:49 AMerror: an unhandled error occurred: program failed:
waiting for RPCs: json: error calling MarshalJSON for type pulumi.StringOutput: Outputs can not be marshaled to JSONclever-kite-79772
08/02/2023, 10:00 AMctx.Export("key-pairs", pairResources)
If I comment it - everything works.fierce-ability-58936
08/02/2023, 9:19 PMThe Pulumi Go SDK does not currently support serializing or deserializing maps with unknown values.How about
pairResources[kp.Name] = pulumi.Sprintf("%s:%s", nkp.KeyName, nkp.KeyPairId)
?clever-kite-79772
08/02/2023, 10:43 PMclever-kite-79772
08/02/2023, 10:44 PMpairResources[kp.Name] = pulumi.All(nkp.KeyName, nkp.KeyPairId).ApplyT(func(v []any) KeyPairExport {
return KeyPairExport{
KeyName: v[0].(string),
Id: v[1].(string),
}
})
But not sure if it's a good solution..fierce-ability-58936
08/02/2023, 10:44 PMclever-kite-79772
08/02/2023, 10:46 PMclever-kite-79772
08/05/2023, 7:39 PMpairResources := pulumi.StringMapMap{}
for _, kp := range keyPairs {
nkp, _ := ec2.NewKeyPair(ctx, kp.Name, &ec2.KeyPairArgs{
KeyName: pulumi.String(environment + "-key-pair-" + kp.Name),
PublicKey: pulumi.String(kp.PublicKey),
Tags: tags,
})
pairResources[kp.Name] = pulumi.StringMap{
"key_name": nkp.KeyName,
"key_pair_id": nkp.KeyPairId,
}
}
ctx.Export("key-pairs", pairResources)
The main idea - the correct datatype is StringMapMap