05-16-2019 08:19 AM
I am trying to deploy virtual smart zone to Azure via Terraform, but could not succeed many times. Did you have any experience about this? Please give me an advice. Thank you so much.
Here are the details:
Terraform Version:
tien$ terraform -v
Terraform v0.11.13
+ provider.azurerm v1.27.1
+ provider.random v2.1.2
What terraform did I write:
resource "azurerm_virtual_machine" "vsz_vm" {
name = "vsz.az.example.com"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.abc.name}"
network_interface_ids = ["${azurerm_network_interface.vsz_nic.id}"]
vm_size = "Standard_D4_v3"
storage_image_reference {
id = "/subscriptions/4389d27e-249a-4f95-8bd6-3486c60945e7/resourceGroups/ABC/providers/Microsoft.Storage/storageAccounts/vszafb3c92c014b61ab/images/vscg-5.1.1.0.598.vhd"
}
storage_os_disk {
name = "vszOsDisk"
managed_disk_type = "Premium_LRS"
create_option = "FromImage"
os_type = "Linux"
}
os_profile {
computer_name = "vsz.az.example.com"
admin_username = "azure"
}
os_profile_linux_config {
disable_password_authentication = true
ssh_keys {
path = "/home/azure/.ssh/authorized_keys"
key_data = "${var.ssh_public_key}"
}
}
tags {
environment = "${var.environment}"
}
}
then I run terraform commandtien$ terraform init --> OK
tien$ terraform plan --> OK
tien$ terraform apply --> ERROR
What issue?
Error: Error applying plan:
1 error(s) occurred:
* module.azure_example_dlc.azurerm_virtual_machine.vsz_vm: 1 error(s) occurred:
* azurerm_virtual_machine.vsz_vm: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="BadRequest" Message="Id /subscriptions/4389d27e-249a-4f95-8bd6-3486c60945e7/resourceGroups/ABC/providers/Microsoft.Storage/storageAccounts/vszafb3c92c014b61ab/images/vscg-5.1.1.0.598.vhd is not a valid resource reference."
The VHD file vscg-5.1.1.0.598.vhd exists in container "images" at Storage Account "vszafb3c92c014b61ab".
Also I create the Managed Image before creating VM from Managed Image as below code:
storage_image_reference {
id = "/subscriptions/4389d27e-249a-4f95-8bd6-3486c60945e7/resourceGroups/ABC/providers/Microsoft.Storage/storageAccounts/vszafb3c92c014b61ab/images/vscg-5.1.1.0.598.vhd"
}
storage_os_disk {
name = "vszOsDisk"
managed_disk_type = "Premium_LRS"
create_option = "FromImage"
os_type = "Linux"
}
05-19-2019 09:10 PM