Back with n00b questions :slightly_smiling_face: ...
# general
l
Back with n00b questions 🙂 • Context: ◦ I'm using the Automation API and Python. ◦ Working with
aws.cloudfront.Distribution
. ◦ Seems the only way to bounce between regions is to set the
aws:region
configuration. ▪︎ Please correct me if I'm wrong about setting that value. • Questions: ◦ Should the
aws:region
config be changed between calls to
aws.cloudfront.Distribution
, can I expect the subsequent distribution to be deployed in the most resent setting? ◦ If using the stack config to exchange parameters between the local program and the Pulumi program, what is the most effective method of getting a
pulumi.automation.Stack
instance in the Pulumi program? ▪︎ I've considered
__file__
,
pulumi.get_stack()
, and
pulumi.automation.select_stack()
but it seems like I'm missing a more obvious method. ▪︎ Edits: • I'm looking to set new values to the stack's config. • Can confirm that the
pulumi.automation.select_stack()
works.
b
I believe you can set the region on the provider? Than you could just instantiate multiple providers and pass them to your distributions.
❤️ 1
I believe that will mean you don't have to do this config handling you're looking at, but to answer your second question - automation api is not meant to be used inside your pulumi program. I don't think that will work.
l
Ah, I totally didn't think about doing the provider thing. Sharp eye. I'll try that here in a bit. Stack shenanigans is working like I want it to within the Pulumi program, but you're probably right. Feels like it's the wrong thing to do. Probably should just interface with external storage from the Pulumi program. I'll probably refactor it and do it the right way again tomorrow. At least I'm learning about this slick system. Thanks for the tips!
b
I would expect that when a deployment starts it grabs the config and doesn't read it again after, so I'm surprised if that worked. But yes I would recommend against automation api inside your program. Good luck!
👍 1
l
Yeah, I just instantiated a
pulumi.automation.Stack
instance within the Pulumi program itself. That seems to interact with the stack's YAML file when running
Stack.set_config
and
Stack.get_config
.
Copy code
import pulumi
from pulumi import automation as auto
from pathlib import Path

# bad ideas
stack = auto.select_stack(
    stack_name=pulumi.get_stack(),
    work_dir=str(Path(__file__).parent.absolute()))

# set a config value
stack.set_config('stuff', auto.ConfigValue('things'))

# log the newly set value
<http://pulumi.info|pulumi.info>(stack.get_config('stuff'))
It's probably working because I'm more-or-less using it as a method of sending output back to the automation program (less the
aws:region
config). Definitely heeding your advice though.
Part of me was hoping it worked more like "RPC calls" when stuff was being put together. All speculation, though. I need to read the docs 😅
b
Yea that is just reading and writing straight to the json file. So I guess that working isn't surprising. The real question is if the ongoing deployment actually picks up your change, I would doubt that and be thoroughly surprised if it did
Automation API as it currently exists is really just a literal layer over the CLI you're used to so in its current form it is manipulating the same project directory you would manually. The RPC portion of automation api doesn't come into play until you start a deployment using it, because at that point it needs to communicate with the Pulumi CLI that is running under the hood as a separate process
l
Ah, that makes sense.