Azure / caf-terraform-landingzones

Azure Terraform SRE framework

Home Page:https://aka.ms/azure-terraform-sre

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[bug] Global settings not recognised

darrenhull opened this issue · comments

Am I doing something really silly?

When adding a resource group at level 3 the global settings are not recognised. If I create a landing zone the plan creates the correct output. However, if I then add a resource group I get the following error:

on /home/vscode/.terraform.cache/ABC/modules/solution/modules/resource_group/module.tf line 15, in resource "azurerm_resource_group" "rg":
│ 15: location = var.global_settings.regions[lookup(var.settings, "region", var.global_settings.default_region)]
│ ├────────────────
│ │ var.global_settings.default_region is "region1"
│ │ var.global_settings.regions is null
│ │ var.settings is object with 2 attributes

To Reproduce
Steps to reproduce the behavior:
create a configuration file with the following in:

landingzone = {
  backend_type        = "azurerm"
  level               = "level2"
  key                 = "caf_connectivity"
  global_settings_key = "launchpad"
  tfstates = {
    launchpad = {
      tfstate = "caf_enterprise_scale.tfstate"
      level   = "lower"
    }
  }
}


global_settings = {
  description = "Global settings object for the current deployment."
  default = {
    passthrough    = false
    random_length  = 3
    default_region = "region1"
    regions = {
      region1 = "uksouth"
      region2 = "ukwest"
    }
  }
}

# resource_groups = {
#   vnet_hub_region1 = {
#     name = "vnet-hub-re1",
#         tags = {
#       level = "connectivity"
#     }
#   }
#   vnet_spoke_region1 = {
#     name = "vnet-spoke-re1",
#     tags = {
#       level = "connectivity"
#     }
#   }
# }

Run the command:

rover -lz /tf/caf/landingzones/caf_solution/ -var-folder /tf/caf/platform/demo/level_2/connectivity -tfstate caf_connectivity.tfstate -env ABC -level level2 -log-severity ERROR -p ${TF_DATA_DIR}/caf_connectivity.tfstate.tfplan -a plan

the output is the expected plan:

` # module.solution.random_string.prefix[0] will be created

  • resource "random_string" "prefix" {
    • id = (known after apply)
    • length = 4
    • lower = true
    • min_lower = 0
    • min_numeric = 0
    • min_special = 0
    • min_upper = 0
    • number = (known after apply)
    • numeric = false
    • result = (known after apply)
    • special = false
    • upper = false
      }

Plan: 1 to add, 0 to change, 0 to destroy.

Changes to Outputs:

  • connectivity_subscription_id = "*****"
  • connectivity_tenant_id = "*****"
  • custom_variables = {}
  • diagnostics = (sensitive value)
  • global_settings = {
    • default = {
      • default_region = "region1"
      • passthrough = false
      • random_length = 3
      • regions = {
        • region1 = "uksouth"
        • region2 = "ukwest"
          }
          }
    • description = "Global settings object for the current deployment."
      }
  • launchpad_identities = (sensitive value)
  • objects = (sensitive value)
  • tfstates = (sensitive value)`

now uncomment the resource groups and rerun, the following error is shown:

│ Error: Attempt to index null value │ │ on /home/vscode/.terraform.cache/ABC/modules/solution/modules/resource_group/module.tf line 15, in resource "azurerm_resource_group" "rg": │ 15: location = var.global_settings.regions[lookup(var.settings, "region", var.global_settings.default_region)] │ ├──────────────── │ │ var.global_settings.default_region is "region1" │ │ var.global_settings.regions is null │ │ var.settings is object with 2 attributes │ │ This value is null, so it does not have any indices.

Configuration (please complete the following information):

  • OS and version: [e.g. Windows 10 19045]
  • Version of the rover aztfmod/rover:1.5.4-2307.2804
  • Version of the landing zone 5.7.2

Additional context
Add any other context about the problem here.

Any suggestions on this would be really appreciated.

Hi, I believe It should be launchpad.tfstate instead of caf_enterprise_scale.tfstate

so I have updated my landingzone to this:

landingzone = {
backend_type = "azurerm"
level = "level2"
key = "caf_connectivity"
global_settings_key = "caf_enterprise_scale"
tfstates = {
caf_enterprise_scale = {
level = "lower"
tfstate = "caf_enterprise_scale.tfstate"
}
}
}

and I still get the same error.

my level 1 landingzone is as follows:
#this file is not needed because it is automatically created but is here to show consistency.

landingzone = {
backend_type = "azurerm"
level = "level1"
key = "caf_enterprise_scale"
global_settings_key = "launchpad"
tfstates = {
launchpad = {
level = "lower"
tfstate = "caf_launchpad.tfstate"
}
}
}

I have resolved this issue now. I had not ran the foundations passthrough 100. if i create that at level 1 and then use that as the lower level for level 2 then it works. However, if you just run the caf_eslz add-ons then it doestnt work.

I think either way the documentation is pretty outdated and needs making clear. The readme's are very out dated.