-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
How to import existing VPC #506
Comments
You can use the Bear in mind that VPC has a pretty large surface area, so you will need to specify quite a lot of information in order to import an existing VPC. const externalVpc = VpcNetwork.import(this, 'ExternalVpc', {
vpcId: 'vpc-bd5656d4',
availabilityZones: [ 'us-east1a', 'us-east-1b' ],
publicSubnetIds: [ 'subnet-1111aaaa', 'subnet-2222bbbb' ],
privateSubnetIds: [ 'subnet-8368fbce', 'subnet-8368abcc' ],
}); And now: new ec2.AutoScalingGroup(stack, 'ASG', {
vpc: externalVpc,
// ...
}); I wonder if it might make sense to provide an environmental context provider that will allow you to read VPC information from the associated account and import it. It shouldn't be hard to implement, so you could just specify the VPC ID and it will save all the other details from |
👍 |
Thanks @eladb , I will try and update on this. |
Hi @nikhilbhoj are you still having issues? |
@debora-ito , I haven't done it yet. I will do it in the coming weekend and update my finding. |
Coming from this StackOverflow Indeed, it would be a nice to have to have a helper to import just with a vpcId. Is there a feature request for that already? |
@pierreozoux it's usually not very useful to just have a VPCID because in most cases you would need to specify a subnet in order to actually use the VPC. |
Sometimes it would be incredibly pragmatic to have a VpcNetworkRef with just an id, e.g. new route53.PrivateHostedZone(this, 'HostedZone', {
zoneName: 'foo.example.com',
vpc: something('vpc-12345678'),
}); There's no reason for this stack/app to know or look up more details about that existing VPC. Currently I implement the private vpcRef(vpcId : string) : ec2.VpcNetworkRef {
return ec2.VpcNetworkRef.import(this, 'unused', {vpcId, availabilityZones: ['unused']})
} |
@pda it was exactly my use case, thanks for sharing :) |
does the introduction of
|
|
If you are getting errors as of 0.36 this only works if you add |
Please also note that you can use the |
Hi, I'm using
Have you changed anything related to it in the last version of CDK? |
@david-a I had the same issue. In my case removing |
I'm attempting to import a created VPC using the approach recommended above but it only works if I supply the vpcId. I'd rather use something less volatile like a name. const vpc = ec2.Vpc.fromLookup(this, "vpc", {
// vpcId: "vpc-0e3e027882ce530fa", // <--- this by itself works
// tags: {"Name": "base-infrastructure-vpc"},
vpcName: "base-infrastructure-vpc/vpc",
}); In the above snippet having |
I have created one blog post on this for CDK in custom VPC for me it works. Here is the link for that https://nikhilbhojcloud.blogspot.com/2019/08/cdk-fargate-load-balanced-service-using.html by referring VPC as "MyVPC" |
hmm... actually my code works if I don't depend on |
Is there a way that we can query and find the CIDR range for an existing VPC? We are using |
@eladb any suggestions on this the above question of any possible way of finding default cidr range of an existing vpc? |
Running into a similar issue as @ashwgupt . I can import an existing VPC no problem but when I try to access the
Any reason this isn't populated when importing the VPC? |
Any luck with bypassing this, anyone? running into the same issue with undefined CIDR: |
@eladb, what's the point of importing a VPC if you have to specify all the other attributes (e.g., subnets, AZs, etc.) and not just the VPC ID? I'd imagine the CDK would get this information on behalf of the developer. |
Seems like specifying a VPC id should be all the CDK should need. It can glean all relevant/connected resources from that. Importing each piece separately is time consuming and makes for a horrible user experience. |
Hi,
Can any one guide, how to import existing VPC like we can do in terraform using data using ec2.VpcNetwork() construct ?
const vpc = new ec2.VpcNetwork(this, 'VPC');
Thanks,
Nikhil
The text was updated successfully, but these errors were encountered: