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(cdk): only make Outputs Exports when necessary #1624

Merged
merged 5 commits into from
Feb 5, 2019

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Jan 28, 2019

Export names must be unique and can conflict, so automatically turning
every Output into an Export can lead to problems for customers who
deploy the same template multiple times. Especially when the outputs
are created for them and they have no control over them.

We'll turn Outputs into exports on-demand (when .makeImportValue() is
called).

Fixes #903, fixes #1611.


Pull Request Checklist

  • Testing
    • Unit test added
    • CLI change?: manually run integration tests and paste output as a PR comment
    • cdk-init template change?: coordinated update of integration tests with team
  • Docs
    • jsdocs: All public APIs documented
    • README: README and/or documentation topic updated
  • Title and Description
    • Change type: title prefixed with fix, feat will appear in changelog
    • Title: use lower-case and doesn't end with a period
    • Breaking?: last paragraph: "BREAKING CHANGE: <describe what changed + link for details>"
    • Issues: Indicate issues fixed via: "Fixes #xxx" or "Closes #xxx"
  • Sensitive Modules (requires 2 PR approvers)
    • IAM Policy Document (in @aws-cdk/aws-iam)
    • EC2 Security Groups and ACLs (in @aws-cdk/aws-ec2)
    • Grant APIs (only if not based on official documentation with a reference)

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

Export names must be unique and can conflict, so automatically turning
every Output into an Export can lead to problems for customers who
deploy the same template multiple times. Especially when the outputs
are created for them and they have no control over them.

We'll turn Outputs into exports on-demand (when .makeImportValue() is
called).

Fixes #903, fixes #1611.
@rix0rrr rix0rrr requested a review from a team as a code owner January 28, 2019 12:46
*/
export?: string;

/**
* Disables the automatic allocation of an export name for this output.
*
* @default false, which means that an export name is either explicitly
* specified or allocated based on the output's logical ID and stack name.
* This disables use of `makeImportValue()` if `export` is not given.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say prohibits rather than disables here... What is disabled is auto-allocation of an export name, and the corollary is you cannot use makeImportValue() unless an export name was provided at creation time.

@@ -76,16 +81,16 @@ export class Output extends StackElement {
this._value = props.value;
this.condition = props.condition;

this.disableExport = props.disableExport !== undefined ? props.disableExport : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

!!props.disableExport ?

this.disableExport = props.disableExport !== undefined ? props.disableExport : false;

if (props.export && this.disableExport) {
throw new Error('Cannot set `disableExport` and specify an export name');
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to contradict what the props documentation says. But TBH I prefer this... And I'd suggest replacing disableExport with something like exportable (semantic is flipped: if !exportable, then you cannot provide - or have allocated - an export name).

*/
private uniqueOutputName() {
// prefix export name with stack name since exports are global within account + region.
const stackName = require('./stack').Stack.find(this).name;
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not like this inline require call. Why not import Stack normally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cyclic dependencies. The core library is rife with them. :(

private uniqueOutputName() {
// prefix export name with stack name since exports are global within account + region.
const stackName = require('./stack').Stack.find(this).name;
return (stackName ? stackName + ':' : '') + this.logicalId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why bother for the case of an un-named stack? I guess this only ever happens in unit tests, where this shouldn't matter. I'd be up for using

return `${stackName}:${this.logicalId}`;

@eladb
Copy link
Contributor

eladb commented Feb 4, 2019

@rix0rrr any updates?

@rix0rrr rix0rrr self-assigned this Feb 4, 2019
@rix0rrr rix0rrr merged commit ebb8aa1 into master Feb 5, 2019
@rix0rrr rix0rrr deleted the huijbers/no-exports branch February 5, 2019 16:37
@fulghum fulghum added the effort/medium Medium work item – several days of effort label Feb 11, 2019
@NGL321 NGL321 added the contribution/core This is a PR that came from AWS. label Sep 27, 2019
@tylerkatz
Copy link

This has not been added to the Golang CDK library. Exports are automatically created.

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. effort/medium Medium work item – several days of effort
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RestApi Endpoint Output Name & Export core: Disable export-by-default
6 participants