Machine: Mac OSX Mojave
pulumi version v0.17.1
Using the python pulumi lib I am unable to read the config values from the Pulumi.yaml files.
Here are my files:
Pulumi.yaml
name: compute
runtime: python
description: Deploys App to Google Cloud Platform
Pulumi.dev.yaml
config:
compute:name: dev
gcp:credentials: ./cicd_demo_gcp_creds.json
gcp:project: cicd-workshops
gcp:region: us-east1
gcp:zone: us-east1-d
python app test.py
import pulumi
conf = pulumi.Config('compute')
print(conf.require('name'))
stack trace
$ python test.py
Traceback (most recent call last):
File "test.py", line 3, in <module>
print(conf.require('name'))
File "/Users/angel/.pyenv/versions/3.7.2/lib/python3.7/site-packages/pulumi/config.py", line 126, in require
raise ConfigMissingError(self.full_key(key))
pulumi.config.ConfigMissingError: Missing required configuration variable 'compute:name'
please set a value using the command `pulumi config set compute:name <value>`
When I run the pulumi config command on the cli it shows the values from the Pulumi.dev.yaml
KEY VALUE
name dev
gcp:credentials ./cicd_demo_gcp_creds.json
gcp:project cicd-workshops
gcp:region us-east1
gcp:zone us-east1-d
I'm running this test.py script from the dir that hosts the yaml files. I've tried different variations of the name spaces but none are working. They're all breaking out with the same error.
Instead of running python test.py, try the following:
mv test.py __main__.py
rm requirements.txt
echo "pulumi>=0.17.2" >> requirements.txt
virtualenv -p python3 venv
source venv/bin/activate
pip3 install -r requirements.txt
pulumi up
As an aside:
I thought we detected an issued a nicer error if the runtime isn't hooked up to a CLI/engine?
I thought we detected an issued a nicer error if the runtime isn't hooked up to a CLI/engine?
Interesting, I can't recall if we ever did this or if it has regressed. I tried running a similar JavaScript program directly with node and it fails in a similar way (providing no helpful guidance that pulumi should be used to run the program).
$ node index.js
/Users/justin/scratch/nodetest/node_modules/@pulumi/pulumi/config.js:141
throw new ConfigMissingError(this.fullKey(key));
^
Error: Missing required configuration variable 'compute:name'
please set a value using the command `pulumi config set compute:name <value>`
at Config.require (/Users/justin/scratch/nodetest/node_modules/@pulumi/pulumi/config.js:141:19)
at Object.<anonymous> (/Users/justin/scratch/nodetest/index.js:6:20)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:775:12)
at startup (internal/bootstrap/node.js:300:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:826:3)
@CyrusNajmabadi, @swgillespie, do you recall if we ever provided a nicer error when a program is incorrectly run directly with node or python? Either way, we definitely should.
Update. @justinvp @joeduffy Thank you all for the quick response. I was able to make this work under the pulumi runtime as you suggested which is great. I see you're already discussing a more informative error message that notifies the user to run these apps under the pulumi runtime. This sort of message would be extremely helpful for future devs. Thank you for all the help.
Opened https://github.com/pulumi/pulumi/issues/2580 to track the good error message. I'll close this one out since the core problem described here is addressed.