Hi everyone, I am having hard time to understand t...
# getting-started
Hi everyone, I am having hard time to understand the concept of stack. What I want to know is the way to setup different infrastructure for each stacks, i.e. dev, prod, test. As far as I know, if I want to define my infra in python, I have to write down everything in
. But this file doesn’t change when I switch between stacks(of course). What should I do? Should I use git? 😞
I also think it is bit confusing, from my understanding
is environment (dev, staging, prod). so the file main is not change (you are correct), you define it in the YAML as config or you can put if statement to check what stack you are on if you need to code something different
Thank you very much. I did like this:
Copy code
import pulumi

stack_name = pulumi.get_stack()

if stack_name == "dev":
    import main_dev
elif stack_name == "prod":
    import main_prod
elif stack_name == "test":
    import main_test
That’ll work. It would be good to know a bit more about what those files contain, too. If they contain mostly configuration settings, another best practice is to use Pulumi’s config system, which lets you pull those values into a file that it reads automatically at runtime. https://www.pulumi.com/docs/intro/concepts/config/
This lets you use the same code to drive all environments, using configuration settings to adjust what’s unique to each environment.
Wow. Thanks. For now each files only needs stack name of each, but later definitely I will use configuration.
👍 1