Skip to content

Commit 5e39d23

Browse files
fix(single-onboarding): add check on root_org_unit (#54)
* add check on root_org_unit * remove redundant check * fix: single account onboard --------- Co-authored-by: Jose Pablo Camacho <jose.camacho@sysdig.com>
1 parent 5add8a7 commit 5e39d23

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

modules/agentless-scanning/locals.tf

+4-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ locals {
119119

120120
# final targets to deploy organizational resources in
121121
deployment_targets_ous = lookup(local.deployment_options, local.org_configuration, local.deployment_options.default)
122+
123+
// check if root is part of the excluded_ouids
124+
isRootExcluded = length(local.root_org_unit) > 0 ? contains(var.exclude_ouids, local.root_org_unit[0]) : false
122125
}
123126

124127
#-----------------------------------------------------------------
@@ -127,7 +130,7 @@ locals {
127130

128131
# if only exclude_ouids are provided and as long as it isn't Root OU, fetch all their child accounts to filter exclusions
129132
data "aws_organizations_organizational_unit_descendant_accounts" "ou_accounts_to_exclude" {
130-
for_each = local.org_configuration == "excluded_ous_only" && !contains(var.exclude_ouids, local.root_org_unit[0]) ? var.exclude_ouids : []
133+
for_each = local.org_configuration == "excluded_ous_only" && !local.isRootExcluded ? var.exclude_ouids : []
131134
parent_id = each.key
132135
}
133136

modules/config-posture/locals.tf

+3-2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ locals {
119119

120120
# final targets to deploy organizational resources in
121121
deployment_targets_ous = lookup(local.deployment_options, local.org_configuration, local.deployment_options.default)
122+
123+
exclude_root_ou = length(local.root_org_unit) > 0 ? contains(var.exclude_ouids, local.root_org_unit[0]) : false
122124
}
123125

124126
#-----------------------------------------------------------------
@@ -127,10 +129,9 @@ locals {
127129

128130
# if only exclude_ouids are provided and as long as it isn't Root OU, fetch all their child accounts to filter exclusions
129131
data "aws_organizations_organizational_unit_descendant_accounts" "ou_accounts_to_exclude" {
130-
for_each = local.org_configuration == "excluded_ous_only" && !contains(var.exclude_ouids, local.root_org_unit[0]) ? var.exclude_ouids : []
132+
for_each = local.org_configuration == "excluded_ous_only" && !local.exclude_root_ou ? var.exclude_ouids : []
131133
parent_id = each.key
132134
}
133-
134135
locals {
135136
# ACCOUNTS CONFIGURATION (determine user provided accounts configuration)
136137
accounts_configuration = (

modules/integrations/event-bridge/locals.tf

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ locals {
119119

120120
# final targets to deploy organizational resources in
121121
deployment_targets_ous = lookup(local.deployment_options, local.org_configuration, local.deployment_options.default)
122+
123+
exclude_root_ou = length(local.root_org_unit) > 0 ? contains(var.exclude_ouids, local.root_org_unit[0]) : false
122124
}
123125

124126
#-----------------------------------------------------------------
@@ -127,7 +129,7 @@ locals {
127129

128130
# if only exclude_ouids are provided and as long as it isn't Root OU, fetch all their child accounts to filter exclusions
129131
data "aws_organizations_organizational_unit_descendant_accounts" "ou_accounts_to_exclude" {
130-
for_each = local.org_configuration == "excluded_ous_only" && !contains(var.exclude_ouids, local.root_org_unit[0]) ? var.exclude_ouids : []
132+
for_each = local.org_configuration == "excluded_ous_only" && !local.exclude_root_ou ? var.exclude_ouids : []
131133
parent_id = each.key
132134
}
133135

modules/onboarding/locals.tf

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ locals {
119119

120120
# final targets to deploy organizational resources in
121121
deployment_targets_ous = lookup(local.deployment_options, local.org_configuration, local.deployment_options.default)
122+
123+
exclude_root_ou = length(local.root_org_unit) > 0 ? contains(var.exclude_ouids, local.root_org_unit[0]) : false
122124
}
123125

124126
#-----------------------------------------------------------------
@@ -127,7 +129,7 @@ locals {
127129

128130
# if only exclude_ouids are provided and as long as it isn't Root OU, fetch all their child accounts to filter exclusions
129131
data "aws_organizations_organizational_unit_descendant_accounts" "ou_accounts_to_exclude" {
130-
for_each = local.org_configuration == "excluded_ous_only" && !contains(var.exclude_ouids, local.root_org_unit[0]) ? var.exclude_ouids : []
132+
for_each = local.org_configuration == "excluded_ous_only" && !local.exclude_root_ou ? var.exclude_ouids : []
131133
parent_id = each.key
132134
}
133135

modules/vm-workload-scanning/locals.tf

+4-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ locals {
133133

134134
# final targets to deploy organizational resources in
135135
deployment_targets_ous = lookup(local.deployment_options, local.org_configuration, local.deployment_options.default)
136+
137+
// check if root is part of the excluded_ouids
138+
isRootExcluded = length(local.root_org_unit) > 0 ? contains(var.exclude_ouids, local.root_org_unit[0]) : false
136139
}
137140

138141
#-----------------------------------------------------------------
@@ -141,7 +144,7 @@ locals {
141144

142145
# if only exclude_ouids are provided and as long as it isn't Root OU, fetch all their child accounts to filter exclusions
143146
data "aws_organizations_organizational_unit_descendant_accounts" "ou_accounts_to_exclude" {
144-
for_each = local.org_configuration == "excluded_ous_only" && !contains(var.exclude_ouids, local.root_org_unit[0]) ? var.exclude_ouids : []
147+
for_each = local.org_configuration == "excluded_ous_only" && !local.isRootExcluded ? var.exclude_ouids : []
145148
parent_id = each.key
146149
}
147150

0 commit comments

Comments
 (0)