Terraform Remote-exec与OpenStack实例问题

时间:2018-12-21 14:47:41

标签: terraform terraform-provider-openstack

我正在尝试在创建实例时执行remote-exec命令,但是面临与我的private_key相关的错误。我验证了密钥是否位于正确的路径上。

resource "openstack_compute_instance_v2" "worker" {
  name            = "${local.env}-worker-0${count.index+1}"
  image_id        = "${lookup(var.image_id, var.k8s_os)}"
  flavor_id       = "${data.openstack_compute_flavor_v2.m1_large.id}"
  key_pair        = "${var.key_name}"
  security_groups = ["${local.env}-worker-sg"]

    connection {
      type        = "ssh"
      user        = "${var.user}"
      private_key = "${var.private_key_path}${var.key_name}.pem"
      timeout = "1m"
      agent = false
    }

  provisioner "remote-exec" {
    inline = [
      "sudo hostnamectl set-hostname --static ${local.env}-worker-0${count.index+1}"
    ]
  }

  count = "${lookup(var.worker_count, local.env)}"
}

所以我在下面出现错误:

openstack_compute_instance_v2.worker[0]: Failed to read key "/home/myuser/.ssh/mykey.pem": no key found

我也尝试使用private_key =“ $ {file(” / home / myuser / .ssh / mykey.pem“)}”“,但出现另一个错误:

* openstack_compute_instance_v2.worker[0]: Failed to parse key file "-----BEGIN RSA PRIVATE KEY---- HERE_IS_MY_PRIVATE_KEYS ----END RSA PRIVATE KEY-----\n": asn1: structure error: superfluous leading zeros in length

0 个答案:

没有答案