Skip to content

Commit 3fa2717

Browse files
feat(onboarding): Avoid recreating stacksets when new OUs to include (#60)
1 parent 5687c3b commit 3fa2717

File tree

6 files changed

+28
-14
lines changed

6 files changed

+28
-14
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ There are four new parameters to configure organizational deployments on the clo
7575

7676
**WARNING**: module variable `organizational_unit_ids` / `org_units` will be DEPRECATED soon going forward. Please work with Sysdig to migrate your Terraform installs to use `include_ouids` instead to achieve the same deployment outcome.
7777

78+
### Stackset Instances Installation
79+
80+
If new OUs are added in the Include OUIDs list, the existing stackset instances will not get recreated and TF will only create the stackset instances for the newly added OUs.
81+
82+
**Note**: This applies to only OUs added/removed to/from the organizational configuration. If accounts are added/removed from the Exclude Accounts or Include Extra Accounts list, it will end up recreating the stackset instances.
83+
84+
<br/>
85+
7886
## Best practices
7987

8088
For contributing to existing modules or adding new modules, below are some of the best practices recommended :-

modules/agentless-scanning/organizational.tf

+6-3
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,15 @@ TEMPLATE
183183

184184
# stackset instance to deploy resources for agentless scanning, in all regions of each account in all organization units
185185
resource "aws_cloudformation_stack_set_instance" "ou_stackset_instance" {
186-
for_each = var.is_organizational ? local.region_set : toset([])
187-
region = each.key
186+
for_each = var.is_organizational ? {
187+
for pair in setproduct(local.region_set, local.deployment_targets_org_units) :
188+
"${pair[0]}-${pair[1]}" => pair
189+
} : {}
188190

191+
region = each.value[0]
189192
stack_set_name = aws_cloudformation_stack_set.ou_resources_stackset[0].name
190193
deployment_targets {
191-
organizational_unit_ids = local.deployment_targets_org_units
194+
organizational_unit_ids = [each.value[1]]
192195
accounts = local.check_old_ouid_param ? null : (local.deployment_targets_accounts_filter == "NONE" ? null : local.deployment_targets_accounts.accounts_to_deploy)
193196
account_filter_type = local.check_old_ouid_param ? null : local.deployment_targets_accounts_filter
194197
}

modules/config-posture/organizational.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ TEMPLATE
7676
}
7777

7878
resource "aws_cloudformation_stack_set_instance" "stackset_instance" {
79-
count = var.is_organizational ? 1 : 0
79+
for_each = var.is_organizational ? toset(local.deployment_targets_org_units) : []
8080

8181
region = var.region == "" ? null : var.region
8282
stack_set_name = aws_cloudformation_stack_set.stackset[0].name
8383
deployment_targets {
84-
organizational_unit_ids = local.deployment_targets_org_units
84+
organizational_unit_ids = [each.value]
8585
accounts = local.check_old_ouid_param ? null : (local.deployment_targets_accounts_filter == "NONE" ? null : local.deployment_targets_accounts.accounts_to_deploy)
8686
account_filter_type = local.check_old_ouid_param ? null : local.deployment_targets_accounts_filter
8787
}

modules/integrations/event-bridge/organizational.tf

+8-5
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ resource "aws_cloudformation_stack_set" "eb_role_stackset" {
6565
}
6666

6767
resource "aws_cloudformation_stack_set_instance" "eb_rule_api_dest_instance" {
68-
for_each = var.is_organizational ? local.region_set : toset([])
69-
region = each.key
68+
for_each = var.is_organizational ? {
69+
for pair in setproduct(local.region_set, local.deployment_targets_org_units) :
70+
"${pair[0]}-${pair[1]}" => pair
71+
} : {}
7072

73+
region = each.value[0]
7174
stack_set_name = aws_cloudformation_stack_set.eb_rule_api_dest_stackset[0].name
7275
deployment_targets {
73-
organizational_unit_ids = local.deployment_targets_org_units
76+
organizational_unit_ids = [each.value[1]]
7477
accounts = local.check_old_ouid_param ? null : (local.deployment_targets_accounts_filter == "NONE" ? null : local.deployment_targets_accounts.accounts_to_deploy)
7578
account_filter_type = local.check_old_ouid_param ? null : local.deployment_targets_accounts_filter
7679
}
@@ -89,11 +92,11 @@ resource "aws_cloudformation_stack_set_instance" "eb_rule_api_dest_instance" {
8992
}
9093

9194
resource "aws_cloudformation_stack_set_instance" "eb_role_stackset_instance" {
92-
count = var.is_organizational ? 1 : 0
95+
for_each = var.is_organizational ? toset(local.deployment_targets_org_units) : []
9396

9497
stack_set_name = aws_cloudformation_stack_set.eb_role_stackset[0].name
9598
deployment_targets {
96-
organizational_unit_ids = local.deployment_targets_org_units
99+
organizational_unit_ids = [each.value]
97100
accounts = local.check_old_ouid_param ? null : (local.deployment_targets_accounts_filter == "NONE" ? null : local.deployment_targets_accounts.accounts_to_deploy)
98101
account_filter_type = local.check_old_ouid_param ? null : local.deployment_targets_accounts_filter
99102
}

modules/onboarding/organizational.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ TEMPLATE
5454
}
5555

5656
resource "aws_cloudformation_stack_set_instance" "stackset_instance" {
57-
count = var.is_organizational ? 1 : 0
57+
for_each = var.is_organizational ? toset(local.deployment_targets_org_units) : []
5858

5959
region = var.region == "" ? null : var.region
6060
stack_set_name = aws_cloudformation_stack_set.stackset[0].name
6161
deployment_targets {
62-
organizational_unit_ids = local.deployment_targets_org_units
62+
organizational_unit_ids = [each.value]
6363
accounts = local.check_old_ouid_param ? null : (local.deployment_targets_accounts_filter == "NONE" ? null : local.deployment_targets_accounts.accounts_to_deploy)
6464
account_filter_type = local.check_old_ouid_param ? null : local.deployment_targets_accounts_filter
6565
}

modules/vm-workload-scanning/organizational.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ resource "aws_cloudformation_stack_set" "scanning_role_stackset" {
120120

121121
# stackset instance to deploy agentless scanning role, in all organization units
122122
resource "aws_cloudformation_stack_set_instance" "scanning_role_stackset_instance" {
123-
count = var.is_organizational ? 1 : 0
123+
for_each = var.is_organizational ? toset(local.deployment_targets_org_units) : []
124124

125125
stack_set_name = aws_cloudformation_stack_set.scanning_role_stackset[0].name
126126
deployment_targets {
127-
organizational_unit_ids = local.deployment_targets_org_units
127+
organizational_unit_ids = [each.value]
128128
accounts = local.check_old_ouid_param ? null : (local.deployment_targets_accounts_filter == "NONE" ? null : local.deployment_targets_accounts.accounts_to_deploy)
129129
account_filter_type = local.check_old_ouid_param ? null : local.deployment_targets_accounts_filter
130130
}

0 commit comments

Comments
 (0)