Hey everyone :wave: Just joined the pulumi communi...
# typescript
e
Hey everyone 👋 Just joined the pulumi community and I am wondering if anyone else has a solution to this: We are working from migrating from CDK to pulumi. TLDR: Can i reference a different pulumi project/stack with stack-references when using a DIY backend (s3) where there a multiple folders? When using pulumi with a
custom backend (s3)
, i am trying to reference a stack that is owned by the infrastructure team. Here is the backend for the infra team:
url: <s3://pulumi-state-us-west-2/development-us-west-2>
The project is development, while their stack is "us-west-2". They use stacks per region. The application team, maintains their own project/stack and uses the same s3 bucket but in a different folder:
url: <s3://pulumi-state-us-west-2/apps/us-west-2/shared>
Project is "shared" or app name, while the stack is "development-us-west-2" or "<env>-<region>. I am trying to reference the infrastructure stack in code like so:
Copy code
export function getInfrastructureStackReference(
  environment?: string,
  region: string = 'us-west-2',
): string {
  const env = getEnvironment(environment);
  return organization/${env}/${region};
}

export function getInfrastructureStackReferenceObject(
  environment?: string,
  region: string = 'us-west-2',
): pulumi.StackReference {
  const env = getEnvironment(environment);
  const cacheKey = ${env}-${region};

  if (!infrastructureStackCache[cacheKey]) {
    const stackRef = getInfrastructureStackReference(env, region);
    infrastructureStackCache[cacheKey] = new pulumi.StackReference(stackRef);
  }

  return infrastructureStackCache[cacheKey];
}
However, I get this error on
pulumi preview
.
Copy code
Diagnostics:
  pulumi:pulumi:StackReference (organization/development/us-west-2):
    error: Preview failed: unknown stack "organization/development/us-west-2"
Anyone know if I am getting this error because the s3 bucket has a different folder than the infrastructure team? The docs seem to indicate you can here: https://www.pulumi.com/docs/iac/concepts/state-and-backends/
Copy code
The bucket-name value can include multiple folders, such as my-bucket/app/project1. This is useful when storing multiple projects' state in the same bucket.
e
TLDR: Can i reference a different pulumi project/stack with stack-references when using a DIY backend (s3) where there a multiple folders?
Not currently, I thought there was an issue for this but currently not seeing it in the search list.
The bucket-name value can include multiple folders, such as my-bucket/app/project1. This is useful when storing multiple projects' state in the same bucket.
We should probably remove that from the docs. The CLI has had support for managing project folders natively for the last couple of years, there's no need for a path per-project for the backend url.
🙏 1
e
Ya. I searched closed issues and also came up with nothing. It may be helpful adding to the docs that its recommended to keep state in the same directory, otherwise stackreferences will fail. Thank you for the update!