chilly-rainbow-79265
08/20/2020, 7:14 AMconfig:
vm:instance_spec:
- count: 1
data_disk_size: 50
name: cassandra
resource_group: pu_demo
type: Standard_A8_v2
user_name: deployer
main.go
// 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
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
important-appointment-55126
08/20/2020, 1:57 PMinstance_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 wrappertype 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"`
}
var d []Data
and pass that to your call to GetObject
d.Data
to `GetObject`; should be the same resultchilly-rainbow-79265
08/20/2020, 2:24 PM