Azure / caf-terraform-landingzones

This solution, offered by the Open-Source community, will no longer receive contributions from Microsoft. Customers are encouraged to transition to Microsoft Azure Verified Modules for continued support and updates from Microsoft. Please note, this repository is scheduled for decommissioning and will be removed on July 1, 2025.
https://github.com/aztfmod/caf-terraform-landingzones
MIT License
761 stars 666 forks source link

Unsupported attribute and Attempt to index null value #418

Open ashishoplinux opened 2 years ago

ashishoplinux commented 2 years ago

Describe the bug Hi Team, facing error when deploying level2 single region hub. seems like a bug , I am using main branch here to deploy

Error: Unsupported attribute
│ 
│   on main.tf line 100, in locals:
│  100:     data.terraform_remote_state.remote[var.landingzone.global_settings_key].outputs.tfstates
│     ├────────────────
│     │ data.terraform_remote_state.remote is object with 1 attribute "caf_gitops"
│     │ var.landingzone.global_settings_key is "caf_gitops"
│ 
│ This object does not have an attribute named "tfstates".
╵
╷
│ Error: Attempt to index null value
│ 
│   on /home/vscode/.terraform.cache/test/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.

To Reproduce Command used -

rover -lz /tf/caf/landingzones/caf_solution -level level2 -var-folder /tf/caf/landingzones/caf_solution/scenario/networking/200-single-region-hub -env test -a plan

Please help with this concern.

Also please let us know if main branch or which branch is bug free and ready to use for customer?

YSDimov commented 1 year ago

You need to point to correct and actual state file. Default is pointing and relying to non existent to obtain regions.

For example: landingzone = { backend_type = "azurerm" global_settings_key = "caf_foundations" level = "level2" key = "networking_hub" tfstates = { caf_foundations = { level = "lower" tfstate = "caf_foundations.tfstate" } } }

Changed to:

landingzone = { backend_type = "azurerm" global_settings_key = "management" level = "level2" key = "networking_hub" tfstates = { management = { tfstate = "management.tfstate" workspace = "tfstate" level = "lower" } } }