Hi guys, I'm playing around in pulumi. Was trying ...
# golang
c
Hi guys, I'm playing around in pulumi. Was trying to have custom keyspace so that I can have a template for creating vms But getting following error Pulumi.dev.yaml
Copy code
config:
  vm:instance_spec:
  - count: 1
    data_disk_size: 50
    name: cassandra
    resource_group: pu_demo
    type: Standard_A8_v2
    user_name: deployer
main.go
Copy code
// vm config struct
type Data struct {
	Data []struct {
		Name              string `json:"name"`
		Type              string `json:"type"`
		Count             int    `json:"count"`
		DataDiskSize      int    `json:"data_disk_size"`
		UserName          string `json:"user_name"`
		ResourceGroupName string `json:"resource_group"`
	} `json:"instance_spec"`
}
func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		vmConfig := config.New(ctx, "vm")
		var d Data
		if err := vmConfig.GetObject("instance_spec", &d); err != nil {
			return err
		})
		fmt.Printf("%v\n", d)
return nil
)}
}
and I'm getting this error
Copy code
Diagnostics:
  pulumi:pulumi:Stack (demo-dev):
    error: program failed: 1 error occurred:
        * json: cannot unmarshal array into Go value of type main.Data
    exit status 1
    error: an unhandled error occurred: program exited with non-zero exit code: 1
@here any ideas on this. Because else change the vm type is pretty bad. If there is any alternate approach, please lemme know.
this vanila go program is working for me
I think internally some key is changing in pulumi. I'm not able to debug also
i
i think the problem is you’re fetching
instance_spec
which is an array, into a struct which embeds an array - ie. all you actually need for
Data
is that inner one; you don’t need the wrapper
Copy code
type Data struct {
		Name              string `json:"name"`
		Type              string `json:"type"`
		Count             int    `json:"count"`
		DataDiskSize      int    `json:"data_disk_size"`
		UserName          string `json:"user_name"`
		ResourceGroupName string `json:"resource_group"`
}
then just declare
var d []Data
and pass that to your call to
GetObject
🙌 1
or, if you wanted to keep your existing struct you could just pass
d.Data
to `GetObject`; should be the same result
c
Thanks. That makes sense. quite a bit of subtleness.
is there any place I can raise a PR for custom keyspace code doc ? current one is not quite beginner friendly