azurerm_virtual_machine_extension Fails to apply

514 views
Skip to first unread message

Andrew Hodgson

unread,
Nov 16, 2017, 5:11:36 AM11/16/17
to terrafo...@googlegroups.com
Hi,

I am using the following code:

resource "azurerm_network_interface" "project_api" {
count = 2
name = "project-api-${var.tags["environment"]}-${count.index}"
location = "${var.main_resource_group_location}"
resource_group_name = "${var.main_resource_group_name}"

ip_configuration {
name = "project-api-${var.tags["environment"]}-${count.index}"
subnet_id = "${var.project_subnet_id}"
private_ip_address_allocation = "dynamic"
}

tags = "${var.tags}"
}

resource "azurerm_availability_set" "project_api" {
name = "project-api-${var.tags["environment"]}"
location = "${var.main_resource_group_location}"
resource_group_name = "${var.main_resource_group_name}"
platform_fault_domain_count = 2
managed = true

tags = "${var.tags}"
}

resource "azurerm_virtual_machine" "project_api" {
count = 2
name = "project-api-${var.tags["environment"]}-${count.index}"
location = "${var.main_resource_group_location}"
resource_group_name = "${var.main_resource_group_name}"
network_interface_ids = ["${element(azurerm_network_interface.project_api.*.id, count.index)}"]
vm_size = "Standard_D2_V2"
availability_set_id = "${azurerm_availability_set.project_api.id}"
delete_os_disk_on_termination = true
license_type = "Windows_Server"

storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2016-Datacenter"
version = "latest"
}

storage_os_disk {
name = "project-api-${var.tags["environment"]}-${count.index}"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}

os_profile {
computer_name = "api-${var.tags["environment"]}-${count.index}"
admin_username = "${var.tags["environment"]}-admin"
admin_password = "${var.vm_password}"
}

os_profile_windows_config {
provision_vm_agent = true
enable_automatic_upgrades = true
}
}

resource "azurerm_virtual_machine_extension" "vsts_agent" {
count = 2
name = "project-vsts-${var.tags["environment"]}-${count.index}"
resource_group_name = "${var.main_resource_group_name}"
location = "${var.main_resource_group_location}"
virtual_machine_name = "${element(azurerm_virtual_machine.project_api.*.id, count.index)}"
publisher = "Microsoft.VisualStudio.Services"
type = "TeamServicesAgent"
type_handler_version = "1.10.0.0"
auto_upgrade_minor_version = true

settings = <<EOF
{
"VSTSAccountName": "[...]",
"TeamProject": "project",
"DeploymentGroup": "project-api-${var.tags["environment"]}"
}
EOF

protected_settings = <<EOF
{
"PATToken": "[...]"
}
EOF
}

resource "azurerm_virtual_machine_extension" "iis" {
count = 2
name = "project-iis-${var.tags["environment"]}-${count.index}"
resource_group_name = "${var.main_resource_group_name}"
location = "${var.main_resource_group_location}"
virtual_machine_name = "${element(azurerm_virtual_machine.project_api.*.id, count.index)}"
publisher = "Microsoft.Azure.Extensions"
type = "CustomScript"
type_handler_version = "2.0.6"
auto_upgrade_minor_version = true

settings = <<EOF
{
"commandToExecute": "powershell Add-WindowsFeature Web-Asp-Net45"
}
EOF
}

The virtual machines are provisioned but it fails adding the virtual machine extensions:

Error: Error applying plan:

4 error(s) occurred:

* module.environment.azurerm_virtual_machine_extension.iis[1]: 1 error(s) occurr
ed:

* azurerm_virtual_machine_extension.iis.1: compute.VirtualMachineExtensionsClien
t#CreateOrUpdate: Failure responding to request: StatusCode=404 -- Original Erro
r: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound"
Message="The Resource 'Microsoft.Compute/virtualMachines/subscriptions' under r
esource group 'my_resource_group' was not found."
* module.environment.azurerm_virtual_machine_extension.vsts_agent[0]: 1 error(s)
occurred:

* azurerm_virtual_machine_extension.vsts_agent.0: compute.VirtualMachineExtensio
nsClient#CreateOrUpdate: Failure responding to request: StatusCode=404 -- Origin
al Error: autorest/azure: Service returned an error. Status=404 Code="ResourceNo
tFound" Message="The Resource 'Microsoft.Compute/virtualMachines/subscriptions'
under resource group 'my_resource_group' was not found."
* module.environment.azurerm_virtual_machine_extension.vsts_agent[1]: 1 error(s)
occurred:

* azurerm_virtual_machine_extension.vsts_agent.1: compute.VirtualMachineExtensio
nsClient#CreateOrUpdate: Failure responding to request: StatusCode=404 -- Origin
al Error: autorest/azure: Service returned an error. Status=404 Code="ResourceNo
tFound" Message="The Resource 'Microsoft.Compute/virtualMachines/subscriptions'
under resource group 'my_resource_group' was not found."
* module.environment.azurerm_virtual_machine_extension.iis[0]: 1 error(s) occurr
ed:

* azurerm_virtual_machine_extension.iis.0: compute.VirtualMachineExtensionsClien
t#CreateOrUpdate: Failure responding to request: StatusCode=404 -- Original Erro
r: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound"
Message="The Resource 'Microsoft.Compute/virtualMachines/subscriptions' under r
esource group 'my_resource_group' was not found."

Anyone seen this before? I have protected the names of the project and resource group. These are being provisioned in UK West.

Thanks.
Andrew.

Andrew Hodgson

unread,
Nov 17, 2017, 11:23:26 AM11/17/17
to terrafo...@googlegroups.com
Hi,

This is now sorted, I was trying to pass the machine ID instead of the name to the VM extension:

virtual_machine_name = "${element(azurerm_virtual_machine.project_api.*.id, count.index)}"

Should be:

virtual_machine_name = "${element(azurerm_virtual_machine.project_api.*.name, count.index)}"

Also I had to change the extensions and versions being used. It does take a long time to apply because the system waits for the extensions to complete on the VMs before returning the HTTP response, so may have to look at another way of doing this for longer running scripts.

Andrew.

________________________________________
From: Andrew Hodgson
Sent: 16 November 2017 10:11
To: terrafo...@googlegroups.com
Subject: azurerm_virtual_machine_extension Fails to apply
Reply all
Reply to author
Forward
0 new messages