Azure / caf-terraform-landingzones-accelerator

Starter project for Applications (level 4) Cloud Adoption Framework for Azure landing zones on Terraform
MIT License
205 stars 233 forks source link

Error: Invalid index when deploying launchpad of version sandpit pipelines January update #29

Closed cedrox closed 3 years ago

cedrox commented 3 years ago

Describe the bug I have an error when I try to instantiate version pipelines in sandpit folder

The given key does not identify an element in this collection value.
Error on or near line 449: Error running terraform plan; exiting with status 2000

configuration/sandpit/pipelines/README-pipelines.md

step 2.1

When

To Reproduce environment=sandpit

rover -lz /tf/caf/public/landingzones/caf_launchpad \ -var-folder /tf/caf/configuration/${environment}/level0/launchpad \ -parallelism 30 \ -level level0 \ -env ${environment} \ -launchpad \ -a apply

Expected behavior Create the launchpad

Screenshots

Terraform returned errors:


Error: Invalid index

  on /home/vscode/.terraform.cache/modules/launchpad/modules/diagnostics/module.tf line 17, in resource "azurerm_monitor_diagnostic_setting" "diagnostics":
  17:   storage_account_id = each.value.destination_type == "storage" ? var.diagnostics.storage_accounts[var.diagnostics.diagnostics_destinations.storage[each.value.destination_key][var.resource_location].storage_account_key].id : null
    |----------------
    | each.value.destination_key is "all_regions"
    | var.diagnostics.diagnostics_destinations.storage is object with 1 attribute "all_regions"
    | var.resource_location is "westeurope"

The given key does not identify an element in this collection value.

Error: Invalid index

  on /home/vscode/.terraform.cache/modules/launchpad/modules/diagnostics/module.tf line 17, in resource "azurerm_monitor_diagnostic_setting" "diagnostics":
  17:   storage_account_id = each.value.destination_type == "storage" ? var.diagnostics.storage_accounts[var.diagnostics.diagnostics_destinations.storage[each.value.destination_key][var.resource_location].storage_account_key].id : null
    |----------------
    | each.value.destination_key is "all_regions"
    | var.diagnostics.diagnostics_destinations.storage is object with 1 attribute "all_regions"
    | var.resource_location is "westeurope"

The given key does not identify an element in this collection value.

Error: Invalid index

  on /home/vscode/.terraform.cache/modules/launchpad/modules/diagnostics/module.tf line 17, in resource "azurerm_monitor_diagnostic_setting" "diagnostics":
  17:   storage_account_id = each.value.destination_type == "storage" ? var.diagnostics.storage_accounts[var.diagnostics.diagnostics_destinations.storage[each.value.destination_key][var.resource_location].storage_account_key].id : null
    |----------------
    | each.value.destination_key is "all_regions"
    | var.diagnostics.diagnostics_destinations.storage is object with 1 attribute "all_regions"
    | var.resource_location is "westeurope"

The given key does not identify an element in this collection value.

Error: Invalid index

  on /home/vscode/.terraform.cache/modules/launchpad/modules/diagnostics/module.tf line 17, in resource "azurerm_monitor_diagnostic_setting" "diagnostics":
  17:   storage_account_id = each.value.destination_type == "storage" ? var.diagnostics.storage_accounts[var.diagnostics.diagnostics_destinations.storage[each.value.destination_key][var.resource_location].storage_account_key].id : null
    |----------------
    | each.value.destination_key is "all_regions"
    | var.diagnostics.diagnostics_destinations.storage is object with 1 attribute "all_regions"
    | var.resource_location is "westeurope"

The given key does not identify an element in this collection value.

Error: Invalid index

  on /home/vscode/.terraform.cache/modules/launchpad/modules/diagnostics/module.tf line 17, in resource "azurerm_monitor_diagnostic_setting" "diagnostics":
  17:   storage_account_id = each.value.destination_type == "storage" ? var.diagnostics.storage_accounts[var.diagnostics.diagnostics_destinations.storage[each.value.destination_key][var.resource_location].storage_account_key].id : null
    |----------------
    | each.value.destination_key is "all_regions"
    | var.diagnostics.diagnostics_destinations.storage is object with 1 attribute "all_regions"
    | var.resource_location is "westeurope"

The given key does not identify an element in this collection value.

Error: Invalid index

  on /home/vscode/.terraform.cache/modules/launchpad/modules/diagnostics/module.tf line 17, in resource "azurerm_monitor_diagnostic_setting" "diagnostics":
  17:   storage_account_id = each.value.destination_type == "storage" ? var.diagnostics.storage_accounts[var.diagnostics.diagnostics_destinations.storage[each.value.destination_key][var.resource_location].storage_account_key].id : null
    |----------------
    | each.value.destination_key is "all_regions"
    | var.diagnostics.diagnostics_destinations.storage is object with 1 attribute "all_regions"
    | var.resource_location is "westeurope"

The given key does not identify an element in this collection value.

Error: Invalid index

  on /home/vscode/.terraform.cache/modules/launchpad/modules/diagnostics/module.tf line 17, in resource "azurerm_monitor_diagnostic_setting" "diagnostics":
  17:   storage_account_id = each.value.destination_type == "storage" ? var.diagnostics.storage_accounts[var.diagnostics.diagnostics_destinations.storage[each.value.destination_key][var.resource_location].storage_account_key].id : null
    |----------------
    | each.value.destination_key is "all_regions"
    | var.diagnostics.diagnostics_destinations.storage is object with 1 attribute "all_regions"
    | var.resource_location is "westeurope"

The given key does not identify an element in this collection value.

Error: Invalid index

  on /home/vscode/.terraform.cache/modules/launchpad/modules/diagnostics/module.tf line 17, in resource "azurerm_monitor_diagnostic_setting" "diagnostics":
  17:   storage_account_id = each.value.destination_type == "storage" ? var.diagnostics.storage_accounts[var.diagnostics.diagnostics_destinations.storage[each.value.destination_key][var.resource_location].storage_account_key].id : null
    |----------------
    | each.value.destination_key is "all_regions"
    | var.diagnostics.diagnostics_destinations.storage is object with 1 attribute "all_regions"
    | var.resource_location is "westeurope"

The given key does not identify an element in this collection value.

Error: Invalid index

  on /home/vscode/.terraform.cache/modules/launchpad/modules/diagnostics/module.tf line 17, in resource "azurerm_monitor_diagnostic_setting" "diagnostics":
  17:   storage_account_id = each.value.destination_type == "storage" ? var.diagnostics.storage_accounts[var.diagnostics.diagnostics_destinations.storage[each.value.destination_key][var.resource_location].storage_account_key].id : null
    |----------------
    | each.value.destination_key is "all_regions"
    | var.diagnostics.diagnostics_destinations.storage is object with 1 attribute "all_regions"
    | var.resource_location is "westeurope"

The given key does not identify an element in this collection value.

Error on or near line 449: Error running terraform plan; exiting with status 2000

Environment (please complete the following information): Rover January 2021 Version of caf-terraform-landingzones-starter

Additional context Tenant with restriction

arnaudlh commented 3 years ago

hi @cedrox your problem feels like you are customizing the region in global_settings (configuration.tfvars file:

regions = {
  region1 = "westeurope"
  region2 = "northeurope"
}

but you might be missing the change the region as well in the diagnostics_destinations.tfvars

storage = {
    all_regions = {
      westeurope= {
        storage_account_key = "diagsiem_region1"
      }
      northeurope= {
        storage_account_key = "diagsiem_region2"
      }
    }
  }

let me know if thats helps

cedrox commented 3 years ago

Much better :) Thanks a lot Arnaud.