Skip to content

Commit

Permalink
tests/resource/aws_eks_node_group: Fix version test to use version fr…
Browse files Browse the repository at this point in the history
…om aws_eks_cluster reference

The EKS Cluster would spin up with the latest Kubernetes version while the Node Group could be hardcoded multiple behind. The EKS API unfortunately does not provide a lookup API for versioning yet.

Previously:

```
Error: error creating EKS Node Group (tf-acc-test-1420558841397012520:tf-acc-test-1420558841397012520): InvalidParameterException: Nodegroup Kubernetes version should be equal to Cluster kubernetes version 1.16 or be behind be 1
```

Output from acceptance testing:

```
--- PASS: TestAccAWSEksNodeGroup_Version (1630.32s)
```
  • Loading branch information
bflad committed May 19, 2020
1 parent 586a5e0 commit 41d88be
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions aws/resource_aws_eks_node_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func testAccCheckAWSEksNodeGroupDisappears(nodeGroup *eks.Nodegroup) resource.Te
}
}

func testAccAWSEksNodeGroupConfigBase(rName string) string {
func testAccAWSEksNodeGroupConfigBaseIamAndVpc(rName string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
state = "available"
Expand Down Expand Up @@ -770,7 +770,13 @@ resource "aws_subnet" "test" {
"kubernetes.io/cluster/%[1]s" = "shared"
}
}
`, rName)
}

func testAccAWSEksNodeGroupConfigBase(rName string) string {
return composeConfig(
testAccAWSEksNodeGroupConfigBaseIamAndVpc(rName),
fmt.Sprintf(`
resource "aws_eks_cluster" "test" {
name = %[1]q
role_arn = aws_iam_role.cluster.arn
Expand All @@ -785,7 +791,29 @@ resource "aws_eks_cluster" "test" {
"aws_main_route_table_association.test",
]
}
`, rName)
`, rName))
}

func testAccAWSEksNodeGroupConfigBaseVersion(rName string, version string) string {
return composeConfig(
testAccAWSEksNodeGroupConfigBaseIamAndVpc(rName),
fmt.Sprintf(`
resource "aws_eks_cluster" "test" {
name = %[1]q
role_arn = aws_iam_role.cluster.arn
version = %[2]q
vpc_config {
subnet_ids = aws_subnet.test[*].id
}
depends_on = [
"aws_iam_role_policy_attachment.cluster-AmazonEKSClusterPolicy",
"aws_iam_role_policy_attachment.cluster-AmazonEKSServicePolicy",
"aws_main_route_table_association.test",
]
}
`, rName, version))
}

func testAccAWSEksNodeGroupConfigNodeGroupName(rName string) string {
Expand Down Expand Up @@ -1110,13 +1138,13 @@ resource "aws_eks_node_group" "test" {
}

func testAccAWSEksNodeGroupConfigVersion(rName, version string) string {
return testAccAWSEksNodeGroupConfigBase(rName) + fmt.Sprintf(`
return testAccAWSEksNodeGroupConfigBaseVersion(rName, version) + fmt.Sprintf(`
resource "aws_eks_node_group" "test" {
cluster_name = aws_eks_cluster.test.name
node_group_name = %[1]q
node_role_arn = aws_iam_role.node.arn
subnet_ids = aws_subnet.test[*].id
version = %[2]q
version = aws_eks_cluster.test.version
scaling_config {
desired_size = 1
Expand All @@ -1130,5 +1158,5 @@ resource "aws_eks_node_group" "test" {
"aws_iam_role_policy_attachment.node-AmazonEC2ContainerRegistryReadOnly",
]
}
`, rName, version)
`, rName)
}

0 comments on commit 41d88be

Please sign in to comment.