Skip to content

Commit bf5dae0

Browse files
Enable log retention for cloudwatch log groups (#387)
* enable log retention for cloudwatch log groups * revert version bump * set default retention to 90 days
1 parent 758fdab commit bf5dae0

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ project adheres to [Semantic Versioning](http://semver.org/).
1313

1414
- Added Termination Policy Option to worker ASGs (by @undeadops)
1515
- Update EBS optimized instances type (by @gloutsch)
16+
- Enable log retention for cloudwatch log groups (by @yuriipolishchuk)
17+
1618

1719
### Changed
1820

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
114114
| cluster\_endpoint\_private\_access | Indicates whether or not the Amazon EKS private API server endpoint is enabled. | string | `"false"` | no |
115115
| cluster\_endpoint\_public\_access | Indicates whether or not the Amazon EKS public API server endpoint is enabled. | string | `"true"` | no |
116116
| cluster\_iam\_role\_name | IAM role name for the cluster. Only applicable if manage_cluster_iam_resources is set to false. | string | `""` | no |
117+
| cluster\_log\_retention\_in\_days | Number of days to retain log events. Default retention - 90 days | string | `"90"` | no |
117118
| cluster\_name | Name of the EKS cluster. Also used as a prefix in names of related resources. | string | n/a | yes |
118119
| cluster\_security\_group\_id | If provided, the EKS cluster will be attached to this security group. If not given, a security group will be created with necessary ingres/egress to work with the workers and provide API access to your current IP/32. | string | `""` | no |
119120
| cluster\_version | Kubernetes version to use for the EKS cluster. | string | `"1.12"` | no |

cluster.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
resource "aws_cloudwatch_log_group" "this" {
2+
name = "/aws/eks/${var.cluster_name}/cluster"
3+
retention_in_days = "${var.cluster_log_retention_in_days}"
4+
5+
count = "${length(var.cluster_enabled_log_types) > 0 ? 1 : 0}"
6+
}
7+
18
resource "aws_eks_cluster" "this" {
29
name = "${var.cluster_name}"
310
enabled_cluster_log_types = "${var.cluster_enabled_log_types}"
@@ -19,6 +26,7 @@ resource "aws_eks_cluster" "this" {
1926
depends_on = [
2027
"aws_iam_role_policy_attachment.cluster_AmazonEKSClusterPolicy",
2128
"aws_iam_role_policy_attachment.cluster_AmazonEKSServicePolicy",
29+
"aws_cloudwatch_log_group.this",
2230
]
2331
}
2432

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ variable "cluster_enabled_log_types" {
44
type = "list"
55
}
66

7+
variable "cluster_log_retention_in_days" {
8+
default = "90"
9+
description = "Number of days to retain log events. Default retention - 90 days."
10+
}
11+
712
variable "cluster_name" {
813
description = "Name of the EKS cluster. Also used as a prefix in names of related resources."
914
}

0 commit comments

Comments
 (0)