【问题标题】:unable to use ssh key when spawning digitalocean droplet using terraform使用 terraform 生成数字海洋液滴时无法使用 ssh 密钥
【发布时间】:2018-01-11 03:32:11
【问题描述】:

我正在使用 terraform v0.10.6 在 digitalocean 上旋转一个液滴。我正在引用已在我的 terraform 配置中添加到 digitalocean 的密钥和 SSH 指纹(复制如下)。我可以使用此 ssh 密钥登录现有的 droplet,但不能登录新形成的 droplet(SSH 根本失败)。关于如何解决这个问题的任何想法,以便当我通过 terraform 启动液滴时,我应该能够通过已经添加到 digitalocean 的密钥登录到液滴(并且在 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"
    }

【问题讨论】:

    标签: ubuntu-16.04 digital-ocean terraform


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2016-10-03
      • 2021-07-31
      • 2015-02-16
      • 2021-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-04
      相关资源
      最近更新 更多