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): Cannot deploy a cross-region pipeline from a Stage #17643

Closed
gshpychka opened this issue Nov 23, 2021 · 3 comments · Fixed by #17730
Closed

(pipelines): Cannot deploy a cross-region pipeline from a Stage #17643

gshpychka opened this issue Nov 23, 2021 · 3 comments · Fixed by #17730
Assignees
Labels
@aws-cdk/pipelines CDK Pipelines library bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@gshpychka
Copy link
Contributor

gshpychka commented Nov 23, 2021

What is the problem?

The cross-region support stack created by CDK pipeline is placed in the wrong scope - outside of the Stage, which leads to dependency crossing a stage boundary error on synth.

This makes it impossible to deploy a cross-region CDK pipeline from a Stage.

Reproduction Steps

from aws_cdk import core as cdk, pipelines, aws_ec2 as ec2
import os


class MyStage(cdk.Stage):
    def __init__(
        self,
        scope: cdk.Construct,
        id: str,
        **kwargs,
    ) -> None:
        super().__init__(scope, id, **kwargs)
        Pipeline(self, "Pipeline")


class Pipeline(cdk.Stack):
    def __init__(
        self,
        scope: cdk.Construct,
        id: str,
        **kwargs,
    ) -> None:
        super().__init__(scope, id, **kwargs)

        source = pipelines.CodePipelineSource.connection(
            repo_string="owner/repo",
            branch="",
            connection_arn="my_arn",
        )

        synth_step = pipelines.ShellStep(
            "synth",
            commands=[],
            input=source,
        )

        pipeline = pipelines.CodePipeline(
            self,
            "pipeline",
            synth=synth_step,
        )

        pipeline.add_stage(
            MultiRegion(self, "main", env=cdk.Environment(region="ap-northeast-1"))
        )


class MultiRegion(cdk.Stage):
    def __init__(
        self,
        scope: cdk.Construct,
        id: str,
        **kwargs,
    ) -> None:
        super().__init__(scope, id, **kwargs)
        AppStack(self, "app")


class AppStack(cdk.Stack):
    def __init__(
        self,
        scope: cdk.Construct,
        id: str,
        **kwargs,
    ) -> None:
        super().__init__(scope, id, **kwargs)
        ec2.Vpc(self, "vpc")


if __name__ == "__main__":
    env = cdk.Environment(account=os.environ["CDK_DEFAULT_ACCOUNT"], region="eu-west-1")
    app = cdk.App()
    MyStage(app, "Stage", env=env)
    app.synth()

cdk synth

What did you expect to happen?

Successful synth

What actually happened?

jsii.errors.JSIIError: You cannot add a dependency from 'Stage/Pipeline' (in Stage 'Stage') to 'cross-region-stack-<account_id>:ap-northeast-1' (in the App): dependency cannot cross stage boundaries

CDK CLI Version

1.133.0

Framework Version

No response

Node.js Version

17.1.0

OS

Linux

Language

Typescript, Python, .NET, Java, Go

Language Version

No response

Other information

No response

@gshpychka gshpychka added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 23, 2021
@gshpychka gshpychka changed the title (pipelines): Cannot deploy a cross-region pipeline from a Stages (pipelines): Cannot deploy a cross-region pipeline from a Stage Nov 23, 2021
@github-actions github-actions bot added the @aws-cdk/pipelines CDK Pipelines library label Nov 23, 2021
@rix0rrr rix0rrr added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Nov 23, 2021
@rix0rrr rix0rrr assigned rix0rrr and unassigned rix0rrr Nov 23, 2021
@gshpychka
Copy link
Contributor Author

From my understanding after discussing with @rix0rrr , it seems that the issue is in here:

supportStack = new CrossRegionSupportStack(app, supportStackId, {

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 23, 2021

Yep. app needs to be this.

rix0rrr added a commit that referenced this issue Nov 26, 2021
Because a cross-environment pipeline cannot be created in `Stage`,
it cannot be deployed using CDK Pipelines.

The error is:

```
Error: You cannot add a dependency from 'AAA' (in Stage 'BBB') to 'CCC' (in the App): dependency cannot cross stage boundaries
```

Root cause is that the `Pipeline` construct creates a support stack
in the `App` scope, which is outside its containing `Stage`, and hence
the dependency crosses stage boundaries.

Fixes #17643.
rix0rrr added a commit that referenced this issue Nov 26, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Because a cross-environment pipeline cannot be created in `Stage`,
it cannot be deployed using CDK Pipelines.

The error is:

```
Error: You cannot add a dependency from 'AAA' (in Stage 'BBB') to 'CCC' (in the App): dependency cannot cross stage boundaries
```

Root cause is that the `Pipeline` construct creates a support stack
in the `App` scope, which is outside its containing `Stage`, and hence
the dependency crosses stage boundaries.

Fixes #17643.
@mergify mergify bot closed this as completed in #17730 Nov 26, 2021
mergify bot pushed a commit that referenced this issue Nov 26, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…17730)

Because a cross-environment pipeline cannot be created in `Stage`,
it cannot be deployed using CDK Pipelines.

The error is:

```
Error: You cannot add a dependency from 'AAA' (in Stage 'BBB') to 'CCC' (in the App): dependency cannot cross stage boundaries
```

Root cause is that the `Pipeline` construct creates a support stack
in the `App` scope, which is outside its containing `Stage`, and hence
the dependency crosses stage boundaries.

Fixes #17643.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

beezly pushed a commit to beezly/aws-cdk that referenced this issue Nov 29, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…ws#17730)

Because a cross-environment pipeline cannot be created in `Stage`,
it cannot be deployed using CDK Pipelines.

The error is:

```
Error: You cannot add a dependency from 'AAA' (in Stage 'BBB') to 'CCC' (in the App): dependency cannot cross stage boundaries
```

Root cause is that the `Pipeline` construct creates a support stack
in the `App` scope, which is outside its containing `Stage`, and hence
the dependency crosses stage boundaries.

Fixes aws#17643.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
pedrosola pushed a commit to pedrosola/aws-cdk that referenced this issue Dec 1, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…ws#17730)

Because a cross-environment pipeline cannot be created in `Stage`,
it cannot be deployed using CDK Pipelines.

The error is:

```
Error: You cannot add a dependency from 'AAA' (in Stage 'BBB') to 'CCC' (in the App): dependency cannot cross stage boundaries
```

Root cause is that the `Pipeline` construct creates a support stack
in the `App` scope, which is outside its containing `Stage`, and hence
the dependency crosses stage boundaries.

Fixes aws#17643.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…ws#17730)

Because a cross-environment pipeline cannot be created in `Stage`,
it cannot be deployed using CDK Pipelines.

The error is:

```
Error: You cannot add a dependency from 'AAA' (in Stage 'BBB') to 'CCC' (in the App): dependency cannot cross stage boundaries
```

Root cause is that the `Pipeline` construct creates a support stack
in the `App` scope, which is outside its containing `Stage`, and hence
the dependency crosses stage boundaries.

Fixes aws#17643.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants