https://pulumi.com logo
Title
s

square-tiger-5809

01/05/2023, 8:54 PM
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
config:
  gcp:project: "new"
  kubernetes:pod_range: "test"
In Pulumi.yaml I define required by using:
config:
  pod_range:
    type: String
pulumi up says
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

red-match-15116

01/05/2023, 8:58 PM
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

square-tiger-5809

01/05/2023, 9:31 PM
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:
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

red-match-15116

01/05/2023, 10:09 PM
Ah! That is indeed the case if you are writing your pulumi program in YAML rather than any of the programming languages.
s

square-tiger-5809

01/05/2023, 10:12 PM
Ah okay, the string validation does seem to work for outputs. Just not within resources.
Might not be intended for resources though.
r

red-match-15116

01/05/2023, 10:14 PM
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

square-tiger-5809

01/05/2023, 10:18 PM
Yeah. Pulumi.yaml like this:
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:
* #/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
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
error: missing required configuration variable 'cluster_name'; run `pulumi config` to set
r

red-match-15116

01/05/2023, 10:21 PM
* #/config/cluster_name/type: value must be one of "string", "integer", "boolean", "array"
This last line implies that the declaration should be lower-case:
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.