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

(aws-ec2): L1 VPC to L2 VPC transformation #14809

Open
1 of 2 tasks
brockuniera opened this issue May 20, 2021 · 13 comments
Open
1 of 2 tasks

(aws-ec2): L1 VPC to L2 VPC transformation #14809

brockuniera opened this issue May 20, 2021 · 13 comments
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud effort/large Large work item – several weeks of effort feature-request A feature should be added or improved. p2

Comments

@brockuniera
Copy link

Static method on Vpc akin to .fromLookup with signature .fromCfnVpc(cfnvpc: CfnVpc): IVpc that performs a hopefully simple transform on a CfnVpc to return a IVpc.

Use Case

More convenient and supported method for mixing CfnInclude'd CloudFormation templates with CDK constructs.

Proposed Solution

Implement the described static method.

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@brockuniera brockuniera added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels May 20, 2021
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label May 20, 2021
@skinny85 skinny85 assigned skinny85 and unassigned rix0rrr May 20, 2021
@skinny85 skinny85 added effort/large Large work item – several weeks of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels May 20, 2021
@skinny85
Copy link
Contributor

Thanks for opening the issue @brockuniera. We are thinking about this.

Related: #14795

mergify bot pushed a commit that referenced this issue Jun 3, 2021
This is part 1 of adding support from converting L1 resources to L2 without making them immutable in the process.
Next phase after this will be adding support for `Bucket.fromCfnBucket()`
(which will use the method from KMS defined here).

Related issues: #9719 #14795 #14809

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Aug 26, 2021
This is part 1 of adding support from converting L1 resources to L2 without making them immutable in the process.
Next phase after this will be adding support for `Bucket.fromCfnBucket()`
(which will use the method from KMS defined here).

Related issues: aws#9719 aws#14795 aws#14809

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jun 17, 2022
@mattsoftware
Copy link

I would love to see this - I have my vpc defined with a CfnVpc to get a little more control over the creation of subnets etc, and I need to use this vpc in the rest of my stack. At the moment I am doing a lookup based on tags which breaks if the stacks do not run in the correct order.

@github-actions github-actions bot removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jun 22, 2022
@moosius
Copy link

moosius commented Aug 14, 2022

I'm dealing with a similar scenario as mattsoftware and would find this extremely useful as well.

@dsmurrell
Copy link

Same here @moosius ! This CDK seems much more complicated than it needs to be.

@elaurijssens
Copy link

This would be so useful! We cannot create our own VPC code because we have to connect to a corporate network infastructure through pre-provisioned TGWs, so we're getting pre-baked CFN templates that we have to import. Not having the L2 object without using lookups is quite a pain.

@MrArnoldPalmer MrArnoldPalmer added p2 and removed p1 labels Jan 27, 2023
@shmuel-torii
Copy link

+1
My use-case: I had to create a VPC using CfnVPC since I imported an existing one. Now I want to pass it to another L2 construct that accept IVpc

@skinny85
Copy link
Contributor

skinny85 commented Feb 1, 2023

BTW, I wrote a Tweet about this topic, but let me repeat it here.

If you have a template with a VPC, and you want to turn it into an IVpc, you can use the Vpc.fromAttributes() method.

Example code in TypeScript, but something very similar should work for other languages too:

const cfnInclude = new cfn_inc.CfnInclude(this, 'VpcTemplate’,
    templateFile: ‘vpc-template.yaml',
});

const cfnVpc = cfnInclude.getResource('VPC') as ec2.CfnVPC;
const privateSubnet1 = cfnInclude.getResource('PrivateSubnet1') as ec2.CfnSubnet;
const privateSubnet2 = cfnInclude.getResource('PrivateSubnet2') as ec2.CfnSubnet;
const cfnRouteTable1 = cfnInclude.getResource('PrivateRouteTable1') as ec2.CfnRouteTable;
const cfnRouteTable2 = cfnInclude.getResource('PrivateRouteTable2') as ec2.CfnRouteTable;

const vpc = ec2.Vpc.fromVpcAttributes(this, ‘ImportedVpc', {
    vpcId: cfnVpc.ref,
    availabilityZones: cdk.Fn.getAzs(),
    privateSubnetIds: [privateSubnetl.ref, privateSubnet2.ref],
    privateSubnetRouteTableIds: [cfnRouteTablel.ref, cfnRouteTable2.ref],
});

Of course, adjust to the exact contents of your template as needed!

@jpSimkins
Copy link

jpSimkins commented Mar 28, 2023

@skinny85 Your comment is about an CF Template and this is asking for CfnVpc to be able to return an IVpc. Is there a way to use this to make CfnVpc return an IVpc?

I don't see any way to get the data needed to get the IVpc object needed with CfnVpc.

I am hitting a wall with this and I really need to be able to convert a CfnVpc to an IVpc or I will be needing to refactor systems for the next couple months...

@skinny85
Copy link
Contributor

@skinny85 Your comment is about an CF Template and this is asking for CfnVpc to be able to return an IVpc. Is there a way to use this to make CfnVpc return an IVpc?

It shouldn't matter where the CfnVPC is coming from - the same principle applies.

@jpSimkins
Copy link

Pardon my ignorance but this seems to work mostly due to the CfnInclude which the getters are not available on the cfnVpc.

const privateSubnet1 = cfnInclude.getResource('PrivateSubnet1') as ec2.CfnSubnet;
const privateSubnet2 = cfnInclude.getResource('PrivateSubnet2') as ec2.CfnSubnet;
const cfnRouteTable1 = cfnInclude.getResource('PrivateRouteTable1') as ec2.CfnRouteTable;
const cfnRouteTable2 = cfnInclude.getResource('PrivateRouteTable2') as ec2.CfnRouteTable;

I don't see any way to get these values from the CfnVpc.

@skinny85
Copy link
Contributor

What the CDK Construct Library calls the Vpc construct is a high-level resource that combines many lower-level ones inside it: CfnVPC, CfnSubnet, CfnRouteTable, etc. In fact, there's over 20 Cfn* constructs in every Vpc instance.

In order to instantiate a Vpc, the CDK needs information about many of these low-level resources. So, going from only a CfnVPC to a Vpc is not possible.

@coding-velociraptor
Copy link

I would like to add that it comes in handy, when used with copilot CLI. It started to support transforming resources through overrides:
https://aws.github.io/copilot-cli/docs/developing/overrides/cdk/

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 effort/large Large work item – several weeks of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests