Skip to content

Commit

Permalink
resource/aws_eks_node_group: Only pass ReleaseVersion during UpdateNo…
Browse files Browse the repository at this point in the history
…degroupVersion if changed (hashicorp#13407)

Reference: hashicorp#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)
```
  • Loading branch information
bflad authored and adamdecaf committed May 28, 2020
1 parent 8612a0b commit 56d0e45
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion aws/resource_aws_eks_node_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
25 changes: 20 additions & 5 deletions aws/resource_aws_eks_node_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
),
},
},
})
}
Expand Down Expand Up @@ -521,17 +528,24 @@ 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"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSEksNodeGroupConfigVersion(rName, "1.16"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEksNodeGroupExists(resourceName, &nodeGroup1),
resource.TestCheckResourceAttr(resourceName, "version", "1.16"),
),
},
},
})
}
Expand Down Expand Up @@ -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"
}
Expand All @@ -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
Expand Down

0 comments on commit 56d0e45

Please sign in to comment.