0

我收到以下错误:

Error: Unsupported block type
front.tf line 164, in resource "azurerm_virtual_machine" "FrontEndVirtualMachines":
164:  admin_ssh_key {
Blocks of type "admin_ssh_key" are not expected here.

我正在关注这个例子:

https://docs.microsoft.com/en-us/azure/developer/terraform/create-linux-virtual-machine-with-infrastructure

我在文档中注意到的一件事,“创建虚拟机”部分使用:

output "tls_private_key" { 
  value = "tls_private_key.Ssh.private_key_pem"
}

而“完整的 Terraform 脚本”部分使用带有花括号的 $:

output "tls_private_key" { 
  value = "${tls_private_key.Ssh.private_key_pem}"
}

我已经尝试了两种方法并遇到了同样的问题。

这是我的代码:

#Create (and display) an SSH key
resource "tls_private_key" "Ssh" {
    algorithm = "RSA"
    rsa_bits = 4096
}
output "tls_private_key" { value = "${tls_private_key.Ssh.private_key_pem}" }

#Create 2 front end web servers VMs
resource "azurerm_virtual_machine" "FrontEndVirtualMachines" {
    count = 2
    name = "vmFront${count.index}"
    location = azurerm_resource_group.PWSDevResourceGroup.location
    availability_set_id = azurerm_availability_set.AvailibilitySet.id
    resource_group_name = azurerm_resource_group.PWSDevResourceGroup.name
    network_interface_ids = [element(azurerm_network_interface.FrontNetworkInterface.*.id, count.index)]
    vm_size = "A4_V2"

 # Uncomment this line to delete the OS disk automatically when deleting the VM
 # delete_os_disk_on_termination = true

 # Uncomment this line to delete the data disks automatically when deleting the VM
 # delete_data_disks_on_termination = true

#Define OS Image
 storage_image_reference {
    publisher = "MicrosoftWindowsServer"
    offer = "WindowsServer"
    sku = "2016-Datacenter"
    version = "latest"
   }

#Define OS Disk
storage_os_disk {
    name = "FrontOSDisk"
    caching = "ReadWrite"
    create_option = "FromImage"
    managed_disk_type = "Standard_LRS"
   }

#Define Secondary Storage Disk
storage_data_disk {
    name = "FrontDataDisk"
    create_option = "Empty"
    lun = 1
    disk_size_gb = "64"
    managed_disk_type = "Standard_LRS"
   }

#Define Admin Profile
 os_profile {
    computer_name = "Front"
    admin_username = "#######"
    admin_password = "#######"
    }

admin_ssh_key {
    username       = "azureuser"
    public_key     = tls_private_key.Ssh.public_key_openssh
    }

boot_diagnostics {
    enabled = true
    storage_uri = azurerm_storage_account.PWSDevStorageAcct.primary_blob_endpoint
    }

tags = {
    environment = "Front-End"
    }
}
4

1 回答 1

0

Azure 文档适用于 azurerm_linux_virtual_machine 资源类型。您正在使用 azurerm_virtual_machine。此资源已拆分为单独的 linux 和 windows 版本。它在 2.x 中仍受支持,但功能已冻结。此外,您正在尝试构建一个不支持添加 admin_ssh_key 的 Windows 服务器。您可能想要使用azurerm_windows_virtual_machine。传递信用

  admin_username      = "adminuser"
  admin_password      = "P@$$w0rd1234!"
于 2020-09-18T14:00:01.557 回答