This message was deleted.
# general
s
This message was deleted.
l
Do you mean supporting config items with different strings before the ":"? like
Copy code
db:size: large
  redis:enabled: true
?
👍 1
c
saw that. But couldn't figure out how to use that.
To give a little more context, I want to have a specific section for vm config and use that for vm creation.
Copy code
vm:config:
  - count: 1
    data_disk_size: 50
    name: cassandra
    resource_group: pu_demo
    type: Standard_A8_v2
    user_name: deployer
but how to get that values in program? no idea. Is there any example kind available? that'll be of huge help
l
Awkward that your config item is called config, but let's give it a go 🙂 Assuming typescript, and that you have an interface called VmConfig that contains count, data_disk_size, etc. then you need to use something like
Copy code
const vmConfigBucket = new pulumi.Config('vm');
const vmConfig = vmConfigBucket.requireObject<VmConfig>('config');
You might find it easier to start with a pile of separate config items. If not, try to come up with a name that isn't "config", as it may end up confusing you. Maybe "InstanceSpec"?
c
InstanceSpec, yeah ofcource, and I'm using golang
l
Ok then maybe something like this?
Copy code
var spec InstanceSpec
        cfg := config.New(ctx, "vm")
        cfg.RequireObject("instanceSpec", &spec)
That will look up key vm:instanceSpec and parse the yaml into a variable of type InstanceSpec.
And if that works, let me know, because it's the first golang I've ever written 🙂
🤩 1
c
then lemme tell you that you're meant for golang. thats what I have in my code
l
🙂 Nice of you to say. I'm still teaching myself typescript... and Kotlin, groovy, python and C#. For some reason, none of the lanugages I already know overlap with my current work ¯\_(ツ)_/¯
🙌 1
c
that's a handful of tools you have in your arsenal.
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
l
Way above my paygrade, sorry 😞
c
haha.. thanks man for looking in to my issue. If you can point to someone, appreciate it.