https://pulumi.com logo
#typescript
Title
# typescript
n

numerous-psychiatrist-20856

08/27/2020, 6:02 PM
Hello! I'm trying to setup a project where in one repo I define all the infrastructure, and in other I have the application building its docker image, but I'm running into issues referencing stacks. Here is the simplified infra code:
Copy code
import * as awsx from "@pulumi/awsx";

const repository = new awsx.ecr.Repository("repository");

export const ecrRepository = repository;
and application code:
Copy code
import * as pulumi from "@pulumi/pulumi";
import * as awsx from "@pulumi/awsx";

const env = pulumi.getStack();
const infra = new pulumi.StackReference(`cakper/infrastructure/${env}`);

infra.requireOutput("ecrRepository").apply(repository => {
    const repo = new awsx.ecr.Repository("repository", repository);
});
problem that I'm running into, is that I can't properly reference the repository and both stacks end up creating it. Can someone please help me wrap my head around it? 🙂
f

faint-table-42725

08/27/2020, 6:09 PM
In the second stack, you need to actually get back the resource itself (instead of relying on the stack output, which isn’t rehydrated as the resource). So you’ll want to do a
get
on the resource and use it from there. Something along these lines: In the exporting stack:
export const repositoryId = repository.id
In the importing stack,
const repo = new awsx.ecr.Repository("repo", { repository: aws.ecr.Repository.get("ecrRepo", infra.requireOutput("repositoryId")) })
n

numerous-psychiatrist-20856

08/27/2020, 6:11 PM
ah, that makes more sense now 🙂
let me try it out
h

hundreds-musician-51496

08/27/2020, 7:24 PM
Stack outputs that serialize to JSON (and back) work best, as well.
n

numerous-psychiatrist-20856

08/27/2020, 7:42 PM
yay, that worked, thanks for help Lee 🙂