Skip to content

Commit

Permalink
Merge pull request #4 from venkyio/main
Browse files Browse the repository at this point in the history
add exclude rule packs

Sorry for the long delay, thanks for the PR!
  • Loading branch information
grothja authored Jan 23, 2022
2 parents 610bc07 + d69c2c9 commit b23355d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
8 changes: 7 additions & 1 deletion examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ module "managed_rules" {
"Operational-Best-Practices-for-NIST-800-53-rev-4",
]

rule_packs_to_exclude = [
"Operational-Best-Practices-for-CIS-AWS-v1.4-Level1",
"Operational-Best-Practices-for-CIS-AWS-v1.4-Level2",
]


# Extra rules not included in the Packs you want to deploy
rules_to_include = [
"dax-encryption-enabled",
Expand All @@ -35,4 +41,4 @@ module "managed_rules" {
}
}
}
}
}
18 changes: 17 additions & 1 deletion locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ locals {
local.pack_file["packs"][pack]
]

rule_packs_to_exclude = [
for pack in var.rule_packs_to_exclude :
local.pack_file["packs"][pack]
]

rules_collected = sort(
distinct(
flatten(
Expand All @@ -17,9 +22,20 @@ locals {
)
)

rules_exclude_collected = sort(
distinct(
flatten(
concat(
var.rules_to_exclude,
local.rule_packs_to_exclude
)
)
)
)

final_rules = [
for rule in local.rules_collected :
rule if !contains(var.rules_to_exclude, rule)
rule if !contains(local.rules_exclude_collected, rule)
]

final_managed_rules = merge(local.managed_rules, var.rule_overrides)
Expand Down
9 changes: 9 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ variable "rule_packs" {
type = list(string)
}

# In cases where rules from other packs overlap and let's say we want to exclude all overlap rules from a pack..
# this feature should address that. Example use case is where securityhub deploys CIS Level1 and 2 Rules and
# lets say we want to exclude all these rules from NIST pack
variable "rule_packs_to_exclude" {
description = "A list of Rule Packs (based off AWS Conformance Packs) from which overlap rules to exclude"
default = []
type = list(string)
}

variable "rules_to_exclude" {
description = "A list of individual AWS-managed Config Rules to exclude from deployment"
default = []
Expand Down

0 comments on commit b23355d

Please sign in to comment.