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

fix(core): impossible to use the same physical stack name for two stacks (under feature flag) #4895

Merged
merged 1 commit into from
Nov 11, 2019

Conversation

eladb
Copy link
Contributor

@eladb eladb commented Nov 7, 2019

Since we used the stack name as the template file name, if users wanted to use the
same stack name in two environments, the emitted templates overwrote each other.

Apparently, the CLI used the artifact ID as the stack name, so this became a bit more complex.
This means that assembly.getStack() is now ambiguous, so I renamed it getStackByName which fails if there are two stacks with the same name (legitimate) and added getStackArtifact which uses the artifact ID.

The core library will effecitvely generate identical cloud assemblies if the stack name and artifact IDs are the same, and to ensure backwards compat, no existing tests have been changed (albeit it would have been more correct to replace all getStackByName with getStackArtifact, but effectively this is the same thing if they are equal).

We want the template file name to use the artifact ID instead of the physical stack name but this can break users that depend on this behavior (despite the fact that it's a formal API). To avoid this, we will only enable this new behavior behind a feature flag which means that it will only be enabled for new projects created through cdk init, but old projects will still get the old behavior.

RFC for feature flags: #4925

Fixes #4412

BREAKING CHANGE: synthesized template file names for new projects created by cdk init will use the stack artifact ID instead of the physical stack name to enable multiple stacks to use the same name (in most cases artifact id and stack name are the same). This is enabled by inserting the feature flag @aws-cdk/core:enableStackNameDuplicates under context in newly generated cdk.json files.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@mergify
Copy link
Contributor

mergify bot commented Nov 7, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@eladb eladb added the pr/do-not-merge This PR should not be merged at this time. label Nov 7, 2019
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@eladb eladb changed the title fix(core): unable to use the same stack name for two stacks in different environments fix(core): impossible to use the same physical stack name for two stacks Nov 8, 2019
@eladb eladb changed the title fix(core): impossible to use the same physical stack name for two stacks fix(core): impossible to use the same physical stack name for two stacks (behind future flag) Nov 8, 2019
@eladb eladb changed the title fix(core): impossible to use the same physical stack name for two stacks (behind future flag) fix(core): impossible to use the same physical stack name for two stacks (future flag) Nov 8, 2019
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@eladb eladb removed the pr/do-not-merge This PR should not be merged at this time. label Nov 8, 2019
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this PR not include bump to the CX protocol?

CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
packages/@aws-cdk/assert/lib/inspector.ts Show resolved Hide resolved
packages/@aws-cdk/core/lib/stack.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/core/lib/stack.ts Show resolved Hide resolved
packages/@aws-cdk/core/test/test.stack.ts Show resolved Hide resolved
packages/aws-cdk/bin/cdk.ts Show resolved Hide resolved
packages/aws-cdk/lib/api/deploy-stack.ts Show resolved Hide resolved
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@eladb eladb changed the title fix(core): impossible to use the same physical stack name for two stacks (future flag) fix(core): impossible to use the same physical stack name for two stacks (under feature flag) Nov 8, 2019
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@SomayaB SomayaB added the contribution/core This is a PR that came from AWS. label Nov 8, 2019
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

…feature flag)

Since we used the stack name as the template file name, if users wanted to use the same stack name in two environments, the emitted templates overwrote each other.

Furthermore, the CLI used the artifact ID as the stack name, so this became a bit more complex. This means that `assembly.getStack()` is now ambiguous, so I renamed it `getStackByName` which fails if there are two stacks with the same name (legitimate) and added `getStackArtifact` which uses the artifact ID.

The core library will effectively generate identical cloud assemblies if the stack name and artifact IDs are the same, and to ensure backwards compat, no existing tests have been changed (albeit it would have been more correct to replace all `getStackByName` with `getStackArtifact`, but effectively this is the same thing if they are equal).

We want the template file name to use the artifact ID instead of the physical stack name but this can break users that depend on this behaviour (despite the fact that it's a formal API). To avoid this, we will only enable this new behaviour behind a [feature flag](#4925) which means that it will only be enabled for new projects created through `cdk init`, but old projects will still get the old behaviour.

RFC for feature flags: #4925

Fixes #4412

BREAKING CHANGE: template file names in `cdk.out` for new projects created by `cdk init` will use `stack.artifactId` instead of the physical stack name to enable multiple stacks to use the same name. In most cases the artifact ID is the same as the stack name. To enable this fix for old projects, add the context key `@aws-cdk/core:enableStackNameDuplicates: true` in your `cdk.json` file.
@eladb eladb force-pushed the benisrae/fix-template-file-name branch from d567535 to 36f0545 Compare November 11, 2019 11:26
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@eladb eladb merged commit 658f100 into master Nov 11, 2019
@eladb eladb deleted the benisrae/fix-template-file-name branch November 11, 2019 11:45
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@joekiller
Copy link

@eladb

FWIW I had to update my classes that implement core.Stack because I just happened to be using the property artifact_id in my stacks and this change was breaking for me.

    self.artifact_id = artifact_id
    AttributeError: can't set attribute

eladb pushed a commit that referenced this pull request Nov 13, 2019
Legacy mode for #4895 still used the uniquely generated id instead of the stack name as the artifact ID in the cloud assembly. The implications were that even if users were not opted-in to the new behavior (through the feature flag), they could not use the stack name in the CLI because the stack artifact ID was still new.

This fix ensures that if the feature flag is not enabled, the artifact ID itself uses the stack name, hence allowing users to query by stack name as long as they are not opted in to the new behavior.

Fixes #4997
mergify bot pushed a commit that referenced this pull request Nov 13, 2019
…4998)

Legacy mode for #4895 still used the uniquely generated id instead of the stack name as the artifact ID in the cloud assembly. The implications were that even if users were not opted-in to the new behavior (through the feature flag), they could not use the stack name in the CLI because the stack artifact ID was still new.

This fix ensures that if the feature flag is not enabled, the artifact ID itself uses the stack name, hence allowing users to query by stack name as long as they are not opted in to the new behavior.

Fixes #4997
RomainMuller pushed a commit that referenced this pull request Nov 13, 2019
…4998)

Legacy mode for #4895 still used the uniquely generated id instead of the stack name as the artifact ID in the cloud assembly. The implications were that even if users were not opted-in to the new behavior (through the feature flag), they could not use the stack name in the CLI because the stack artifact ID was still new.

This fix ensures that if the feature flag is not enabled, the artifact ID itself uses the stack name, hence allowing users to query by stack name as long as they are not opted in to the new behavior.

Fixes #4997
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Usage of cdk.StackProps.stackName when having multiple stacks with the same name
6 participants