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(ec2): can't use imported Subnets in a SubnetSelection #9579

Merged
merged 4 commits into from
Aug 14, 2020

Conversation

flemjame-at-amazon
Copy link
Contributor


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

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.

The title does not really describe what's wrong.

A simpler fix is to turn this into a getter:

https://github.com/aws/aws-cdk/blob/master/packages/@aws-cdk/aws-ec2/lib/vpc.ts#L348

get availabilityZones(): { return subnets.map(s => s.availabilityZone); },

Which (should) make it so that the evaluation of availabilityZone is only done when it's actually requested by a construct.

@flemjame-at-amazon
Copy link
Contributor Author

flemjame-at-amazon commented Aug 12, 2020

A simpler fix is to turn this into a getter:

https://github.com/aws/aws-cdk/blob/master/packages/@aws-cdk/aws-ec2/lib/vpc.ts#L348

get availabilityZones(): { return subnets.map(s => s.availabilityZone); },

Which (should) make it so that the evaluation of availabilityZone is only done when it's actually requested by a construct.

  public selectSubnets(selection: SubnetSelection = {}): SelectedSubnets {
    const subnets = this.selectSubnetObjects(selection);
    const pubs = new Set(this.publicSubnets);

    return {
      subnetIds: subnets.map(s => s.subnetId),
      get availabilityZones(): string[] { return subnets.map(s => s.availabilityZone); },
      internetConnectivityEstablished: tap(new CompositeDependable(), d => subnets.forEach(s => d.add(s.internetConnectivityEstablished))),
      subnets,
      hasPublic: subnets.some(s => pubs.has(s)),
    };
  }

That seems to have done it.

Any thoughts on returning a CFN reference if the AZ is referenced, but wasn't provided in the subnet lookup? Technically it would work for region-agnostic templates.

@flemjame-at-amazon flemjame-at-amazon changed the title fix(ec2): subnet AZ evaluation for imported subnet fix(ec2): fix imported subnets throwing error during subnet selection Aug 12, 2020
@rix0rrr
Copy link
Contributor

rix0rrr commented Aug 13, 2020

Any thoughts on returning a CFN reference if the AZ is referenced, but wasn't provided in the subnet lookup? Technically it would work for region-agnostic templates.

I don't see how that will work though. How will:

{ "Fn::GetAtt": [ "s-12356", "AvailabilityZone"] }

Resolve to the availability zone of subnet s-123456? This goes against everything I know to be true about CloudFormation. Is this a special case?

(The first argument to Fn::GetAtt is typically a Logical ID of a resource that exists in the same template, not an identifier to an arbitrary AWS resource that exists outside of the template)

EDIT: It's definitely not documented here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html

@flemjame-at-amazon
Copy link
Contributor Author

Any thoughts on returning a CFN reference if the AZ is referenced, but wasn't provided in the subnet lookup? Technically it would work for region-agnostic templates.

I don't see how that will work though. How will:

{ "Fn::GetAtt": [ "s-12356", "AvailabilityZone"] }

Resolve to the availability zone of subnet s-123456? This goes against everything I know to be true about CloudFormation. Is this a special case?

(The first argument to Fn::GetAtt is typically a Logical ID of a resource that exists in the same template, not an identifier to an arbitrary AWS resource that exists outside of the template)

EDIT: It's definitely not documented here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html

I didn't read the documentation carefully enough -- you're right, we don't get a logical ID from a subnet import. Ok I'll scrap that part of the code.

@mergify mergify bot dismissed rix0rrr’s stale review August 13, 2020 13:25

Pull request has been modified.

@rix0rrr rix0rrr changed the title fix(ec2): fix imported subnets throwing error during subnet selection fix(ec2): can't use imported Subnets in a SubnetSelection Aug 14, 2020
@mergify
Copy link
Contributor

mergify bot commented Aug 14, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 94af631
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify
Copy link
Contributor

mergify bot commented Aug 14, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 1c4eae8 into aws:master Aug 14, 2020
@flemjame-at-amazon flemjame-at-amazon deleted the fix-8301 branch September 2, 2020 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lambda Function] subnet selection tries to evaluate subnet AZ even if AZ filtering is not specified
3 participants