Hi All,
Terraform Version: v1.6.6 AMD64
AzureRM version:3.64.0
I am creating multiple virtual machine using for each loop and I want to execute powershell script in all this virtual machine using “azurerm_virtual_machine_extension”.
Below is the code snippet
resource “azurerm_virtual_machine_extension” “install_new_vm” {
count = length(var.virtual_machine_name)
name = “${var.virtual_machine_name[count.index]}-vm”
virtual_machine_id = azurerm_windows_virtual_machine.new-vm[count.index].id
publisher = “Microsoft.Compute”
type = “CustomScriptExtension”
type_handler_version = “1.10”
protected_settings = <<SETTINGS
{
“commandToExecute”: “powershell -command "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('{base64encode(data.template_file.dotnet_and_powerbi_script[count.index].rendered)}')) | Out-File -filepath dotnet_and_powerbi_script.ps1\" && powershell -ExecutionPolicy Unrestricted -File dotnet_and_powerbi_script.ps1 -GatewayName {var.new-vm-adminusername} -GatewayKey ${azurerm_key_vault_secret.new-vm-password[count.index].value}”
}
SETTINGS
tags = local.all_tags
depends_on = [ azurerm_windows_virtual_machine.new-vm ]
}
While executing above code I am getting error given below:
Error: compute.VirtualMachineExtensionsClient#CreateOrUpdate: Failure sending request: StatusCode=400 – Original Error: Code=“BadRequest” Message=“Multiple VMExtensions per handler not supported for OS type ‘Windows’. VMExtension ‘new-vm’ with handler ‘Microsoft.Compute.CustomScriptExtension’ already added or specified in input.”
│
│ with azurerm_virtual_machine_extension.install_new_vm[1],
│ on resources.virtualmachines.tf line 76, in resource “azurerm_virtual_machine_extension” “install_new_vm”:
│ 76: resource “azurerm_virtual_machine_extension” “install_new_vm” {