Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipelines: Stage can't deploy an existing stack bound to another scope #26074

Closed
justinwiley opened this issue Jun 21, 2023 · 2 comments
Closed
Labels
@aws-cdk/pipelines CDK Pipelines library bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@justinwiley
Copy link

justinwiley commented Jun 21, 2023

Describe the bug

I have an existing application, with a stack called 'ExampleStack' that I have been deploying via cdk deploy ExampleStack. It's bound to the scope of the app:

const app = new App();
const exampleStack = new ExampleStack(app, 'ExampleStack', props); 

I want to set up a new code pipeline, using CDK Pipeline to deploy ExampleStack, per AWS recommended best practices.

However, when I move the example stack into a stage:

class ExampleStage extends Stage {
  constructor(scope: Construct, id: string, props: StageProps) {
    super(scope, id, props);

    new ExampleStack(this, 'ExampleStack', props);  // example stack duplicate created
  }
}

...the logical id of the stack changes, since it's now in the scope of the Stage, not the app, meaning an entirely new stack with duplicated resources is created which is not the desired behavior.

If I use the app in the stage:

class ExampleStage extends Stage {
  constructor(scope: Construct, id: string, props: StageProps) {
    super(scope, id, props);

    new ExampleStack(app, 'ExampleStack', props); // synth fails
  }
}

...it fails during synthesis time with:

The given Stage construct ('Example') should contain at least one Stack.

Expected Behavior

A convenient and documented way of deploying existing stacks in stages without having to recreate the or import their resources into a new stack.

Current Behavior

Stacks are recreated when moved into stages, or blueprint errors are thrown.

Reproduction Steps

See above.

Possible Solution

Update the stage synth method to allow a scope to be passed in, and reference it during synthesis:

  interface StageSynthesisOptions = {
    ...
    synthesisScope: App|Stage
  }

  public synth(options: StageSynthesisOptions = { }): cxapi.CloudAssembly {
    if (!this.assembly || options.force) {
      this.assembly = synthesize(options.synthesisScope || this, {
        skipValidation: options.skipValidation,
        validateOnSynthesis: options.validateOnSynthesis,
      });
    }

    return this.assembly;
  }

...and updating what invokes snyth to pass on the new argument as well.

Additional Information/Context

No response

CDK CLI Version

2.83.0 (build 0fd7f2b)

Framework Version

No response

Node.js Version

18

OS

mac

Language

Typescript

Language Version

No response

Other information

No response

@justinwiley justinwiley added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 21, 2023
@github-actions github-actions bot added the @aws-cdk/pipelines CDK Pipelines library label Jun 21, 2023
@peterwoodworth
Copy link
Contributor

Did you try supplying the stackName directly?

@peterwoodworth peterwoodworth added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Jun 21, 2023
@github-actions
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/pipelines CDK Pipelines library bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants