https://pulumi.com logo
Title
g

gorgeous-window-12350

05/18/2021, 5:37 PM
I have a staging and production stack managing infrastructure in the same AWS account, but I only want a single elastic container registry resource between both stacks. I can’t simply remove the ECR resource from the staging stack because a bunch of other staging resources reference it. I also tried forcing staging to use the same ECR repo name as production, but that complained that the resource already existed when I ran
pulumi up
. Any guidance here?
Mm actually I realized I can probably just import the prod ecr repo into my staging stack. But is it appropriate for a resource to be managed by two different stacks?
b

billowy-army-68599

05/18/2021, 5:44 PM
you can't manage a resource by two different stacks, no. What most people do here is set a config boolean:
pulumi config set enableECR
Then use an if statement if it's enabled
g

gorgeous-window-12350

05/18/2021, 5:55 PM
@billowy-army-68599 Thanks for the reply! I was able to import the same resource into both stacks, so I think that I can manage the same resource in both stacks, but perhaps I shouldn’t. I know that I can toggle the ECR on in one environment and off in another. The issue I’m running into is that I need to reference the ECR resource in both stacks, since my AWS tasks need to reference images in that one ECR instance.
An alternative path would be to output the ECR id from the production stack and import it into my staging stack. Is that possible, and would that be a better approach?
b

billowy-army-68599

05/18/2021, 5:59 PM
you definitely shouldn't manage the resource in both stacks
you have two options really: - move the ECR definition into its own project and use a stack reference - use the if statement method I defined above, and if it's set to false use a
.get()
method
so:
if true {
 // create the resource
} else {
  ecr.get_repository
}
g

gorgeous-window-12350

05/18/2021, 8:26 PM
Thank you, that solved my issue. New to Pulumi and hadn’t made use of the get functions yet