Skip to content
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

Added support for EKS control plane logging #8216

Merged
merged 7 commits into from
Apr 9, 2019
Merged

Added support for EKS control plane logging #8216

merged 7 commits into from
Apr 9, 2019

Conversation

MarcusNoble
Copy link
Contributor

@MarcusNoble MarcusNoble commented Apr 5, 2019

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Fixes #8204

Changes proposed in this pull request:

  • Add the ability to enable or disable the various logging for an EKS control plane

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccAWSEksCluster_Logging'

==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccAWSEksCluster_Logging -timeout 120m
?       github.com/terraform-providers/terraform-provider-aws   [no test files]
=== RUN   TestAccAWSEksCluster_Logging
=== PAUSE TestAccAWSEksCluster_Logging
=== CONT  TestAccAWSEksCluster_Logging
--- PASS: TestAccAWSEksCluster_Logging (1314.83s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       1315.972s

@ghost ghost added size/M Managed by automation to categorize the size of a PR. service/eks Issues and PRs that pertain to the eks service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Apr 5, 2019
@bflad bflad added the enhancement Requests to existing resources that expand the functionality or scope. label Apr 8, 2019
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @MarcusNoble 👋 Thanks for submitting this, it is off to a good start. Please see some initial feedback below and let us know if you have any questions or do not have time to complete these items.

aws/resource_aws_eks_cluster.go Outdated Show resolved Hide resolved
@@ -132,6 +142,10 @@ func resourceAwsEksClusterCreate(d *schema.ResourceData, meta interface{}) error
input.Version = aws.String(v.(string))
}

if l, ok := d.GetOk("logging"); ok && l.([]interface{}) != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this check more meaningful, it should check len(l.([]interface{})) > 0 as d.GetOk() should always return ok for root level list attributes. It'd be simpler if the logging was always set in the struct above and the expand function handled any special logic though, e.g.

	input := &eks.CreateClusterInput{
		Name:               aws.String(name),
		Logging:            expandEksLoggingTypes(d.Get("logging").([]interface{})),
		RoleArn:            aws.String(d.Get("role_arn").(string)),
		ResourcesVpcConfig: expandEksVpcConfigRequest(d.Get("vpc_config").([]interface{})),
	}
// ...
func expandEksLoggingTypes(logTypes []interface{}) *eks.Logging {
	if len(logTypes) == 0 {
		return nil
	}
	// ...

@@ -218,6 +232,14 @@ func resourceAwsEksClusterRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error setting vpc_config: %s", err)
}

types := []string{}
if len(cluster.Logging.ClusterLogging) > 0 && *cluster.Logging.ClusterLogging[0].Enabled {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before accessing anything inside cluster.Logging we should first perform a nil check to prevent potential panics. 👍

It also doesn't seem like we should always depend on a single LogSetup object that is Enabled here, even if that is how the API behaves today. We could miss results by not looping through the objects and especially if the API's first result is disabled while some of the rest may be enabled. It seems like we should check each LogSetup element then check Enabled. We then would typically suggest moving this into its own flatten function to simplify things a little.

e.g.

enabledClusterLogTypes := []string{}

if cluster.Logging != nil {
  enabledClusterLogTypes = flattenEksEnabledLogTypes(cluster.Logging.ClusterLogging)
}
// ...
func flattenEksEnabledLogTypes(logSetups []*eks.LogSetup) []interface{} {
	enabledLogTypes := []string{}

	for _, logSetup := range logSetups {
		if logSetup == nil || !aws.BoolValue(logSetup.Enabled) {
			continue
		}

		for _, logType := logSetup.Types {
			enabledLogTypes = append(enabledLogTypes, aws.BoolValue(logType))
		}
	}

	return enabledLogTypes
}

types = append(types, *logType)
}
}
d.Set("logging", types)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using d.Set() with aggregate types (TypeList, TypeSet, TypeMap), we should perform error checking to prevent issues where the code is not properly able to set the Terraform state. e.g.

Suggested change
d.Set("logging", types)
if err := d.Set("logging", enabledClusterLoggingTypes); err != nil {
return fmt.Errorf("error setting logging: %s", err)
}

@@ -114,6 +116,14 @@ func resourceAwsEksCluster() *schema.Resource {
},
},
},
"logging": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider renaming this attribute cluster_log_types or even enabled_cluster_log_types to show the designation that this handling is specifically for the Types within the ClusterLogging of the API. It also needs documentation added in website/docs/r/eks_cluster.html.markdown 👍

}

enabledLogs := &eks.LogSetup{
Enabled: &enabled,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This can be simplified to

Suggested change
Enabled: &enabled,
Enabled: aws.Bool(true),

func expandEksLoggingTypes(logTypes []interface{}) *eks.Logging {
enabled := true
disabled := false
enabledTypes := []*string{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I believe this could be simplified with expandStringList(logTypes)

@ghost ghost added size/L Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. and removed size/M Managed by automation to categorize the size of a PR. labels Apr 9, 2019
@MarcusNoble
Copy link
Contributor Author

@bflad Thank you so much for your feedback. I'm still fairly new to Go so was very helpful. I believe I've addressed all your comments now. :)

@bflad bflad self-requested a review April 9, 2019 12:08
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, @MarcusNoble! Thanks so much. 🚀

Output from acceptance testing:

--- PASS: TestAccAWSEksCluster_Logging (1210.36s)
--- PASS: TestAccAWSEksCluster_basic (1229.58s)
--- PASS: TestAccAWSEksClusterDataSource_basic (1249.35s)
--- PASS: TestAccAWSEksCluster_VpcConfig_SecurityGroupIds (1371.63s)
--- PASS: TestAccAWSEksCluster_VpcConfig_EndpointPrivateAccess (1418.73s)
--- PASS: TestAccAWSEksCluster_VpcConfig_EndpointPublicAccess (1553.32s)
--- PASS: TestAccAWSEksCluster_Version (2674.15s)

@@ -39,6 +41,8 @@ The following arguments are supported:
* `role_arn` - (Required) The Amazon Resource Name (ARN) of the IAM role that provides permissions for the Kubernetes control plane to make calls to AWS API operations on your behalf.
* `vpc_config` - (Required) Nested argument for the VPC associated with your cluster. Amazon EKS VPC resources have specific requirements to work properly with Kubernetes. For more information, see [Cluster VPC Considerations](https://docs.aws.amazon.com/eks/latest/userguide/network_reqs.html) and [Cluster Security Group Considerations](https://docs.aws.amazon.com/eks/latest/userguide/sec-group-reqs.html) in the Amazon EKS User Guide. Configuration detailed below.
* `version` – (Optional) Desired Kubernetes master version. If you do not specify a value, the latest available version at resource creation is used and no upgrades will occur except those automatically triggered by EKS. The value must be configured and increased to upgrade the version when desired. Downgrades are not supported by EKS.
* `enabled_cluster_log_types` - (Optional) A list of the desired control plane logging to enable. For more information, see [Amazon EKS Control Plane Logging
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Should be alphabetically sorted to match rest of documentation

@bflad bflad added this to the v2.6.0 milestone Apr 9, 2019
@bflad bflad merged commit 04d95fc into hashicorp:master Apr 9, 2019
bflad added a commit that referenced this pull request Apr 9, 2019
@bflad
Copy link
Contributor

bflad commented Apr 11, 2019

This has been released in version 2.6.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Mar 30, 2020

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!

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. enhancement Requests to existing resources that expand the functionality or scope. service/eks Issues and PRs that pertain to the eks service. size/L Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for eks control pane logs
2 participants