【问题标题】:Issues with "admin_ssh_key" within azurerm_virtual_machine block using HCL/Terraform使用 HCL/Terraform 的 azurerm_virtual_machine 块中的“admin_ssh_key”问题
【发布时间】:2021-01-04 16:08:02
【问题描述】:

我收到以下错误:

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"
    }
}

【问题讨论】:

    标签: azure azure-devops terraform terraform-provider-azure hcl


    【解决方案1】:

    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!"
    

    【讨论】:

      猜你喜欢
      • 2021-01-31
      • 1970-01-01
      • 2019-04-23
      • 2022-01-16
      • 2021-08-10
      • 1970-01-01
      • 2020-09-24
      • 1970-01-01
      • 2022-12-15
      相关资源
      最近更新 更多