Skip to Content

Terraform Provider がないエラー対処

環境

Ubuntu 18.04.2 LTS
Terraform v0.12.4

概要

terraform init 時に下記のエラーが出た場合の対処方法

> terraform init

Initializing the backend...

Initializing provider plugins...
- Checking for available provider plugins...
- Downloading plugin for provider "aws" (terraform-providers/aws) 2.19.0...

Error installing provider "aws": Error parsing netrc file at "/home/ohmura/.netrc": line 4: keyword expected; got protocol.

Terraform analyses the configuration and state and automatically downloads
plugins for the providers used. However, when attempting to download this
plugin an unexpected error occurred.

This may be caused if for some reason Terraform is unable to reach the
plugin repository. The repository may be unreachable if access is blocked
by a firewall.

If automatic installation is not possible or desirable in your environment,
you may alternatively manually install plugins by downloading a suitable
distribution package and placing the plugin's executable file in the
following directory:
    terraform.d/plugins/linux_amd64

手順

ディレクトリ確認

> cd ~/.terraform.d/
> ls 
checkpoint_signature

plugins ディレクトリ作成

mkdir -p plugins/linux_amd64

手動で必要なproviderをダウンロード
エラーメッセージ内でご指定のバージョンを落とす
> - Downloading plugin for provider “aws” (terraform-providers/aws) 2.19.0…

WEBサイトから必要なリンク先を確認

> wget https://releases.hashicorp.com/terraform-provider-aws/2.19.0/terraform-provider-aws_2.19.0_linux_amd64.zip

解凍

> unzip terraform-provider-aws_2.19.0_linux_amd64.zip 

ZIPファイル削除

> rm terraform-provider-aws*.zip

ファイル確認

> pwd
/home/ohmura/.terraform.d/plugins/linux_amd64
> ls
terraform-provider-aws_v2.19.0_x4*

再度、terraform init
エラーが解消された

> terraform init

Initializing the backend...

Initializing provider plugins...

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, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.aws: version = "~> 2.19"

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.

参考

https://qiita.com/micci184/items/9f8eb1d6fa7301e36b67