Terraform Azurerm error: linuxConfiguration.ssh.publicKeys.path is invalid

Terraform Azurerm error: linuxConfiguration.ssh.publicKeys.path is invalid

我正在使用 Terraform v0.12.24 和 provider.azurerm v2.2.0 当我尝试创建规模集 VM 时出现以下错误:

Error: compute.VirtualMachineScaleSetsClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidParameter" Message="The value of parameter linuxConfiguration.ssh.publicKeys.path is invalid." Target="linuxConfiguration.ssh.publicKeys.path"

on scaleset.tf line 1, in resource "azurerm_virtual_machine_scale_set" "demo": 1: resource "azurerm_virtual_machine_scale_set" "demo" {

我正在使用 Windows 10 进行地形配置。我的 os_profile_linux_config 如下:

       storage_profile_image_reference {
        publisher = "Canonical"
        offer     = "UbuntuServer"
        sku       = "18.04-LTS"
        version   = "latest"
      }

  os_profile_linux_config {
    disable_password_authentication = true

    ssh_keys {
      key_data = file("C:/Users/jack/Documents/key/id_rsa.pub")
      path     = "C:/Users/jack/Documents/key"
    }
  }

首先,我尝试了两种不同的密钥对。一个由 puttygen 创建,另一个由 ssh-keygen 使用 git bash 创建。我对他们两个都有同样的错误。 你有什么想法吗?

关于你的问题,我认为你误解了ssh_key的属性path,这里显示:

ssh_keys - (Optional) Specifies a collection of path and key_data to be placed on the virtual machine.

是你要创建的VM里面的路径,不是你执行Terraform的机器的路径。还有:

Note: Please note that the only allowed path is /home//.ssh/authorized_keys due to a limitation of Azure.