Reputation: 377
I have a azurerm_virtual_machine_extension
section that looks like this
resource "azurerm_virtual_machine_extension" "InstallCts" {
name = "Install_Cts"
virtual_machine_id = "${element(azurerm_windows_virtual_machine.myserver.*.id, count.index )}"
publisher = "Microsoft.Azure.Extensions"
type = "CustomScript"
type_handler_version = "2.0"
settings = <<SETTINGS
{
"fileUris": [ "https://someurl_server.ps1}" ],
"commandToExecute": "powershell someurl_server.ps1"
}
SETTINGS
}
I keep getting the below error msge
The "count" object can only be used in "module", "resource", and "data"
blocks, and only when the "count" argument is set.
Does azurerm_virtual_machine_extension
work well with azurerm_windows_virtual_machine
with count
or it is not compatible? Any help on this would be appreciated
Upvotes: 0
Views: 1170
Reputation: 28204
As the error display, you should define the count
in the resource azurerm_virtual_machine_extension
section. Note that the extension Microsoft.Azure.Extensions.CustomScript
is used for Linux VMs extension, you can change it like below to work with Windows VMs.
resource "azurerm_virtual_machine_extension" "InstallCts" {
count = length(var.vm_names) # specify here
name = "Install_Cts"
virtual_machine_id = "${element(azurerm_windows_virtual_machine.rg.*.id, count.index )}"
# publisher = "Microsoft.Azure.Extensions"
# type = "CustomScript"
# type_handler_version = "2.0"
publisher = "Microsoft.Compute"
type = "CustomScriptExtension"
type_handler_version = "1.8"
settings = <<SETTINGS
{
"fileUris": [ "https://someurl_server.ps1}" ],
"commandToExecute": "powershell someurl_server.ps1"
}
SETTINGS
}
For example, the below command works for me to add a web server in each VM.
Upvotes: 1
Reputation: 238
I found a similar kidda issue on github. It's closed but I think it covers your issue too. Have a look at this:
https://github.com/terraform-providers/terraform-provider-azurerm/issues/5675
Upvotes: 0