/var/www/yatta47.log

/var/www/yatta47.log

やったのログ置場です。スクラップみたいな短編が多いかと。

/.terraform.d/plugins/linux_amd64: no such file or directoryと出てきた場合の対処

f:id:yatta47:20210227142332p:plain

Terraformerでインフラをエクスポートしてみようと思ってコマンド実行してみたら早速エラー。

$ terraformer import aws --resources=api_gateway --regions=ap-northeast-1
2020/11/08 03:19:05 aws importing region ap-northeast-1
2020/11/08 03:19:05 aws importing... api_gateway
2020/11/08 03:19:07 open /home/XXXXXXXX/.terraform.d/plugins/linux_amd64: no such file or directory
$

なんやねん。ってことで調べることに。

 

発生したエラーはこちら

open /home/XXXXXXXX/.terraform.d/plugins/linux_amd64: no such file or directory

必要なファイルがないということでエラーっぽいな。

 

解決方法

こちらに書いてありました。

plugin error 1: open /Users/jvlle/.terraform.d/plugins/darwin_amd64: no such file or directory open /Users/jvlle/.terraform.d/plugins/darwin_amd64: no such file or directory · Issue #184 · GoogleCloudPlatform/terraformer · GitHub

terraformの初期化しておかないといけないってことね。

 

やってみた。

まずはinit.tfを作成。

echo 'provider "aws" {}' > init.tf

そのあと、terraform initをします。

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/aws...
- Installing hashicorp/aws v3.14.1...
- Installed hashicorp/aws v3.14.1 (signed by HashiCorp)

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, we recommend adding version constraints in a required_providers block
in your configuration, with the constraint strings suggested below.

* hashicorp/aws: version = "~> 3.14.1"

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

これで完了。ちゃんとコマンド打てるようになりました。

 

まとめ

自分でやったときは順番が逆でやっていたせいで、Terraformの初期化がうまくできずに今回のエラーが出てきたのだと思います。

っていうかちゃんとREADME.mdに書いてあったね。

READMEはちゃんと読みましょう。