Hello! I'm trying to setup a project where in one ...
# typescript
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? 🙂
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
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")) })
ah, that makes more sense now 🙂
let me try it out
Stack outputs that serialize to JSON (and back) work best, as well.
yay, that worked, thanks for help Lee 🙂