【发布时间】:2020-08-04 00:06:31
【问题描述】:
我不知道它试图通过 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
【问题讨论】:
-
我猜 terraform 正在尝试使用
target_user将target_host连接到deploy_nixos模块中声明的deploy_nixos。问题是它将使用哪个 ssh 密钥?看看下面@qudongfang 的回答。
标签: terraform