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]: Instance - support for NetworkInterfaces #17127

Closed
2 tasks
mainframenzo opened this issue Oct 23, 2021 · 3 comments · Fixed by #25441
Closed
2 tasks

[aws-ec2]: Instance - support for NetworkInterfaces #17127

mainframenzo opened this issue Oct 23, 2021 · 3 comments · Fixed by #25441
Assignees
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@mainframenzo
Copy link

mainframenzo commented Oct 23, 2021

Description

Add boolean property of associatePublicIpAddress to ec2.Instance properties.

Use Case

AutoScalingGroup does this, but in my case the instance is not in an ASG, and my subnet is configured to not map public IPs by default.

Proposed Solution

I'll leave this to you.

Other information

No response

Acknowledge

  • I may be able to implement this feature request
  • This feature might incur a breaking change
@mainframenzo mainframenzo added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Oct 23, 2021
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Oct 23, 2021
@mainframenzo mainframenzo changed the title [aws-ec2]: Add autoAssignPublicIp for ec2.Instance [aws-ec2]: Add associatePublicIpAddress for ec2.Instance Oct 23, 2021
@njlynch njlynch added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Oct 25, 2021
@njlynch njlynch removed their assignment Oct 25, 2021
@njlynch
Copy link
Contributor

njlynch commented Oct 25, 2021

Thanks for the feature request.

It looks like the way to do this is to set the NetworkInterfaces property of the instance.

    "NetworkInterfaces": [ {
      "AssociatePublicIpAddress": "true",
      "DeviceIndex": "0",
      "GroupSet": [{ "Ref" : "myVPCEC2SecurityGroup" }],
      "SubnetId": { "Ref" : "PublicSubnet" }
    } ]

(Source: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html#aws-properties-ec2-instance--examples)

In the meantime, you can use escape hatches to set the above properties on your instance.

@corymhall corymhall changed the title [aws-ec2]: Add associatePublicIpAddress for ec2.Instance [aws-ec2]: Instance - support for NetworkInterfaces Jun 23, 2022
@allquixotic
Copy link

This has been sitting for a long time, and also affects LaunchTemplates. This greatly complicates working with LaunchTemplate construct in CDK. Can this be implemented already?

@MrArnoldPalmer MrArnoldPalmer added p2 and removed p1 labels Jan 27, 2023
@colifran colifran self-assigned this May 2, 2023
@mergify mergify bot closed this as completed in #25441 May 23, 2023
mergify bot pushed a commit that referenced this issue May 23, 2023
…roviding an associatePublicIpAddress property (#25441)

## Motivation

When creating and launching an EC2 instance, a public IPv4 address will be assigned by default for any instances being launched into a default public subnet. Conversely, any EC2 instance being launched into a nondefault public subnet will not be automatically assigned a public IPv4 address. The decision to automatically assign or not assign a public IPv4 address is based on a subnet property which is true by default for default public subnets and false by default for nondefault public subnets. This property can be controlled by specifying that the 'associatePublicIpAddress' be true for an EC2 instance. This property can be exposed via the 'networkInterfaces' property on the underlying L1 CfnInstance construct. Furthermore, any network interface that has an 'associatePublicIpAddress' set to true must also be the primary network interface for the EC2 instance and a primary network interface will always have a device index of 0. The work in this PR will allow a user to automatically have a public IPv4 address assigned to an EC2 instance that they are launching into a nondefault public subnet or stop the default subnet behavior of automatically assigning a public IPv4 address.

## Important Changes

The changes made in this PR start by exposing the 'networkInterfaces' property on the underlying L1 CfnInstance. Next, I added 'associatePublicIpAddress' as an optional boolean property that is part of the 'InstanceProps' interface. Importantly, if 'associatePublicIpAddress' is set to true or false, then this means we need to launch the EC2 instance with a configured primary network interface. If 'associatePublicIpAddress' is set to true or false, a network interfaces array is created with the specified network interface configuration for the primary network interface. The subnetId and securityGroupIds are also configured for the network interface since they must be defined on the network interface level when launching an EC2 instance with a configured network interface. I updated the L1 CfnInstance to set subnetId and securityGroupIds to undefined in the event that the network interfaces array is defined. 

Closes #17127

----

*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

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
5 participants