Hi all, I have a `Pulumi.dev.yaml` of the followin...
# getting-started
m
Hi all, I have a
Pulumi.dev.yaml
of the following form:
Copy code
config:
  gcp-go-gke:data:
    cluster:
      initialNodeCount: 2
      machineType: n1-standard-2
      name: my-cluster
    registry:
      appLabel: my-proj
      deployment:
        containers:
        - image: us-central1-docker.pkg.dev/my-gcloud-proj/my-gcloud-repo/my-image:0.1.0
          name: my-image
        name: my-deployment
        replicas: 1
      namespace:
        metadata:
          name: namespace-meta
        name: my-namespace
      service:
        name: my-service
        port: 80
        serviceType: LoadBalancer
        targetPort: 8080
  gcp:project: my-proj
  gcp:zone: us-west1-a
In
main.go
, I have the following code:
Copy code
type Data struct {
	cluster  Cluster
	registry Registry
}

type Cluster struct {
	initialNodeCount int
	machineType      string
	name             string
}
type Registry struct {
	appLabel   string
	deployment Deployment
	namespace  Namespace
	service    Service
}

type Deployment struct {
	containers []Container
	name       string
	replicas   int
}

type Namespace struct {
	metadata Metadata
	name     string
}

type Service struct {
	name        string
	port        int
	targetPort  int
	serviceType string
}

type Container struct {
	image string
	name  string
}

type Metadata struct {
	name string
}

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {

		var d Data
		cfg := config.New(ctx, "")
		cfg.RequireObject("data", &d)

		engineVersions, err := container.GetEngineVersions(ctx, &container.GetEngineVersionsArgs{})
		if err != nil {
			return err
		}
		masterVersion := engineVersions.LatestMasterVersion

		cluster, err := container.NewCluster(ctx, d.cluster.name, &container.ClusterArgs{
            ...
        }
The
cfg.RequireObject
call does not panic, but
d.cluster.name
resolves to
""
. I’m using this doc as a reference to read structured configuration. Any tips for troubleshooting why the config is not read properly? I used verbose logging (
pulumi up --logtostderr --logflow -v=9 2> out.txt
) but didn’t find anything useful in the logs. Thanks in advance for your help/guidance! 🙂
Happy to move this post over to #golang instead if it’s a better candidate for that channel
e
Sanity check you can add
fmt.Println("ENV:", os.Getenv("PULUMI_CONFIG"))
to check the program config looks right. Should be a JSON object with all your values in it.
m
Thanks for the tip — the config does seem to be correct
e
#golang might see the issue but the code looks alright to me. If you don't have any luck feel free to open an issue at our github and we can take a closer look.
👍 1
m
Here’s a much simpler case of the error to reproduce. Stack:
Copy code
config:
  gcp-go-gke:data:
    cluster:
      name: my-cluster
  gcp:project: my-proj
  gcp:zone: us-west1-a
`main.go`:
Copy code
type Data struct {
	cluster Cluster
}

type Cluster struct {
	name string
}

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {

		var d Data
		cfg := config.New(ctx, "")
		cfg.RequireObject("data", &d)

		fmt.Println("Cluster name is:", d.cluster.name)

		return nil
	})
}
And
d.cluster.name
here is
""
Does Pulumi support ingesting structured config if the some of the fields themselves are user-defined go structs? Seems that’s the primary difference between the use-case here and the provided example
Think I figured it out. The issue is that my struct fields are private (lower-case), but need to be upper-case so
RequireObject
can properly populate the passed in struct.
e
Ah yes, its just using the standard go json marshalling logic underneath. Surprisingly that constraint isn't pointed out in the docs.