Help us understand the problem. What is going on with this article?

terraform apply で Error connecting to SSH_AUTH_SOCK エラーが出るのを解決する

More than 3 years have passed since last update.

Terraform で remote-exec provisioner を含むプランを terraform apply するとこんなエラーが出ることがある:

$ terraform apply
digitalocean_droplet.web: Refreshing state...
digitalocean_droplet.web: Destroying...
digitalocean_droplet.web: Creating...
  image:                "" => "ubuntu-14-04-x64"
...

digitalocean_droplet.web: Provisioning with 'remote-exec'...
Error applying plan:

1 error(s) occurred:

* Error connecting to SSH_AUTH_SOCK: dial unix 0: no such file or directory

これは Terraform がリモートへの接続のためにローカルの ssh-agent プロセスを利用しようとしたとき、プロセスが実行中でない場合に発生する。

解決するには ssh-agent を起動する(ここらへんを参照のこと:ssh-agentの使い方 - Qiita)または ssh-agent を使わないように設定する:

terraform.tf
resource "foo_resource" "bar" {
    # ...
    provisioner "remote-exec" {
        # ...
        connection = {
            agent = false                 # ←agent を経由しないようにする
            key_file = "/path/to/id_rsa"  # ←使う秘密鍵を明示的に与える

        }
    }
}
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away