Skip to content

feat(onboarding): Avoid recreating stacksets when new OUs to include #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ There are four new parameters to configure organizational deployments on the clo

**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.

### Stackset Instances Installation

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.

**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.

<br/>

## Best practices

For contributing to existing modules or adding new modules, below are some of the best practices recommended :-
Expand Down
9 changes: 6 additions & 3 deletions modules/agentless-scanning/organizational.tf
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,15 @@ TEMPLATE

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

region = each.value[0]
stack_set_name = aws_cloudformation_stack_set.ou_resources_stackset[0].name
deployment_targets {
organizational_unit_ids = local.deployment_targets_org_units
organizational_unit_ids = [each.value[1]]
accounts = local.check_old_ouid_param ? null : (local.deployment_targets_accounts_filter == "NONE" ? null : local.deployment_targets_accounts.accounts_to_deploy)
account_filter_type = local.check_old_ouid_param ? null : local.deployment_targets_accounts_filter
}
Expand Down
4 changes: 2 additions & 2 deletions modules/config-posture/organizational.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ TEMPLATE
}

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

region = var.region == "" ? null : var.region
stack_set_name = aws_cloudformation_stack_set.stackset[0].name
deployment_targets {
organizational_unit_ids = local.deployment_targets_org_units
organizational_unit_ids = [each.value]
accounts = local.check_old_ouid_param ? null : (local.deployment_targets_accounts_filter == "NONE" ? null : local.deployment_targets_accounts.accounts_to_deploy)
account_filter_type = local.check_old_ouid_param ? null : local.deployment_targets_accounts_filter
}
Expand Down
13 changes: 8 additions & 5 deletions modules/integrations/event-bridge/organizational.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ resource "aws_cloudformation_stack_set" "eb_role_stackset" {
}

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

region = each.value[0]
stack_set_name = aws_cloudformation_stack_set.eb_rule_api_dest_stackset[0].name
deployment_targets {
organizational_unit_ids = local.deployment_targets_org_units
organizational_unit_ids = [each.value[1]]
accounts = local.check_old_ouid_param ? null : (local.deployment_targets_accounts_filter == "NONE" ? null : local.deployment_targets_accounts.accounts_to_deploy)
account_filter_type = local.check_old_ouid_param ? null : local.deployment_targets_accounts_filter
}
Expand All @@ -89,11 +92,11 @@ resource "aws_cloudformation_stack_set_instance" "eb_rule_api_dest_instance" {
}

resource "aws_cloudformation_stack_set_instance" "eb_role_stackset_instance" {
count = var.is_organizational ? 1 : 0
for_each = var.is_organizational ? toset(local.deployment_targets_org_units) : []

stack_set_name = aws_cloudformation_stack_set.eb_role_stackset[0].name
deployment_targets {
organizational_unit_ids = local.deployment_targets_org_units
organizational_unit_ids = [each.value]
accounts = local.check_old_ouid_param ? null : (local.deployment_targets_accounts_filter == "NONE" ? null : local.deployment_targets_accounts.accounts_to_deploy)
account_filter_type = local.check_old_ouid_param ? null : local.deployment_targets_accounts_filter
}
Expand Down
4 changes: 2 additions & 2 deletions modules/onboarding/organizational.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ TEMPLATE
}

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

region = var.region == "" ? null : var.region
stack_set_name = aws_cloudformation_stack_set.stackset[0].name
deployment_targets {
organizational_unit_ids = local.deployment_targets_org_units
organizational_unit_ids = [each.value]
accounts = local.check_old_ouid_param ? null : (local.deployment_targets_accounts_filter == "NONE" ? null : local.deployment_targets_accounts.accounts_to_deploy)
account_filter_type = local.check_old_ouid_param ? null : local.deployment_targets_accounts_filter
}
Expand Down
4 changes: 2 additions & 2 deletions modules/vm-workload-scanning/organizational.tf
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ resource "aws_cloudformation_stack_set" "scanning_role_stackset" {

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

stack_set_name = aws_cloudformation_stack_set.scanning_role_stackset[0].name
deployment_targets {
organizational_unit_ids = local.deployment_targets_org_units
organizational_unit_ids = [each.value]
accounts = local.check_old_ouid_param ? null : (local.deployment_targets_accounts_filter == "NONE" ? null : local.deployment_targets_accounts.accounts_to_deploy)
account_filter_type = local.check_old_ouid_param ? null : local.deployment_targets_accounts_filter
}
Expand Down