-
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
ec2: specifying EC2 private IP with associate public IP enabled generates invalid CFn #26187
Comments
Per cloudformation doc
I believe CDK should throw when both this option and network interfaces option are specified. |
…enabled generates invalid CFn (#26208) When both associatePublicIpAddress and privateIpAddress properties are supplied to the EC2 Instance construct, an invalid CloudFormation template is generated due to the presence of both PrivateIpAddess and NetworkInterfaces properties on the AWS::EC2::Instance resource. The generated template leaves the PrivateIpAddress property populated but also includes a NetworkInterfaces property, resulting in a deployment error: "Network interfaces and an instance-level private IP address may not be specified on the same request." (see [the AWS::EC2::Instance docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html#cfn-ec2-instance-privateipaddress)) This erroneous behavior is due to the fact that a network interface is automatically created by the construct when the associatePublicIpAddress is ```true``` while leaving the PrivateIpAddress property on the resource. This PR includes a fix that modifies the behavior of the logic that creates the NetworkInterface to move the private IP to that auto-generated NI, eliminating the top-level resource property. Closes #26187. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
@mrgrain I see that this change has been merged in, and I also see that the changelog indicates that the change was incorporated into 2.87.0 (build 9fca790). However, when I test locally, I'm still seeing the invalid EC2 resource being generated. I would debug it, but since I have no mapfiles (see #20561) to walk through the code, I can't. Is there a chance an old copy of aws-cdk-lib is being shipped in 2.87.0? |
Describe the bug
When both associatePublicIpAddress and privateIpAddress properties are supplied to the EC2 Instance construct, an invalid CloudFormation template is generated due to the presence of both PrivateIpAddess and NetworkInterfaces properties on the AWS::EC2::Instance resource.
Expected Behavior
The value of the privateIpAddress property should be added to the generated NetworkInterface, omitting the resource-level PrivateIpAddress property.
Current Behavior
The generated template leaves the PrivateIpAddress property populated but also includes a NetworkInterfaces property, resulting in a deployment error: "Network interfaces and an instance-level private IP address may not be specified on the same request"
Reproduction Steps
cdk synth
, capturing the output.cdk deploy
- this will result in the "Network interfaces and an instance-level private IP address may not be specified on the same request" error and rollback.Possible Solution
The logic used to detect the use of associatePublicIpAddress should also include moving the value of privateIpAddress to the NetworkInterface object.
Additional Information/Context
No response
CDK CLI Version
2.85.0 (build 4e0d726)
Framework Version
No response
Node.js Version
18.0.0
OS
Windows, Mac
Language
Typescript
Language Version
5.1.3
Other information
No response
The text was updated successfully, but these errors were encountered: