Can I add an ESC environment to a stack using the ...
# esc
a
Can I add an ESC environment to a stack using the Automation API? Thanks.
or is there an alternate method of accessing an ESC environment dynamically from python?
r
Can I add an ESC environment to a stack using the Automation API? Thanks.
Yup. We're working on getting the SDK docs updated with these new additions but in the meanwhile, here's the test code that exercises these functions for an example: https://github.com/pulumi/pulumi/blob/6f41d715d90dfd87b9d274b4a1bc95ca1a6b6b14/sdk/python/lib/test/automation/test_local_workspace.py#L211
a
thank you @red-match-15116. I'm using the local program python example and getting the following error: AttributeError: 'Stack' object has no attribute 'add_environments' i'm on Pulumi CLI v3.104.2
r
what's the version of your pulumi sdk in your python env?
a
ah I see... pulumi 3.80.0 pulumi-aiven 6.6.1 pulumi-gcp 6.67.0 pulumi-random 4.14.0 pulumiverse-time 0.0.16
r
yup that's it, you'll need pulumi >= 3.96.0 I think
a
i'll update to 3.104.2
thanks again!
r
np, happy to help!
a
Hi, I'm having an issue accessing the env vars from an ESC environment. The call to create the GCP Project and services fails as the org id and billing code are missing. Error message "reason": "UREQ_PROJECT_BILLING_NOT_FOUND" Code snippet from the automation main.py:
Copy code
stack = auto.create_or_select_stack(stack_name=client_code, work_dir=work_dir)
stack.add_environments("gcp-base-env")
config = stack.get_all_config() #is this needed?
stack.refresh(on_output=print)
up_res = stack.up(on_output=print, debug=True)
Code snippet from _ _ main __ .py
Copy code
config = Config()

# GCP 
org_billing_account = config.get("gcp-base-env:GCP_ORG_BILLING_ACCOUNT")
org_id = config.get("gcp-base-env:GCP_ORG_ID")
attached a screenshot of running pulumi env open
r
From the automation main.py you shouldn't need the
config = stack.get_all_config()
- you would only need that if you wanted to access the configuration values within the automation script (rather than the pulumi program) From your
___main__.py_
, can you try the following:
Copy code
config = Config("gcp-base-env")
org_billing_account = config.get("GCP_ORG_BILLING_ACCOUNT")
org_id = config.get("GCP_ORG_ID")
a
@red-match-15116, thank you so much! The missing arg to Config() was the key 🙂
I want to let you know I see the attached error dialog on the Editor page. It displays every time the page loads but I am not experiencing any issues editing or saving environments.
Copy code
main.56a454faf2ef5516.js:1 ERROR TypeError: Cannot read properties of undefined (reading 'indexOf')
    at main.56a454faf2ef5516.js:1:3627252
    at Array.filter (<anonymous>)
    at t.getValidEnvironments (main.56a454faf2ef5516.js:1:3627224)
    at Object.next (main.56a454faf2ef5516.js:1:3627121)
    at je.next (main.56a454faf2ef5516.js:1:10124)
    at He._next (main.56a454faf2ef5516.js:1:9804)
    at He.next (main.56a454faf2ef5516.js:1:9497)
    at main.56a454faf2ef5516.js:1:15367
    at sn._next (main.56a454faf2ef5516.js:1:14888)
    at sn.next (main.56a454faf2ef5516.js:1:9497)
r
Yeah sorry about that, it's a known issue and we're working on a fix!
a
awesome!
and no worries!