Skip to content

Commit c0bdf5a

Browse files
committed
feat: change variables shape, add validations
1 parent b8cd6a5 commit c0bdf5a

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ resource "aws_guardduty_detector" "primary" {
4949
resource "aws_guardduty_detector_feature" "this" {
5050
for_each = var.configuration_features
5151
detector_id = aws_guardduty_detector.primary.id
52-
name = each.name
53-
status = each.status ? "ENABLED" : "DISABLED"
52+
name = each.key
53+
status = each.enabled ? "ENABLED" : "DISABLED"
5454

5555
dynamic "additional_configuration" {
5656
for_each = each.additional_configuration
5757
content {
58-
name = additional_configuration.name
59-
status = each.status ? "ENABLED" : "DISABLED"
58+
name = additional_configuration.key
59+
status = each.enabled ? "ENABLED" : "DISABLED"
6060
}
6161
}
6262
}

modules/organizations_admin/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ resource "aws_guardduty_organization_configuration" "this" {
3838
resource "aws_guardduty_organization_configuration_feature" "this" {
3939
for_each = var.organization_configuration_features
4040
detector_id = var.guardduty_detector_id
41-
name = each.name
41+
name = each.key
4242
auto_enable = each.auto_enable
4343

4444
dynamic "additional_configuration" {
4545
for_each = each.additional_configuration
4646
content {
47-
name = additional_configuration.name
47+
name = additional_configuration.key
4848
auto_enable = additional_configuration.auto_enable
4949
}
5050
}

modules/organizations_admin/variables.tf

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,28 @@ variable "auto_enable_organization_members" {
4343
}
4444

4545
variable "organization_configuration_features" {
46+
description = "Enable new organization GuardDuty protections only available as features"
4647
type = map(object({
47-
name = string
48-
auto_enable = string # NEW | ALL | NONE
49-
additional_configuration = list(object({
50-
name = string # EKS_ADDON_MANAGEMENT | ECS_FARGATE_AGENT_MANAGEMENT | EC2_AGENT_MANAGEMENT
48+
auto_enable = string
49+
additional_configuration = map(object({
5150
auto_enable = string
5251
}))
5352
}))
54-
}
53+
validation {
54+
condition = alltrue([for k in var.organization_configuration_features : contains(["S3_DATA_EVENTS", "EKS_AUDIT_LOGS", "EBS_MALWARE_PROTECTION", "RDS_LOGIN_EVENTS", "EKS_RUNTIME_MONITORING", "LAMBDA_NETWORK_LOGS", "RUNTIME_MONITORING"], k)])
55+
error_message = "The organization_configuration_features key must be one of: S3_DATA_EVENTS, EKS_AUDIT_LOGS, EBS_MALWARE_PROTECTION, RDS_LOGIN_EVENTS, EKS_RUNTIME_MONITORING, LAMBDA_NETWORK_LOGS, RUNTIME_MONITORING."
56+
}
57+
validation {
58+
condition = alltrue([for k, v in var.organization_configuration_features : contains(["ALL", "NONE", "NEW"], v.auto_enable)])
59+
error_message = "The auto_enable value must be one of: ALL, NONE, NEW."
60+
}
61+
validation {
62+
condition = alltrue([for k, v in var.organization_configuration_features : [for a in v.additional_configuration : contains(["EKS_ADDON_MANAGEMENT", "ECS_FARGATE_AGENT_MANAGEMENT", "EC2_AGENT_MANAGEMENT"], a)]])
63+
error_message = "The additional_configuration key must be one of: EKS_ADDON_MANAGEMENT, ECS_FARGATE_AGENT_MANAGEMENT, EC2_AGENT_MANAGEMENT."
64+
}
65+
validation {
66+
condition = alltrue([for k, v in var.organization_configuration_features : [for a in v.additional_configuration : contains(["ALL", "NONE", "NEW"], a.auto_enable)]])
67+
error_message = "The auto_enable value must be one of: ALL, NONE, NEW."
68+
}
69+
default = {}
70+
}

variables.tf

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ variable "finding_publishing_frequency" {
4646
variable "configuration_features" {
4747
description = "Enable new GuardDuty protections only available as features"
4848
type = map(object({
49-
name = string # S3_DATA_EVENTS | EKS_AUDIT_LOGS | EBS_MALWARE_PROTECTION | RDS_LOGIN_EVENTS | EKS_RUNTIME_MONITORING | LAMBDA_NETWORK_LOGS | RUNTIME_MONITORING
50-
enable = bool
51-
additional_configuration = list(object({ # EKS_ADDON_MANAGEMENT | ECS_FARGATE_AGENT_MANAGEMENT | EC2_AGENT_MANAGEMENT
52-
name = string
53-
enable = bool
54-
}))
49+
enabled = bool
50+
additional_configuration = map(bool)
5551
}))
52+
validation {
53+
condition = alltrue([for k in var.configuration_features : contains(["S3_DATA_EVENTS", "EKS_AUDIT_LOGS", "EBS_MALWARE_PROTECTION", "RDS_LOGIN_EVENTS", "EKS_RUNTIME_MONITORING", "LAMBDA_NETWORK_LOGS", "RUNTIME_MONITORING"], k)])
54+
error_message = "The configuration_features key must be one of: S3_DATA_EVENTS, EKS_AUDIT_LOGS, EBS_MALWARE_PROTECTION, RDS_LOGIN_EVENTS, EKS_RUNTIME_MONITORING, LAMBDA_NETWORK_LOGS, RUNTIME_MONITORING."
55+
}
56+
validation {
57+
condition = alltrue([for k, v in var.configuration_features : [for a in v.additional_configuration : contains(["EKS_ADDON_MANAGEMENT", "ECS_FARGATE_AGENT_MANAGEMENT", "EC2_AGENT_MANAGEMENT"], a)]])
58+
error_message = "The additional_configuration key must be one of: EKS_ADDON_MANAGEMENT, ECS_FARGATE_AGENT_MANAGEMENT, EC2_AGENT_MANAGEMENT."
59+
}
5660
default = {}
5761
}
5862

0 commit comments

Comments
 (0)