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

Added the PrimaryIpv6 argument in launch template network configuration. #37142

Merged
merged 18 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/37142.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_launch_template: Add `PrimaryIpv6` argument
```
14 changes: 14 additions & 0 deletions internal/service/ec2/ec2_launch_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,12 @@ func ResourceLaunchTemplate() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"primary_ipv6": {
Type: nullable.TypeNullableBool,
Optional: true,
DiffSuppressFunc: nullable.DiffSuppressNullableBool,
ValidateFunc: nullable.ValidateTypeStringNullableBool,
},
"private_ip_address": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1977,6 +1983,10 @@ func expandLaunchTemplateInstanceNetworkInterfaceSpecificationRequest(tfMap map[
apiObject.AssociatePublicIpAddress = aws.Bool(v)
}

if v, null, _ := nullable.Bool(tfMap["primary_ipv6"].(string)).ValueBool(); !null {
apiObject.PrimaryIpv6 = aws.Bool(v)
}

if v, null, _ := nullable.Bool(tfMap["delete_on_termination"].(string)).ValueBool(); !null {
apiObject.DeleteOnTermination = aws.Bool(v)
}
Expand Down Expand Up @@ -2968,6 +2978,10 @@ func flattenLaunchTemplateInstanceNetworkInterfaceSpecification(apiObject *ec2.L
tfMap["associate_public_ip_address"] = strconv.FormatBool(aws.BoolValue(v))
}

if v := apiObject.PrimaryIpv6; v != nil {
tfMap["primary_ipv6"] = strconv.FormatBool(aws.BoolValue(v))
}

if v := apiObject.DeleteOnTermination; v != nil {
tfMap["delete_on_termination"] = strconv.FormatBool(aws.BoolValue(v))
}
Expand Down
87 changes: 87 additions & 0 deletions internal/service/ec2/ec2_launch_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ func TestAccEC2LaunchTemplate_networkInterface(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "network_interfaces.0.ipv6_prefixes.#", "0"),
resource.TestCheckResourceAttr(resourceName, "network_interfaces.0.network_card_index", "0"),
resource.TestCheckResourceAttrSet(resourceName, "network_interfaces.0.network_interface_id"),
resource.TestCheckResourceAttr(resourceName, "network_interfaces.0.primary_ipv6", ""),
resource.TestCheckResourceAttr(resourceName, "network_interfaces.0.private_ip_address", ""),
resource.TestCheckResourceAttr(resourceName, "network_interfaces.0.security_groups.#", "0"),
resource.TestCheckResourceAttr(resourceName, "network_interfaces.0.subnet_id", ""),
Expand Down Expand Up @@ -1393,6 +1394,54 @@ func TestAccEC2LaunchTemplate_instanceMarketOptions(t *testing.T) {
})
}

func TestAccEC2LaunchTemplate_primaryIPv6(t *testing.T) {
ctx := acctest.Context(t)
var template ec2.LaunchTemplate
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_launch_template.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckLaunchTemplateDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccLaunchTemplateConfig_primaryIPv6(rName, "true"),
Check: resource.ComposeTestCheckFunc(
testAccCheckLaunchTemplateExists(ctx, resourceName, &template),
resource.TestCheckResourceAttr(resourceName, "network_interfaces.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "network_interfaces.0.network_interface_id"),
resource.TestCheckResourceAttr(resourceName, "network_interfaces.0.primary_ipv6", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccLaunchTemplateConfig_primaryIPv6(rName, "false"),
Check: resource.ComposeTestCheckFunc(
testAccCheckLaunchTemplateExists(ctx, resourceName, &template),
resource.TestCheckResourceAttr(resourceName, "network_interfaces.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "network_interfaces.0.network_interface_id"),
resource.TestCheckResourceAttr(resourceName, "network_interfaces.0.primary_ipv6", "false"),
),
},
{
Config: testAccLaunchTemplateConfig_primaryIPv6(rName, "null"),
Check: resource.ComposeTestCheckFunc(
testAccCheckLaunchTemplateExists(ctx, resourceName, &template),
resource.TestCheckResourceAttr(resourceName, "network_interfaces.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "network_interfaces.0.network_interface_id"),
resource.TestCheckResourceAttr(resourceName, "network_interfaces.0.primary_ipv6", ""),
),
},
},
})
}

func TestAccEC2LaunchTemplate_instanceRequirements_memoryMiBAndVCPUCount(t *testing.T) {
ctx := acctest.Context(t)
var template ec2.LaunchTemplate
Expand Down Expand Up @@ -3813,6 +3862,44 @@ resource "aws_launch_template" "test" {
`, rName, associatePublicIPAddress)
}

func testAccLaunchTemplateConfig_primaryIPv6(rName, primaryIPv6 string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.1.0.0/16"

tags = {
Name = %[1]q
}
}

resource "aws_subnet" "test" {
vpc_id = aws_vpc.test.id
cidr_block = "10.1.0.0/24"

tags = {
Name = %[1]q
}
}

resource "aws_network_interface" "test" {
subnet_id = aws_subnet.test.id

tags = {
Name = %[1]q
}
}

resource "aws_launch_template" "test" {
name = %[1]q

network_interfaces {
network_interface_id = aws_network_interface.test.id
primary_ipv6 = %[2]s
}
}
`, rName, primaryIPv6)
}

func testAccLaunchTemplateConfig_associateCarrierIPAddress(rName, associateCarrierIPAddress string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/launch_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ This data source exports the following attributes in addition to the arguments a
* `http_put_response_hop_limit` - The desired HTTP PUT response hop limit for instance metadata requests.
* `security_groups` - List of associated Security Group IDS.
* `associate_public_ip_address` - Whether a Public IP address is associated with the instance.
* `primary_ipv6` - Whether the first IPv6 GUA will be made the primary IPv6 address.
Copy link
Contributor

Choose a reason for hiding this comment

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

This updates the wrong docs. :/ Launch Configurations don't support this attribute, and are deprecated. I think this was meant to be added to aws_launch_template docs

* `user_data` - User Data of the instance.
* `enable_monitoring` - Whether Detailed Monitoring is Enabled.
* `ebs_optimized` - Whether the launched EC2 instance will be EBS-optimized.
Expand Down