I'm learning config concepts. Trying to ensure cer...
# getting-started
s
I'm learning config concepts. Trying to ensure certain configs are required. I've got a stack example with config
Pulumi.example.yaml
in program
kubernetes
Copy code
config:
  gcp:project: "new"
  kubernetes:pod_range: "test"
In Pulumi.yaml I define required by using:
Copy code
config:
  pod_range:
    type: String
pulumi up says
Copy code
error: could not get cloud url: could not load current project: could not validate '/Users/me/workspace/pulumi/kubernetes/Pulumi.yaml': 8 errors occurred:
	* #/config/pod_range: oneOf failed
	* #/config/pod_range: expected string, but got object
	* #/config/pod_range: expected integer, but got object
	* #/config/pod_range: expected boolean, but got object
	* #/config/pod_range: expected array, but got object
	* #/config/pod_range: doesn't validate with '/$defs/configTypeDeclaration'
	* #/config/pod_range/type: doesn't validate with '/$defs/simpleConfigType'
	* #/config/pod_range/type: value must be one of "string", "integer", "boolean", "array"
Removing the
config
key from Pulumi.yaml will make a preview run. Any ideas?
r
You can make a config key required by calling it with
config.require()
in the code rather than by defining the schema for it in the pulumi.yaml: https://www.pulumi.com/docs/intro/concepts/config/#:~:text=let%20name%20%3D%20config.require(%22name%22)%3B
There is no way to define the expected schema of the config in the pulumi.yaml
s
Ah ok. Thanks! This was misleading to me, as the docs suggest the pattern you saw https://www.pulumi.com/docs/intro/concepts/config/#code with the example:
Copy code
configuration:
  name:
    type: String
  lucky:
    default: 42
outputs:
  stdout: Hello, ${name} -- I see your lucky number is ${lucky}!
Not big deal. 😄 Was just trying to establish best practices.
r
Ah! That is indeed the case if you are writing your pulumi program in YAML rather than any of the programming languages.
s
Ah okay, the string validation does seem to work for outputs. Just not within resources.
Might not be intended for resources though.
r
Ah okay, the string validation does seem to work for outputs. Just not within resources.
I'm not sure I understand - is this still in relation to configuration?
s
Yeah. Pulumi.yaml like this:
Copy code
name: kubernetes
runtime: yaml
description: A minimal Google Cloud Pulumi YAML program
variables:
    project: ${pulumi.project}
configuration:
  cluster_name:
    type: String
resources:
  gke-cluster:
    type: gcp:container:Cluster
    properties:
      location: europe-west2
      name: ${cluster_name}
Produces this preview:
Copy code
* #/config/cluster_name: oneOf failed
	* #/config/cluster_name: expected string, but got object
	* #/config/cluster_name: expected integer, but got object
	* #/config/cluster_name: expected boolean, but got object
	* #/config/cluster_name: expected array, but got object
	* #/config/cluster_name: doesn't validate with '/$defs/configTypeDeclaration'
	* #/config/cluster_name/type: doesn't validate with '/$defs/simpleConfigType'
	* #/config/cluster_name/type: value must be one of "string", "integer", "boolean", "array"
with this config
Copy code
config:
  gcp:project: "new"
  kubernetes:cluster_name: "test"
But this might go back to your answer that YAML won't support this.
The error catching does work better in Yaml with config variable referenced in outputs
Copy code
error: missing required configuration variable 'cluster_name'; run `pulumi config` to set
r
* #/config/cluster_name/type: value must be one of "string", "integer", "boolean", "array"
This last line implies that the declaration should be lower-case:
Copy code
configuration:
  cluster_name:
    type: string
But yeah, the docs have it as capitalized. Indeed confusing.
What you're doing should work, config is made to be passed into resources. There is something odd going on here.