From 37db9e5b8e211628fe8b37475247f66b3bbde328 Mon Sep 17 00:00:00 2001 From: Vara Bonthu Date: Sat, 30 Oct 2021 22:46:10 +0100 Subject: [PATCH 1/9] ec2 launch template network_card_index attribute added to network interfaces block --- internal/service/ec2/launch_template.go | 9 ++++ .../ec2/launch_template_data_source.go | 4 ++ internal/service/ec2/launch_template_test.go | 42 +++++++++++++++++++ website/docs/r/launch_template.html.markdown | 1 + 4 files changed, 56 insertions(+) diff --git a/internal/service/ec2/launch_template.go b/internal/service/ec2/launch_template.go index 77a2da63978..1efc63391df 100644 --- a/internal/service/ec2/launch_template.go +++ b/internal/service/ec2/launch_template.go @@ -491,6 +491,10 @@ func ResourceLaunchTemplate() *schema.Resource { ValidateFunc: validation.IsIPv6Address, }, }, + "network_card_index": { + Type: schema.TypeInt, + Optional: true, + }, "network_interface_id": { Type: schema.TypeString, Optional: true, @@ -1190,6 +1194,7 @@ func getNetworkInterfaces(n []*ec2.LaunchTemplateInstanceNetworkInterfaceSpecifi "interface_type": aws.StringValue(v.InterfaceType), "ipv4_address_count": aws.Int64Value(v.SecondaryPrivateIpAddressCount), "ipv6_address_count": aws.Int64Value(v.Ipv6AddressCount), + "network_card_index": aws.Int64Value(v.NetworkCardIndex), "network_interface_id": aws.StringValue(v.NetworkInterfaceId), "private_ip_address": aws.StringValue(v.PrivateIpAddress), "subnet_id": aws.StringValue(v.SubnetId), @@ -1614,6 +1619,10 @@ func readNetworkInterfacesFromConfig(ni map[string]interface{}) (*ec2.LaunchTemp networkInterface.DeviceIndex = aws.Int64(int64(v)) } + if v, ok := ni["network_card_index"].(int); ok { + networkInterface.NetworkCardIndex = aws.Int64(int64(v)) + } + if v, ok := ni["network_interface_id"].(string); ok && v != "" { networkInterface.NetworkInterfaceId = aws.String(v) } diff --git a/internal/service/ec2/launch_template_data_source.go b/internal/service/ec2/launch_template_data_source.go index 5a36579b3e6..04131f3804c 100644 --- a/internal/service/ec2/launch_template_data_source.go +++ b/internal/service/ec2/launch_template_data_source.go @@ -300,6 +300,10 @@ func DataSourceLaunchTemplate() *schema.Resource { Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "network_card_index": { + Type: schema.TypeInt, + Optional: true, + }, "network_interface_id": { Type: schema.TypeString, Computed: true, diff --git a/internal/service/ec2/launch_template_test.go b/internal/service/ec2/launch_template_test.go index e52795c8325..5697dec660f 100644 --- a/internal/service/ec2/launch_template_test.go +++ b/internal/service/ec2/launch_template_test.go @@ -815,6 +815,35 @@ func TestAccEC2LaunchTemplate_networkInterfaceType(t *testing.T) { }) } +func TestAccEC2LaunchTemplate_networkInterfaceCardIndex(t *testing.T) { + var template ec2.LaunchTemplate + resourceName := "aws_launch_template.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, autoscaling.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckLaunchTemplateDestroy, + Steps: []resource.TestStep{ + { + Config: testAccLaunchTemplateConfig_networkInterfaceCardIndex(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckLaunchTemplateExists(resourceName, &template), + resource.TestCheckResourceAttrSet(resourceName, "instance_type"), + resource.TestCheckResourceAttr(resourceName, "network_interfaces.#", "1"), + resource.TestCheckResourceAttr(resourceName, "network_interfaces.0.network_card_index", "1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccEC2LaunchTemplate_associatePublicIPAddress(t *testing.T) { var template ec2.LaunchTemplate rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -2023,6 +2052,19 @@ resource "aws_launch_template" "test" { `, rName) } +func testAccLaunchTemplateConfig_networkInterfaceCardIndex(rName string) string { + return fmt.Sprintf(` +resource "aws_launch_template" "test" { + name = %[1]q + instance_type = "p4d.24xlarge" + + network_interfaces { + network_card_index = 1 + } +} +`, rName) +} + const testAccLaunchTemplateConfig_asg_basic = ` data "aws_ami" "test_ami" { most_recent = true diff --git a/website/docs/r/launch_template.html.markdown b/website/docs/r/launch_template.html.markdown index f98c354dc1b..7be97163325 100644 --- a/website/docs/r/launch_template.html.markdown +++ b/website/docs/r/launch_template.html.markdown @@ -301,6 +301,7 @@ Each `network_interfaces` block supports the following: * `ipv6_addresses` - One or more specific IPv6 addresses from the IPv6 CIDR block range of your subnet. Conflicts with `ipv6_address_count` * `ipv6_address_count` - The number of IPv6 addresses to assign to a network interface. Conflicts with `ipv6_addresses` * `network_interface_id` - The ID of the network interface to attach. +* `network_card_index` - The index of the network card. Some instance types support multiple network cards. The primary network interface must be assigned to network card index 0. The default is network card index 0. * `private_ip_address` - The primary private IPv4 address. * `ipv4_address_count` - The number of secondary private IPv4 addresses to assign to a network interface. Conflicts with `ipv4_addresses` * `ipv4_addresses` - One or more private IPv4 addresses to associate. Conflicts with `ipv4_address_count` From 93897d40792c8c3cd36647b7e514abc416df8bc0 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 3 Nov 2021 11:02:03 -0400 Subject: [PATCH 2/9] Add CHANGELOG entry. --- .changelog/21555.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/21555.txt diff --git a/.changelog/21555.txt b/.changelog/21555.txt new file mode 100644 index 00000000000..754d770cd5a --- /dev/null +++ b/.changelog/21555.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_launch_template: Add `network_card_index` argument to `network_interfaces` configuration block +``` \ No newline at end of file From f5d426a9c57c0ba87cccdc07759016f8e609b706 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 3 Nov 2021 11:03:36 -0400 Subject: [PATCH 3/9] Fix terrafmt error. --- internal/service/ec2/launch_template_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/ec2/launch_template_test.go b/internal/service/ec2/launch_template_test.go index 5697dec660f..f2a49b23dc1 100644 --- a/internal/service/ec2/launch_template_test.go +++ b/internal/service/ec2/launch_template_test.go @@ -2055,7 +2055,7 @@ resource "aws_launch_template" "test" { func testAccLaunchTemplateConfig_networkInterfaceCardIndex(rName string) string { return fmt.Sprintf(` resource "aws_launch_template" "test" { - name = %[1]q + name = %[1]q instance_type = "p4d.24xlarge" network_interfaces { From 5cf09adfc4d0fef444eacc422d7c32548d25b2bf Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 3 Nov 2021 11:06:37 -0400 Subject: [PATCH 4/9] Tweak CHANGELOG entry. --- .changelog/21555.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.changelog/21555.txt b/.changelog/21555.txt index 754d770cd5a..0bd51e74996 100644 --- a/.changelog/21555.txt +++ b/.changelog/21555.txt @@ -1,3 +1,7 @@ ```release-note:enhancement resource/aws_launch_template: Add `network_card_index` argument to `network_interfaces` configuration block +``` + +```release-note:enhancement +data-source/aws_launch_template: Add `network_card_index` attribute to `network_interfaces` configuration block ``` \ No newline at end of file From 9dd8cbe9352df175fb9ce006f004f5686b803391 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 3 Nov 2021 11:23:54 -0400 Subject: [PATCH 5/9] Skip acceptance test errors like 'Error creating License Manager license configuration: ResourceLimitExceededException: You have reached the maximum allowed number of license configurations created in one day.'. --- internal/service/ec2/instance_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/service/ec2/instance_test.go b/internal/service/ec2/instance_test.go index 3af815f8410..31846328498 100644 --- a/internal/service/ec2/instance_test.go +++ b/internal/service/ec2/instance_test.go @@ -32,6 +32,7 @@ func testAccErrorCheckSkipEC2(t *testing.T) resource.ErrorCheckFunc { return acctest.ErrorCheckSkipMessagesContaining(t, "VolumeTypeNotAvailableInRegion", "Invalid value specified for Phase", + "You have reached the maximum allowed number of license configurations created in one day", ) } From 7ef0de94afce51f6d3a96f72606a0453540f8118 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 3 Nov 2021 11:38:52 -0400 Subject: [PATCH 6/9] r/aws_placement_group: 'partition_count' is Computed. --- .changelog/21555.txt | 4 ++++ internal/service/ec2/placement_group.go | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.changelog/21555.txt b/.changelog/21555.txt index 0bd51e74996..f775636f02c 100644 --- a/.changelog/21555.txt +++ b/.changelog/21555.txt @@ -4,4 +4,8 @@ resource/aws_launch_template: Add `network_card_index` argument to `network_inte ```release-note:enhancement data-source/aws_launch_template: Add `network_card_index` attribute to `network_interfaces` configuration block +``` + +```release-note:bug +resource/aws_placement_group: `partition_count` argument is Computed, preventing spurious resource diffs ``` \ No newline at end of file diff --git a/internal/service/ec2/placement_group.go b/internal/service/ec2/placement_group.go index 60bf15b831f..5ccbe59e07a 100644 --- a/internal/service/ec2/placement_group.go +++ b/internal/service/ec2/placement_group.go @@ -40,8 +40,9 @@ func ResourcePlacementGroup() *schema.Resource { }, "partition_count": { Type: schema.TypeInt, - ForceNew: true, Optional: true, + Computed: true, + ForceNew: true, // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/placement-groups.html#placement-groups-limitations-partition. ValidateFunc: validation.IntBetween(0, 7), }, From 3c49c1c438eff4f9fdd50eda1c75e7c1ccc334c2 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 3 Nov 2021 11:56:56 -0400 Subject: [PATCH 7/9] Revert "Skip acceptance test errors like 'Error creating License Manager license configuration: ResourceLimitExceededException: You have reached the maximum allowed number of license configurations created in one day.'." This reverts commit 9dd8cbe9352df175fb9ce006f004f5686b803391. --- internal/service/ec2/instance_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/service/ec2/instance_test.go b/internal/service/ec2/instance_test.go index 31846328498..3af815f8410 100644 --- a/internal/service/ec2/instance_test.go +++ b/internal/service/ec2/instance_test.go @@ -32,7 +32,6 @@ func testAccErrorCheckSkipEC2(t *testing.T) resource.ErrorCheckFunc { return acctest.ErrorCheckSkipMessagesContaining(t, "VolumeTypeNotAvailableInRegion", "Invalid value specified for Phase", - "You have reached the maximum allowed number of license configurations created in one day", ) } From af544da4c63f793d49ca43e5d4a987f51710675d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 3 Nov 2021 12:00:47 -0400 Subject: [PATCH 8/9] Skip acceptance test errors like 'Error creating License Manager license configuration: ResourceLimitExceededException: You have reached the maximum allowed number of license configurations created in one day.'. --- .../licensemanager/license_configuration_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/service/licensemanager/license_configuration_test.go b/internal/service/licensemanager/license_configuration_test.go index 5aa7e68cccd..c76a3ab02b2 100644 --- a/internal/service/licensemanager/license_configuration_test.go +++ b/internal/service/licensemanager/license_configuration_test.go @@ -14,6 +14,16 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" ) +func init() { + acctest.RegisterServiceErrorCheckFunc(licensemanager.EndpointsID, testAccErrorCheckSkipLicenseManager) +} + +func testAccErrorCheckSkipLicenseManager(t *testing.T) resource.ErrorCheckFunc { + return acctest.ErrorCheckSkipMessagesContaining(t, + "ResourceLimitExceededException", + ) +} + func TestAccLicenseManagerLicenseConfiguration_basic(t *testing.T) { var licenseConfiguration licensemanager.LicenseConfiguration resourceName := "aws_licensemanager_license_configuration.example" From 7313504d3bf1cceecf34aec0cbe8eeee1e1ce245 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 3 Nov 2021 12:05:35 -0400 Subject: [PATCH 9/9] Revert "Skip acceptance test errors like 'Error creating License Manager license configuration: ResourceLimitExceededException: You have reached the maximum allowed number of license configurations created in one day.'." This reverts commit af544da4c63f793d49ca43e5d4a987f51710675d. --- .../licensemanager/license_configuration_test.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/internal/service/licensemanager/license_configuration_test.go b/internal/service/licensemanager/license_configuration_test.go index c76a3ab02b2..5aa7e68cccd 100644 --- a/internal/service/licensemanager/license_configuration_test.go +++ b/internal/service/licensemanager/license_configuration_test.go @@ -14,16 +14,6 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" ) -func init() { - acctest.RegisterServiceErrorCheckFunc(licensemanager.EndpointsID, testAccErrorCheckSkipLicenseManager) -} - -func testAccErrorCheckSkipLicenseManager(t *testing.T) resource.ErrorCheckFunc { - return acctest.ErrorCheckSkipMessagesContaining(t, - "ResourceLimitExceededException", - ) -} - func TestAccLicenseManagerLicenseConfiguration_basic(t *testing.T) { var licenseConfiguration licensemanager.LicenseConfiguration resourceName := "aws_licensemanager_license_configuration.example"