-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Support EKS cluster private access #8024
Conversation
Updated via: go get github.com/aws/aws-sdk-go@v1.18.5 go mod tidy go mod vendor
@ewbankkit would you prefer a review or me to add the required testing and data source changes in a separate commit after yours? Already have them written. |
@bflad I'll keep going as long as I can keep focus on this, if that's OK. |
aws/data_source_aws_eks_cluster.go
Outdated
@@ -70,6 +70,14 @@ func dataSourceAwsEksCluster() *schema.Resource { | |||
Computed: true, | |||
Elem: &schema.Schema{Type: schema.TypeString}, | |||
}, | |||
"endpoint_private_access": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add acceptance testing for these two attributes, e.g.
resource.TestCheckResourceAttrPair(resourceName, "vpc_config.0.endpoint_private_access", dataSourceResourceName, "vpc_config.0.endpoint_private_access"),
resource.TestCheckResourceAttrPair(resourceName, "vpc_config.0.endpoint_public_access", dataSourceResourceName, "vpc_config.0.endpoint_public_access"),
Nit: Attribute alphabetical ordering
aws/resource_aws_eks_cluster.go
Outdated
@@ -98,6 +97,16 @@ func resourceAwsEksCluster() *schema.Resource { | |||
MinItems: 1, | |||
Elem: &schema.Schema{Type: schema.TypeString}, | |||
}, | |||
"endpoint_private_access": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add acceptance testing for these new arguments. Example below should get you close.
Nit: Attribute alphabetical ordering
func TestAccAWSEksCluster_VpcConfig_EndpointPrivateAccess(t *testing.T) {
var cluster1, cluster2, cluster3 eks.Cluster
rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))
resourceName := "aws_eks_cluster.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEksClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEksClusterConfig_VpcConfig_EndpointPrivateAccess(rName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEksClusterExists(resourceName, &cluster1),
resource.TestCheckResourceAttr(resourceName, "vpc.config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vpc.config.0.endpoint_private_access", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSEksClusterConfig_VpcConfig_EndpointPrivateAccess(rName, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEksClusterExists(resourceName, &cluster2),
testAccCheckAWSEksClusterNotRecreated(&cluster1, &cluster2),
resource.TestCheckResourceAttr(resourceName, "vpc.config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vpc.config.0.endpoint_private_access", "false"),
),
},
{
Config: testAccAWSEksClusterConfig_VpcConfig_EndpointPrivateAccess(rName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEksClusterExists(resourceName, &cluster3),
testAccCheckAWSEksClusterNotRecreated(&cluster2, &cluster3),
resource.TestCheckResourceAttr(resourceName, "vpc.config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vpc.config.0.endpoint_private_access", "true"),
),
},
},
})
}
func TestAccAWSEksCluster_VpcConfig_EndpointPublicAccess(t *testing.T) {
var cluster1, cluster2, cluster3 eks.Cluster
rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))
resourceName := "aws_eks_cluster.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEksClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEksClusterConfig_VpcConfig_EndpointPublicAccess(rName, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEksClusterExists(resourceName, &cluster1),
resource.TestCheckResourceAttr(resourceName, "vpc.config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vpc.config.0.endpoint_public_access", "false"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSEksClusterConfig_VpcConfig_EndpointPublicAccess(rName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEksClusterExists(resourceName, &cluster2),
testAccCheckAWSEksClusterNotRecreated(&cluster1, &cluster2),
resource.TestCheckResourceAttr(resourceName, "vpc.config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vpc.config.0.endpoint_public_access", "true"),
),
},
{
Config: testAccAWSEksClusterConfig_VpcConfig_EndpointPublicAccess(rName, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEksClusterExists(resourceName, &cluster3),
testAccCheckAWSEksClusterNotRecreated(&cluster2, &cluster3),
resource.TestCheckResourceAttr(resourceName, "vpc.config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vpc.config.0.endpoint_public_access", "false"),
),
},
},
})
}
func testAccAWSEksClusterConfig_VpcConfig_EndpointPrivateAccess(rName string, endpointPrivateAccess bool) string {
return fmt.Sprintf(`
%[1]s
resource "aws_eks_cluster" "test" {
name = %[2]q
role_arn = "${aws_iam_role.test.arn}"
vpc_config {
endpoint_private_access = %[3]t
endpoint_public_access = true
subnet_ids = ["${aws_subnet.test.*.id[0]}", "${aws_subnet.test.*.id[1]}"]
}
depends_on = ["aws_iam_role_policy_attachment.test-AmazonEKSClusterPolicy", "aws_iam_role_policy_attachment.test-AmazonEKSServicePolicy"]
}
`, testAccAWSEksClusterConfig_Base(rName), rName, endpointPrivateAccess)
}
func testAccAWSEksClusterConfig_VpcConfig_EndpointPublicAccess(rName string, endpointPublicAccess bool) string {
return fmt.Sprintf(`
%[1]s
resource "aws_eks_cluster" "test" {
name = %[2]q
role_arn = "${aws_iam_role.test.arn}"
vpc_config {
endpoint_private_access = true
endpoint_public_access = %[3]t
subnet_ids = ["${aws_subnet.test.*.id[0]}", "${aws_subnet.test.*.id[1]}"]
}
depends_on = ["aws_iam_role_policy_attachment.test-AmazonEKSClusterPolicy", "aws_iam_role_policy_attachment.test-AmazonEKSServicePolicy"]
}
`, testAccAWSEksClusterConfig_Base(rName), rName, endpointPublicAccess)
}
aws/resource_aws_eks_cluster.go
Outdated
"security_group_ids": schema.NewSet(schema.HashString, flattenStringList(vpcConfig.SecurityGroupIds)), | ||
"subnet_ids": schema.NewSet(schema.HashString, flattenStringList(vpcConfig.SubnetIds)), | ||
"vpc_id": aws.StringValue(vpcConfig.VpcId), | ||
"endpoint_private_access": aws.BoolValue(vpcConfig.EndpointPrivateAccess), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Struct alphabetical ordering
aws/resource_aws_eks_cluster_test.go
Outdated
@@ -97,6 +97,8 @@ func TestAccAWSEksCluster_basic(t *testing.T) { | |||
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.security_group_ids.#", "0"), | |||
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.subnet_ids.#", "2"), | |||
resource.TestMatchResourceAttr(resourceName, "vpc_config.0.vpc_id", regexp.MustCompile(`^vpc-.+`)), | |||
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.endpoint_private_access", "false"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Attribute alphabetical ordering
Add private access support to aws_eks_cluster data source. Add 'expandEksVpcConfigUpdateRequest'. - Additional aws_eks_cluster resource acceptance tests from @bflad. - Changes after initial review: - Attribute alphabetical ordering - Note on resource 'update' timeout
Initial review issues addressed and additional acceptance tests added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ewbankkit! 🚀
Output from acceptance testing:
--- PASS: TestAccAWSEksClusterDataSource_basic (1320.87s)
--- PASS: TestAccAWSEksCluster_basic (1295.89s)
--- PASS: TestAccAWSEksCluster_VpcConfig_SecurityGroupIds (1327.26s)
--- PASS: TestAccAWSEksCluster_VpcConfig_EndpointPrivateAccess (1490.80s)
--- PASS: TestAccAWSEksCluster_VpcConfig_EndpointPublicAccess (1526.63s)
--- PASS: TestAccAWSEksCluster_Version (2552.56s)
} | ||
} | ||
|
||
if d.HasChange("vpc_config") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this is not acting like it seems it should, be needed to change this to check the nested attributes. 🙁
if d.HasChange("vpc_config.0.endpoint_private_access") || d.HasChange("vpc_config.0.endpoint_public_access") {
Previous output from acceptance testing:
--- FAIL: TestAccAWSEksCluster_Version (2519.24s)
testing.go:538: Step 2 error: Error applying: 1 error occurred:
* aws_eks_cluster.test: 1 error occurred:
* aws_eks_cluster.test: error updating EKS Cluster (tf-acc-test-zdu6h) config: InvalidParameterException: Cluster is already at the desired configuration with endpointPrivateAccess: false and endpointPublicAccess: true
Even though the acceptance test debug logs were correctly only showing:
UPDATE: aws_eks_cluster.test
version: "1.10" => "1.11"
Output from acceptance testing:
--- PASS: TestAccAWSEksClusterDataSource_basic (1320.87s)
--- PASS: TestAccAWSEksCluster_basic (1295.89s)
--- PASS: TestAccAWSEksCluster_VpcConfig_SecurityGroupIds (1327.26s)
--- PASS: TestAccAWSEksCluster_VpcConfig_EndpointPrivateAccess (1490.80s)
--- PASS: TestAccAWSEksCluster_VpcConfig_EndpointPublicAccess (1526.63s)
--- PASS: TestAccAWSEksCluster_Version (2552.56s)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a schema.TypeList
vs. schema.TypeSet
thing for the vpc_config
attribute maybe?
This has been released in version 2.3.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Community Note
Fixes #8022.
WIP as I need this for evaluation; Happy to close if there's a more official PR coming otherwise I will continue to work on this.
Includes AWS SDK update from #8021.
Right now only the public/private access flags can be updated in
vpc_config
although the API suggests that security groups and subnets can be updated in future.Related:
TODO
aws_eks_cluster
data sourceAcceptance tests so far: