1

我正在尝试根据 terraform docs 中指定的格式,将 remote-exec 配置器用于与我在 GCP 上的项目相关的用例,使用 Terraform 版本 12 在配置器超时后,我得到一个已知的主机密钥不匹配错误。

resource "google_compute_instance" "secondvm" {
    name = "secondvm"
    machine_type = "n1-standard-1"
    zone = "us-central1-a"
 boot_disk {
            initialize_params {
                    image = "centos-7-v20190905"
            }
    }

    network_interface {
            network = "default"


            access_config {
            nat_ip = google_compute_address.second.address
            network_tier = "PREMIUM"
    }


    }

    #metadata = {
#ssh-keys = "root:${file("~/.ssh/id_rsa.pub")}"

#}

    metadata_startup_script = "cd /; touch makefile.txt; sudo echo \"string xyz bgv\" >>./makefile.txt"

    provisioner "remote-exec" {

    inline = [
            "sudo sed -i 's/xyz/google_compute_address.first.address/gI' /makefile.txt"
    ]

    connection {
            type = "ssh"
            #port = 22
            host = self.network_interface[0].access_config[0].nat_ip
            user = "root"
            timeout = "120s"
            #agent = false
            private_key = file("~/.ssh/id_rsa")
            #host_key = file("~/.ssh/google_compute_engine.pub")
            host_key = file("~/.ssh/id_rsa.pub")
    }
}

    depends_on = [google_compute_address.second]

}

我不确定我在这里的键到底做错了什么,但我得到的错误是

    google_compute_instance.secondvm: Still creating... [2m10s elapsed]
google_compute_instance.secondvm (remote-exec): Connecting to remote host via SSH...
google_compute_instance.secondvm (remote-exec):   Host: 104.155.186.128
google_compute_instance.secondvm (remote-exec):   User: root
google_compute_instance.secondvm (remote-exec):   Password: false
google_compute_instance.secondvm (remote-exec):   Private key: true
google_compute_instance.secondvm (remote-exec):   Certificate: false
google_compute_instance.secondvm (remote-exec):   SSH Agent: false
google_compute_instance.secondvm (remote-exec):   Checking Host Key: true
google_compute_instance.secondvm: Still creating... [2m20s elapsed]


Error: timeout - last error: SSH authentication failed (root@104.155.186.128:22): ssh: handshake failed: knownhosts: key mismatch

4

0 回答 0