9

私はAWS の 2 層の例を使用しており、すべてを直接コピー アンド ペーストしました。terraform apply作成された EC2 インスタンスに SSH で接続しようとするところまで機能します。最終的に失敗する前に、この出力を提供して数回ループします。

aws_instance.web (remote-exec): Connecting to remote host via SSH...
aws_instance.web (remote-exec):   Host: 54.174.8.144
aws_instance.web (remote-exec):   User: ubuntu
aws_instance.web (remote-exec):   Password: false
aws_instance.web (remote-exec):   Private key: false
aws_instance.web (remote-exec):   SSH Agent: true

最終的に、次の理由で失敗します。

Error applying plan:

1 error(s) occurred:

* ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

私は周りを検索して、いくつかの古い投稿/問題が反転agent=falseしているのを見ました。また、変更や成功なしでそれを試しました。この例が箱から出してすぐに壊れていることに懐疑的ですが、それを壊す可能性のある調整や変更は行っていません. OS X 10.10.5に自作でインストールされたterraform 0.6.11を使用しています。

追加の詳細:

resource "aws_instance" "web" {
  # The connection block tells our provisioner how to
  # communicate with the resource (instance)
  connection {
    # The default username for our AMI
    user = "ubuntu"

    # The connection will use the local SSH agent for authentication.
    agent = false
  }

  instance_type = "t1.micro"

  # Lookup the correct AMI based on the region
  # we specified
  ami = "${lookup(var.aws_amis, var.aws_region)}"

  # The name of our SSH keypair we created above.
  key_name = "${aws_key_pair.auth.id}"

  # Our Security group to allow HTTP and SSH access
  vpc_security_group_ids = ["${aws_security_group.default.id}"]

  # We're going to launch into the same subnet as our ELB. In a production
  # environment it's more common to have a separate private subnet for
  # backend instances.
  subnet_id = "${aws_subnet.default.id}"

  # We run a remote provisioner on the instance after creating it.
  # In this case, we just install nginx and start it. By default,
  # this should be on port 80
  provisioner "remote-exec" {
    inline = [
      "sudo apt-get -y update",
      "sudo apt-get -y install nginx",
      "sudo service nginx start"
    ]
  }
}

そして、変数 tf ファイルから:

variable "key_name" {
  description = "Desired name of AWS key pair"
  default = "test-keypair"
}

variable "key_path" {
  description = "key location"
  default = "/Users/n8/dev/play/.ssh/terraform.pub"
}

しかし、私はこのコマンドでsshできます:

ssh -i ../.ssh/terraform ubuntu@w.x.y.z
4

4 に答える 4

23

次の 2 つの可能性があります。

  1. キーをに追加しますssh-agent

    ssh-add ../.ssh/terraform
    

    構成で使用agent = trueします。ケースはあなたのために働くはずです

  2. キーを直接使用するように構成を変更します

    secret_key = "../.ssh/terraform"
    

    とか、ぐらい。より具体的な構文については、ドキュメントを参照してください。

于 2016-02-13T17:22:07.237 に答える