From 56d0e45d516a6349ab60a39619214e00f437abdd Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Wed, 20 May 2020 15:47:44 -0400 Subject: [PATCH] resource/aws_eks_node_group: Only pass ReleaseVersion during UpdateNodegroupVersion if changed (#13407) Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/12675 It was expected to see an error similar to the issue report about the incompatible update and Terraform was previously submitting the state value for `release_version`, however the EKS API as of today was automatically fixing the incorrect value instead of returning an error. The resource change is to ensure that we will only submit correct API parameters should the API return errors for this situation in the future again. Output from acceptance testing: ``` --- PASS: TestAccAWSEksNodeGroup_disappears (1356.93s) --- PASS: TestAccAWSEksNodeGroup_InstanceTypes (1519.46s) --- PASS: TestAccAWSEksNodeGroup_ScalingConfig_MaxSize (1540.56s) --- PASS: TestAccAWSEksNodeGroup_DiskSize (1550.40s) --- PASS: TestAccAWSEksNodeGroup_basic (1581.83s) --- PASS: TestAccAWSEksNodeGroup_AmiType (1591.47s) --- PASS: TestAccAWSEksNodeGroup_RemoteAccess_SourceSecurityGroupIds (1602.60s) --- PASS: TestAccAWSEksNodeGroup_ScalingConfig_DesiredSize (1632.41s) --- PASS: TestAccAWSEksNodeGroup_ScalingConfig_MinSize (1683.52s) --- PASS: TestAccAWSEksNodeGroup_Tags (1712.30s) --- PASS: TestAccAWSEksNodeGroup_Labels (1765.19s) --- PASS: TestAccAWSEksNodeGroup_RemoteAccess_Ec2SshKey (1767.20s) --- PASS: TestAccAWSEksNodeGroup_ReleaseVersion (2853.92s) --- PASS: TestAccAWSEksNodeGroup_Version (3045.62s) ``` --- aws/resource_aws_eks_node_group.go | 2 +- aws/resource_aws_eks_node_group_test.go | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/aws/resource_aws_eks_node_group.go b/aws/resource_aws_eks_node_group.go index 534fe588300e..4b0becb90ce9 100644 --- a/aws/resource_aws_eks_node_group.go +++ b/aws/resource_aws_eks_node_group.go @@ -377,7 +377,7 @@ func resourceAwsEksNodeGroupUpdate(d *schema.ResourceData, meta interface{}) err NodegroupName: aws.String(nodeGroupName), } - if v, ok := d.GetOk("release_version"); ok { + if v, ok := d.GetOk("release_version"); ok && d.HasChange("release_version") { input.ReleaseVersion = aws.String(v.(string)) } diff --git a/aws/resource_aws_eks_node_group_test.go b/aws/resource_aws_eks_node_group_test.go index 9d9c18b4e9f1..3d38d87ae878 100644 --- a/aws/resource_aws_eks_node_group_test.go +++ b/aws/resource_aws_eks_node_group_test.go @@ -280,7 +280,7 @@ func TestAccAWSEksNodeGroup_ReleaseVersion(t *testing.T) { CheckDestroy: testAccCheckAWSEksNodeGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSEksNodeGroupConfigReleaseVersion(rName), + Config: testAccAWSEksNodeGroupConfigReleaseVersion(rName, "1.15"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEksNodeGroupExists(resourceName, &nodeGroup1), resource.TestCheckResourceAttrPair(resourceName, "release_version", ssmParameterDataSourceName, "value"), @@ -291,6 +291,13 @@ func TestAccAWSEksNodeGroup_ReleaseVersion(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccAWSEksNodeGroupConfigReleaseVersion(rName, "1.16"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEksNodeGroupExists(resourceName, &nodeGroup1), + resource.TestCheckResourceAttrPair(resourceName, "release_version", ssmParameterDataSourceName, "value"), + ), + }, }, }) } @@ -521,10 +528,10 @@ func TestAccAWSEksNodeGroup_Version(t *testing.T) { CheckDestroy: testAccCheckAWSEksNodeGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSEksNodeGroupConfigVersion(rName, "1.14"), + Config: testAccAWSEksNodeGroupConfigVersion(rName, "1.15"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEksNodeGroupExists(resourceName, &nodeGroup1), - resource.TestCheckResourceAttr(resourceName, "version", "1.14"), + resource.TestCheckResourceAttr(resourceName, "version", "1.15"), ), }, { @@ -532,6 +539,13 @@ func TestAccAWSEksNodeGroup_Version(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccAWSEksNodeGroupConfigVersion(rName, "1.16"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEksNodeGroupExists(resourceName, &nodeGroup1), + resource.TestCheckResourceAttr(resourceName, "version", "1.16"), + ), + }, }, }) } @@ -961,8 +975,8 @@ resource "aws_eks_node_group" "test" { `, rName, labelKey1, labelValue1, labelKey2, labelValue2) } -func testAccAWSEksNodeGroupConfigReleaseVersion(rName string) string { - return testAccAWSEksNodeGroupConfigBase(rName) + fmt.Sprintf(` +func testAccAWSEksNodeGroupConfigReleaseVersion(rName string, version string) string { + return testAccAWSEksNodeGroupConfigBaseVersion(rName, version) + fmt.Sprintf(` data "aws_ssm_parameter" "test" { name = "/aws/service/eks/optimized-ami/${aws_eks_cluster.test.version}/amazon-linux-2/recommended/release_version" } @@ -973,6 +987,7 @@ resource "aws_eks_node_group" "test" { node_role_arn = aws_iam_role.node.arn release_version = data.aws_ssm_parameter.test.value subnet_ids = aws_subnet.test[*].id + version = aws_eks_cluster.test.version scaling_config { desired_size = 1