Skip to content

Conversation

phuhung273
Copy link
Contributor

@phuhung273 phuhung273 commented Apr 4, 2025

Issue # (if applicable)

Closes #33876

Description of changes

LogicalId generation cover unresolved token case.

Description of how you validated changes

Unit + Integ

Checklist


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

@aws-cdk-automation aws-cdk-automation requested a review from a team April 4, 2025 06:36
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p1 admired-contributor [Pilot] contributed between 13-24 PRs to the CDK labels Apr 4, 2025
Copy link

codecov bot commented Apr 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.98%. Comparing base (242091a) to head (3290166).
Report is 16 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #34041   +/-   ##
=======================================
  Coverage   83.98%   83.98%           
=======================================
  Files         120      120           
  Lines        6976     6976           
  Branches     1178     1178           
=======================================
  Hits         5859     5859           
  Misses       1005     1005           
  Partials      112      112           
Flag Coverage Δ
suite.unit 83.98% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk ∅ <ø> (∅)
packages/aws-cdk-lib/core 83.98% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Apr 4, 2025
@shikha372 shikha372 self-assigned this Apr 9, 2025
this.mountTargetsAvailable = [];
if (useMountTargetOrderInsensitiveLogicalID) {
if (useMountTargetOrderInsensitiveLogicalID || useMountTargetImportedSubnetAwareLogicalID) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can’t we handle this specifically for unresolved token values? For example, we could check if subnet.node.id is an unresolved token — if it is, we replace it with a unique ID; otherwise, we leave it as is. From what I see, the current implementation likely doesn't work correctly when the value is unresolved. This check should allow us to conditionally update the value. Let me know if you can think of any scenarios where it would work with token values — in that case, we might need to introduce a feature flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your guidance, i should have done that in the 1st place. This logic is updated as suggested, please have a check.

Copy link
Contributor

@shikha372 shikha372 Apr 23, 2025

Choose a reason for hiding this comment

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

Thank you @phuhung273 , looking at this again, i can think of one more use case for this scenario, where you're referring to the subnet ID of an existing VPC and not an imported subnet, something like

const vpc = new ec2.Vpc(stack, 'Vpc', {
  natGateways: 1,
  restrictDefaultSecurityGroup: false,
  subnetConfiguration: [
    {
      name: 'test',
      subnetType: ec2.SubnetType.PUBLIC,
    },
  ],
});

const fileSystem = new FileSystem(stack, 'FileSystem', {
  vpc,
  vpcSubnets: vpc.selectSubnets({
    subnets: vpc.publicSubnets,
  }),
});

can we confirm it doesn't impact the existing subnet references that are created through CDK, want to make sure that we don't change this mistakenly for any case of non-imported subnets before opting out of feature flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry this took a while as I had no idea how to validate all cases, but here are what I found:

For the case that you're referring to

Can confirm that subnet.node.id is not a token, therefore still keep old logic.
Screenshot 2025-04-26 065958

Checking ec2.Vpc constructor

All subnets created by constructor are given a non-token id, following pattern Subnet1, Subnet2, Subnet3, matching with the behaviour of above case

subnetConstructId: subnetId(configuration.name, index),

export function subnetId(name: string, i: number) {
return `${name}Subnet${i + 1}`;
}

Most important point

If there is any case that we haven't covered, and it is a token, then it doesn't even work from the first place, yelling the same error as the originated issue.

Your amazing suggestion to use Token.isUnresolved ensures we only cover those cases that never work. I think it's totally safe. Let me know if you can think of any other cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, thank you @phuhung273

@phuhung273 phuhung273 force-pushed the efs-imported-subnet branch from 3290166 to 132a68a Compare April 16, 2025 14:15
@phuhung273 phuhung273 changed the title fix(efs): reference imported subnet (under feature flag) fix(efs): reference imported subnet Apr 16, 2025
@phuhung273 phuhung273 requested a review from shikha372 April 16, 2025 15:04
@phuhung273 phuhung273 changed the title fix(efs): reference imported subnet fix(efs): support imported subnet Apr 26, 2025
Copy link
Contributor

mergify bot commented Apr 28, 2025

Thank you for contributing! Your pull request will be updated from main 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: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: e669292
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit 20df8fb into aws:main Apr 28, 2025
13 of 15 checks passed
Copy link
Contributor

mergify bot commented Apr 28, 2025

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

Copy link
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 28, 2025
@phuhung273 phuhung273 deleted the efs-imported-subnet branch April 29, 2025 05:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p1 pr/needs-maintainer-review This PR needs a review from a Core Team Member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-efs: FileSystem deployment fails if vpcSubnets are referenced from existing subnets
3 participants