terraform ssh:握手失败:ssh:无法进行身份验证,尝试了方法[无公钥],没有支持的方法

时间:2019-06-08 22:33:12

标签: terraform

我不知道它试图通过SSH连接到哪里?进入新部署的资源?

如何更详细地诊断此错误?

Error: Error applying plan:

1 error occurred:
    * module.deploy_nixos.null_resource.deploy_nixos: timeout - last error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
data "google_compute_network" "default" {
  name = "default"
}

resource "google_compute_firewall" "deploy-nixos" {
  name    = "deploy-nixos"
  network = "${data.google_compute_network.default.name}"

  allow {
    protocol = "icmp"
  }

  // Allow SSH access
  allow {
    protocol = "tcp"
    ports    = ["22", "80", "443"]
  }

  source_tags = ["nixos"]
}

resource "google_compute_instance" "deploy-nixos" {
  name         = "deploy-nixos-example"
  machine_type = "g1-small"
  zone         = "europe-west2-a"
  # region      = "eu-west2"

  // Bind the firewall rules
  tags = ["nixos"]

  boot_disk {
    initialize_params {
      // Start with an image the deployer can SSH into
      image = "${module.nixos_image_custom.self_link}"
      size  = "25"
    }
  }

  network_interface {
    network = "default"

    // Give it a public IP
    access_config {}
  }

  lifecycle {
    // No need to re-deploy the machine if the image changed
    // NixOS is already immutable
    ignore_changes = ["boot_disk"]
  }
}

module "deploy_nixos" {
  source = "../../deploy_nixos"

  // Deploy the given NixOS configuration. In this case it's the same as the
  // original image. So if the configuration is changed later it will be
  // deployed here.
  nixos_config = "${path.module}/image_nixos_custom.nix"

  target_user = "root"
  target_host = "${google_compute_instance.deploy-nixos.network_interface.0.access_config.0.nat_ip}"

  triggers = {
    // Also re-deploy whenever the VM is re-created
    instance_id = "${google_compute_instance.deploy-nixos.id}"
  }
}

带有调试输出:

module.deploy_nixos.null_resource.deploy_nixos: Creating...
  triggers.%:                 "" => "3"
  triggers.deploy_nixos_drv:  "" => "/nix/store/0dmz6dhqbk1g6ni3b92l95s377zbikaz-nixos-system-unnamed-19.03.172837.6c3826d1c93.drv"
  triggers.deploy_nixos_keys: "" => "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a"
  triggers.instance_id:       "" => "deploy-nixos-example"
module.deploy_nixos.null_resource.deploy_nixos: Provisioning with 'file'...
2019-06-08T22:31:00.030Z [DEBUG] plugin.terraform: file-provisioner (internal) 2019/06/08 22:31:00 [DEBUG] connecting to TCP connection for SSH
2019-06-08T22:31:00.041Z [DEBUG] plugin.terraform: file-provisioner (internal) 2019/06/08 22:31:00 [DEBUG] handshaking with SSH
2019-06-08T22:31:00.119Z [DEBUG] plugin.terraform: file-provisioner (internal) 2019/06/08 22:31:00 [WARN] ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
2019-06-08T22:31:00.119Z [DEBUG] plugin.terraform: file-provisioner (internal) 2019/06

2 个答案:

答案 0 :(得分:1)

检查模块的源(source =“ ../../deploy_nixos”)可能在此处定义了null_resource(此处未在问题中显示)。您可能在那里使用过terraform remote_exec或文件供应器,并且需要检查其中的连接属性。

示例Terraform连接属性如下

provisioner "file" {
  source      = "conf/myapp.conf"
  destination = "/etc/myapp.conf"

  connection {
    type     = "ssh"
    user     = "root"
    password = "${var.root_password}"
  }
}

有关更多详细信息,请检查:https://www.terraform.io/docs/provisioners/connection.html

答案 1 :(得分:0)

确保已添加ssh密钥。

POST /calendar/v3/calendars/your_calendar_id@group.calendar.google.com/events