azurenoops / ref-scca-enclave-landing-zone-starter

A reference implementation of an SCCA-compliant Mission Enclave landing zone that supports running Azure PaaS services using Azure NoOps.
4 stars 7 forks source link

02-management_groups/main.tf and outputs.tf fail due to Invalid Index errors when enable_management_groups is false. #10

Closed timothymeyers closed 1 year ago

timothymeyers commented 1 year ago

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Running terraform plan results in two Invalid index errors as a result of setting enable_management_groups=false in parameters.tfvars

Any log messages given by the failure

image

Expected/desired behavior

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)

Versions

Mention any other details that might be useful

The fix is straight forward. We can use length() to check for elements and otherwise return null.

triggers = {
    "azurerm_management_group" = length(module.mod_management_group) > 0 ? jsonencode(keys(module.mod_management_group[0])) : null
  }
output "management_groups" {
  value = length(module.mod_management_group) > 0 ? module.mod_management_group[0].management_groups : null
}

Thanks! We'll be in touch soon.