【问题标题】:how to copy local file to azure vm through terraform?如何通过terraform将本地文件复制到azure vm?
【发布时间】:2020-01-24 07:25:38
【问题描述】:

我正在尝试使用 terraform 在 Azure 中创建一个 VM,并将文件从本地计算机复制到 azure 上的远程虚拟机。


    os_profile {
    computer_name = "pdemo"
    admin_username = "ubuntu"
  }
  os_profile_linux_config {
    disable_password_authentication = true
    ssh_keys {
      key_data = "ssh-rsa ********************************** "
      path = "/home/ubuntu/.ssh/authorized_keys"
    }
  }
  provisioner "file" {
    connection {
      type = "ssh"
      user = "ubuntu"
      host = azurerm_public_ip.terraform-PUBLIC-IP.ip_address
      private_key = file("/home/ubuntu/.ssh/id_rsa")
    }
    source = "/home/ubuntu/.ssh/terraform.pub"
    destination = "/home/ubuntu/.ssh/terraform.pub"
  }
}

它给出了一个错误:

azurerm_virtual_machine.terraform-app-VM: Still creating... [1m30s elapsed]
azurerm_virtual_machine.terraform-app-VM: Still creating... [1m40s elapsed]
azurerm_virtual_machine.terraform-app-VM: Still creating... [6m20s elapsed]
azurerm_virtual_machine.terraform-app-VM: Still creating... [6m30s elapsed]

Error: timeout - last error: SSH authentication failed (ubuntu@:22): ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain


【问题讨论】:

    标签: azure terraform


    【解决方案1】:

    请检查您使用的私钥,因为错误显示身份验证问题。

    还可以像这样添加agent=false

    provisioner "file" {
        connection {
          type = "ssh"
          user = "ubuntu"
          host = azurerm_public_ip.terraform-PUBLIC-IP.ip_address
          private_key = file("/home/ubuntu/.ssh/id_rsa")
          agent    = false
          timeout  = "10m"
        }
        source = "/home/ubuntu/.ssh/terraform.pub"
        destination = "/home/ubuntu/.ssh/terraform.pub"
      }
    

    【讨论】:

    • 私钥是正确的,因为虚拟机正在运行,我可以使用私钥ssh到它。
    • 你试过agent=false
    • 是的,但还是同样的问题。
    • 尝试将私钥的权限改为600。chmod 600 /home/ubuntu/.ssh/id_rsa
    • 我注意到,如果您第一次运行 terraform 脚本,它会给出错误:错误:超时 - 最后一个错误:SSH 身份验证失败(ubuntu@:22):ssh:握手失败:ssh :无法验证,尝试的方法 [none publickey],没有支持的方法如果我再次运行代码第二次,它会给出错误:错误:超时 - 最后一个错误:拨号 tcp 40.114.2.59:22:i/o超时如果我第三次运行代码,它就可以工作。你知道是什么问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 2018-07-12
    • 1970-01-01
    • 2016-10-13
    相关资源
    最近更新 更多