LoginSignup
1

More than 5 years have passed since last update.

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

Posted at

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"  # ←使う秘密鍵を明示的に与える

        }
    }
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1