使用 terraform 生成 digitalocean 液滴时无法使用 ssh 密钥

unable to use ssh key when spawning digitalocean droplet using terraform

我正在使用 terraform v0.10.6 在 digitalocean 上旋转一个 droplet。我正在引用一个密钥和 SSH 指纹,它们已经添加到我的 terraform 配置中的 digitalocean(复制在下面)。我可以使用此 ssh 密钥登录现有的 droplet,但不能登录新形成的 droplet(SSH 完全失败)。关于如何解决这个问题的任何想法,以便当我通过 terraform 启动 droplet 时,我应该能够通过已经添加到 digitalocean 上的密钥登录到 droplet(并且在 DO 控制台上可见)。目前,droplet 出现在 digitalocean 管理控制台上,但我永远无法通过 SSH 连接到服务器(连接被拒绝)。

test.tf

# add base droplet with name
resource "digitalocean_droplet" "do-mail" {
  image              = "ubuntu-16-04-x64"
  name               = "tmp.validdomain.com"
  region             = "nyc3"
  size               = "1gb"
  private_networking = true

  ssh_keys = [
    "${var.ssh_fingerprint}",
  ]

  connection {
    user        = "root"
    type        = "ssh"
    private_key = "${file(var.private_key)}"
    timeout     = "2m"
  }

  provisioner "remote-exec" {
    inline = [
      "export PATH=$PATH:/usr/bin",
      "sudo apt-get update",
    ]
  }
}

terraform.tfvars

digitalocean_token = "correcttoken"
public_key = "~/.ssh/id_rsa.pub"
private_key = "~/.ssh/id_rsa"
ssh_fingerprint = "correct:finger:print"

provider.tf

provider "digitalocean" {
  token = "${var.digitalocean_token}"
}

variables.tf

##variables used by terraform

    # DO token
    variable "digitalocean_token" {
      type = "string"
    }

    # DO public key file location on local server
    variable "public_key" {
      type = "string"
    }

    # DO private key file location on local server
    variable "private_key" {
      type = "string"
    }

    # DO ssh key fingerprint
    variable "ssh_fingerprint" {
      type = "string"
    }

当我将 digitalocean 令牌指定为环境变量(而不是依赖 terraform.tfvars 文件)时,我能够在初始化时使用 SSH 密钥设置一个新的 Droplet。