I'm trying to changed the value in a terraform map. In my terraform.auto.tfvars file:
dependencies = {
win_chocolatey = {
name = "chocolatey"
publisher = "Microsoft.Azure.Extensions"
type = "CustomScript"
virtual_machine_id = ""
type_handler_version = "2.0"
auto_upgrade_minor_version = "false"
extensions_custom_script_fileuris = ""
extensions_custom_command = "powershell -ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) exit 0"
tags = {
purpose = "software"
}
}
}
And in my main.tf file, I want to update the value of virtual_machine_id before passing the variable to the resources.
I have tried this:
data "azurerm_virtual_machine" "wininstaller" {
name = "vm-wininstall"
resource_group_name = "rg-zephyr-devops"
}
locals {
dependencies = {
for x in var.dependencies : { win_chocolatey.virtual_machine_id = data.azurerm_virtual_machine.wininstaller.id }
}
}
but I get an error in the for loop:
Error: Invalid 'for' expression
on main.tf line 19, in locals: 19: dependencies = {for x in var.dependencies : { win_chocolatey.virtual_machine_id = data.azurerm_virtual_machine.wininstaller.id }}
Key expression is required when building an object.
Does anyone know how to fix this or a better way to do this?