aztfmod / terraform-azurerm-caf

Terraform supermodule for the Terraform platform engineering for Azure
https://aztfmod.github.io/documentation/
MIT License
537 stars 689 forks source link

Error in VM_extensions { microsoft_enterprise_cloud_monitoring } #911

Open asolomchuk opened 2 years ago

asolomchuk commented 2 years ago

Getting error when creating VM with the following extension:

virtual_machine_extensions = { microsoft_enterprise_cloud_monitoring = { diagnostic_log_analytics_key = "central_workspace" } }

Tried both ways of LogAnalytics creation , the errors are same. 1)

diagnostic_log_analytics = { central_workspace = { region = "region1" name = "TEST-diag-la" resource_group_key = "rg" } }

2) log_analytics = { central_workspace = { name = "TEST2-la" resource_group_key = "rg" sku = "PerGB2018" retention_in_days = 31 } } ___ ERROR ____ Getting the following error , looks like var.settings.diagnostics.log_analytics doen't get the info about created LA. Does somebody has succeeded inn deploying 'microsoft_enterprise_cloud_monitoring ' ?

Error: Invalid index │ │ on /home/vscode/.terraform.cache/modules/vm_extension_monitoring_agent/modules/compute/virtual_machine_extensions/Microsoft.EnterpriseCloud.Monitoring.tf line 45, in data "external" "monitoring_workspace_key": │ 45: var.settings.diagnostics.log_analytics[var.extension.diagnostic_log_analytics_key].name, │ ├──────────────── │ │ var.extension.diagnostic_log_analytics_key is "central_workspace" │ │ var.settings.diagnostics.log_analytics is object with no attributes │ │ The given key does not identify an element in this collection value. ╵ ╷ │ Error: Invalid index │ │ on /home/vscode/.terraform.cache/modules/vm_extension_monitoring_agent/modules/compute/virtual_machine_extensions/Microsoft.EnterpriseCloud.Monitoring.tf line 46, in data "external" "monitoring_workspace_key": │ 46: var.settings.diagnostics.log_analytics[var.extension.diagnostic_log_analytics_key].resource_group_name, │ ├──────────────── │ │ var.extension.diagnostic_log_analytics_key is "central_workspace" │ │ var.settings.diagnostics.log_analytics is object with no attributes │ │ The given key does not identify an element in this collection value. ╵ ╷ │ Error: Invalid index │ │ on /home/vscode/.terraform.cache/modules/vm_extension_monitoring_agent/modules/compute/virtual_machine_extensions/Microsoft.EnterpriseCloud.Monitoring.tf line 47, in data "external" "monitoring_workspace_key": │ 47: substr(var.settings.diagnostics.log_analytics[var.extension.diagnostic_log_analytics_key].id, 15, 36) │ ├──────────────── │ │ var.extension.diagnostic_log_analytics_key is "central_workspace" │ │ var.settings.diagnostics.log_analytics is object with no attributes │ │ The given key does not identify an element in this collection value.

arnaudlh commented 2 years ago

hi @asolomchuk - Did you have a chance to try out example 211-vm-bastion-winrm-agents here: https://github.com/aztfmod/terraform-azurerm-caf/tree/master/examples/compute/virtual_machine/211-vm-bastion-winrm-agents.

You can launch it via baremetal Terraform or via rover examples:

rover -lz /tf/caf/examples \
-var-folder /tf/caf/examples/compute/virtual_machine/211-vm-bastion-winrm-agents \
-var var_folder_path=/tf/caf/examples/compute/virtual_machine/211-vm-bastion-winrm-agents \
-level level1 \
-env contoso-sandpit \
-tfstate 211-vm-bastion-winrm-agents.tfstate \
-a apply 
asolomchuk commented 2 years ago

Hello @arnaudlh , I copied the folder with example /211-vm-bastion-winrm-agents , into our repo and deployed with latest logic and solution master branches from github. In the result I got the same errors plus more several similar for storage account (it was expected as, before I just didn't use the part with storage in our configuration ) : Terraform returned errors: ╷ │ Error: Error in function call │ │ on /home/vscode/.terraform.cache/modules/vm_extension_diagnostics/modules/compute/virtual_machine_extensions/microsoft.azure.diagnostics.tf line 37, in locals: │ 37: template_path = var.extension_name == "microsoft_azure_diagnostics" ? fileexists(var.settings.xml_diagnostics_file) ? var.settings.xml_diagnostics_file : format("%s/%s", var.settings.var_folder_path, var.settings.xml_diagnostics_file) : null │ ├──────────────── │ │ var.settings.var_folder_path is null │ │ var.settings.xml_diagnostics_file is "./diagnostics/wadcfg.xml" │ │ Call to function "format" failed: unsupported value for "%s" at 0: null │ value cannot be formatted. ╵ ╷ │ Error: Invalid index │ │ on /home/vscode/.terraform.cache/modules/vm_extension_diagnostics/modules/compute/virtual_machine_extensions/microsoft.azure.diagnostics.tf line 47, in data "external" "storage_account_key": │ 47: var.settings.diagnostics.storage_accounts[var.extension.diagnostics_storage_account_keys[0]].name, │ ├──────────────── │ │ var.extension.diagnostics_storage_account_keys[0] is "bootdiag_region1" │ │ var.settings.diagnostics.storage_accounts has a sensitive value │ │ The given key does not identify an element in this collection value. ╵ ╷ │ Error: Invalid index │ │ on /home/vscode/.terraform.cache/modules/vm_extension_diagnostics/modules/compute/virtual_machine_extensions/microsoft.azure.diagnostics.tf line 48, in data "external" "storage_account_key": │ 48: var.settings.diagnostics.storage_accounts[var.extension.diagnostics_storage_account_keys[0]].resource_group_name, │ ├──────────────── │ │ var.extension.diagnostics_storage_account_keys[0] is "bootdiag_region1" │ │ var.settings.diagnostics.storage_accounts has a sensitive value │ │ The given key does not identify an element in this collection value. ╵ ╷ │ Error: Invalid index │ │ on /home/vscode/.terraform.cache/modules/vm_extension_diagnostics/modules/compute/virtual_machine_extensions/microsoft.azure.diagnostics.tf line 49, in data "external" "storage_account_key": │ 49: substr(var.settings.diagnostics.storage_accounts[var.extension.diagnostics_storage_account_keys[0]].id, 15, 36) │ ├──────────────── │ │ var.extension.diagnostics_storage_account_keys[0] is "bootdiag_region1" │ │ var.settings.diagnostics.storage_accounts has a sensitive value │ │ The given key does not identify an element in this collection value. ╵ ╷ │ Error: Invalid index │ │ on /home/vscode/.terraform.cache/modules/vm_extension_monitoring_agent/modules/compute/virtual_machine_extensions/Microsoft.EnterpriseCloud.Monitoring.tf line 45, in data "external" "monitoring_workspace_key": │ 45: var.settings.diagnostics.log_analytics[var.extension.diagnostic_log_analytics_key].name, │ ├──────────────── │ │ var.extension.diagnostic_log_analytics_key is "central_logs_region1" │ │ var.settings.diagnostics.log_analytics has a sensitive value │ │ The given key does not identify an element in this collection value. ╵ ╷ │ Error: Invalid index │ │ on /home/vscode/.terraform.cache/modules/vm_extension_monitoring_agent/modules/compute/virtual_machine_extensions/Microsoft.EnterpriseCloud.Monitoring.tf line 46, in data "external" "monitoring_workspace_key": │ 46: var.settings.diagnostics.log_analytics[var.extension.diagnostic_log_analytics_key].resource_group_name, │ ├──────────────── │ │ var.extension.diagnostic_log_analytics_key is "central_logs_region1" │ │ var.settings.diagnostics.log_analytics has a sensitive value │ │ The given key does not identify an element in this collection value. ╵ ╷ │ Error: Invalid index │ │ on /home/vscode/.terraform.cache/modules/vm_extension_monitoring_agent/modules/compute/virtual_machine_extensions/Microsoft.EnterpriseCloud.Monitoring.tf line 47, in data "external" "monitoring_workspace_key": │ 47: substr(var.settings.diagnostics.log_analytics[var.extension.diagnostic_log_analytics_key].id, 15, 36) │ ├──────────────── │ │ var.extension.diagnostic_log_analytics_key is "central_logs_region1" │ │ var.settings.diagnostics.log_analytics has a sensitive value │ │ The given key does not identify an element in this collection value. ╵ Error on or near line 249: Error running terraform plan; exiting with status 2000

asolomchuk commented 2 years ago

@SergioMiyama Hi SergioMiyama , did you have a chance to check this issue ?