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

export() must be idempotent (was: error when calling export() on multiple items) #1496

Closed
BDQ opened this issue Jan 8, 2019 · 3 comments
Closed
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud @aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/small Small work item – less than a day of effort third-party This issue is related to third-party libraries or applications.

Comments

@BDQ
Copy link
Contributor

BDQ commented Jan 8, 2019

The Stack code below results in the following error:

Error: There is already a Construct with name 'PublicSubnetIDs' in VpcNetwork

export class ClusterStack extends cdk.Stack {
  public readonly vpcRefProps: ec2.VpcNetworkRefProps;
  public readonly ecsClusterRefProps: ecs.ImportedClusterProps;

  constructor(parent: cdk.App, name: string) {
    super(parent, name);

    // VPC using a small CIDR for staging
    const vpc = new ec2.VpcNetwork(this, "vpc", {
      cidr: "10.0.0.0/24",
      maxAZs: 2
    });

    // Create the ECS cluster
    const cluster = new ecs.Cluster(this, "cluster", {
      vpc
    });

    // export vpc
    this.vpcRefProps = vpc.export();
    // export cluster
    this.ecsClusterRefProps = cluster.export();
  }
}
@rix0rrr rix0rrr added @aws-cdk/core Related to core CDK functionality @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud third-party This issue is related to third-party libraries or applications. labels Jan 8, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 8, 2019

Related to:

#1095
#89 (indirectly)

@RomainMuller RomainMuller added the bug This issue is a bug. label Jan 8, 2019
@eladb
Copy link
Contributor

eladb commented Jan 8, 2019

The issue here is vpc.export() is called twice: once explicitly in the code and then implicitly as a result of cluster.export(). And our current pattern for implementing those exports is that we always define a set of new cdk.Outputs for each attribute that we wish to export.

Naturally these outputs can be reused if they are already defined.

Since this is implemented across our entire library, we can probably use some sugar methods so that implementing exports will not be a pain everywhere.

I'll rename the issue to reflect this requirement.

@eladb eladb changed the title Error when calling export() on multiple items (including a VPC) export() must be idempotent (was: error when calling export() on multiple items) Jan 8, 2019
@eladb eladb self-assigned this Jan 15, 2019
@fulghum fulghum added the effort/small Small work item – less than a day of effort label Jan 29, 2019
@eladb eladb removed their assignment May 5, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Jun 26, 2019

export() no longer exists.

@rix0rrr rix0rrr closed this as completed Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud @aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/small Small work item – less than a day of effort third-party This issue is related to third-party libraries or applications.
Projects
None yet
Development

No branches or pull requests

5 participants