https://pulumi.com logo
#general
Title
# general
a

agreeable-whale-35898

02/08/2024, 3:12 PM
Hi, I'm trying to understand how to work efficiently with Pulumi in multiple accounts. Currently, I have two different projects that must be non-related, so when I'm in directory of the first project,
one/
, I just need to type
pulumi up
and that's it, and when in the other project's directory,
two/
- the same: just type
pulumi up
and that's it. But it's not convenient, because I must always run
pulumi logout
, then
pulumi login
to switch from one project to the other (as they are managed in different Pulumi accounts). In Terraform it's very simple: the
backend
is bound to a specific AWS account and managed there, so everything is local: I just run
terraform apply --var-file=dev.tfvars
and
provider aws { profile = var.profile ...
binds it to the right profile / account. Do you have any idea how to make it simple as that in Pulumi too? Is it possible to keep all "login" / "profile" info located in the project directory and not having to switch accounts again and again?
s

salmon-account-74572

02/08/2024, 3:26 PM
There's a
backend.url
value you can add to your project configuration that might help. More details here: https://www.pulumi.com/docs/concepts/state/
l

little-cartoon-10569

02/08/2024, 6:45 PM
Is the backend what's presenting the problem here, or are you trying to get the aws.Provider instance in each project to be completely unrelated? If it's the latter, then I recommend disabling default providers and creating the provider explicitly in each project. It means you'll need to pass it into every resource constructor, but it allows you to guarantee that the projects never intrude into each other's accounts.
a

agreeable-whale-35898

02/08/2024, 8:11 PM
@little-cartoon-10569 I'm not 100% sure that I understand your question, but I get it right, that I'm referring to the Pulumi account, not the (AWS) provider. The provider is solvable, as I can write in the project file (the
Pulumi.yaml
file) the name of the AWS provider e.g.:
Copy code
config:
  aws:profile: specific_profile_name
@salmon-account-74572 thanks! exactly what I was looking for! 😊 I ended up using this for local dev stages:
Copy code
backend:
  url: file://.
and I believe that
url: s3://...
will fit when we advance
s

salmon-account-74572

02/08/2024, 8:28 PM
Perfect, glad I was able to help!
l

little-cartoon-10569

02/08/2024, 8:34 PM
If configuring the aws:profile setting is fixing the problem, then the backend fix is solving the problem as a side effect. It's a good fix to prevent repeated calls to
pulumi login
. Which AWS account (and indeed, region) you are using is defined by instances of aws.Provider: account is Provider. You should probably read up on that class and what it can do. It will help you avoid similar problems in the future. https://www.pulumi.com/registry/packages/aws/api-docs/provider/