Skip to content

Commit

Permalink
fix(event-hub): do not try to access root mgmt group in non-org mode …
Browse files Browse the repository at this point in the history
…(SSPROD-36994) (#30)

The change in #27 fixes the onboarding of the organizational mode
but introduces a regression when onboarding a single subscription:

```
Error: Invalid index

  on .terraform/modules/single-subscription-threat-detection/modules/services/event-hub-data-source/organizational.tf line 14, in locals:
  14:   selected_management_group = length(data.azurerm_management_group.onboarded_management_group) > 0 ? values(data.azurerm_management_group.onboarded_management_group) : [data.azurerm_management_group.root_management_group[0]]
    ├────────────────
    │ data.azurerm_management_group.root_management_group is empty tuple
```

Avoiding to access the undefined `root_management_group` if
`is_organizational` is false fixes the issue.

This was caught by the automated daily regression tests and the fix has
been confirmed by testing manually modifying the `source` on `main.tf`
to point to my local `terraform-azurerm-secure` repo.
  • Loading branch information
jacalvo authored Feb 5, 2024
1 parent d58be63 commit 0373d2d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion modules/services/event-hub-data-source/organizational.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data "azurerm_management_group" "root_management_group" {
}

locals {
selected_management_group = length(data.azurerm_management_group.onboarded_management_group) > 0 ? values(data.azurerm_management_group.onboarded_management_group) : [data.azurerm_management_group.root_management_group[0]]
selected_management_group = var.is_organizational ? (length(data.azurerm_management_group.onboarded_management_group) > 0 ? values(data.azurerm_management_group.onboarded_management_group) : [data.azurerm_management_group.root_management_group[0]]) : []
all_mg_subscription_ids = flatten([
for mg in local.selected_management_group : mg.all_subscription_ids
])
Expand Down

0 comments on commit 0373d2d

Please sign in to comment.