LoginSignup
3
0

terraform initした際に「Error: error configuring S3 Backend: error validating provider credentials」となるときの対処

Last updated at Posted at 2023-01-16

はじめに

Terraformでインフラを記述する際に、
プロジェクトフォルダを作成したあと最初に
terraform initコマンドを入力して初期化します。
このときに出るエラーとして、掲題のケースがあり、
この対処について確認していきたいと思います。

エラー内容

$ terraform init
Error: error configuring S3 Backend: error validating provider credentials: error calling sts:GetCallerIdentity: InvalidClientTokenId: The security token included in the request is invalid.
        status code: 403, request id: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

対処

結論、AWSの認証情報設定が必要になります。
〜/.aws/credentialsファイルにてアクセスキーとシークレットアクセスキーを設定します。

$ aws configure
(※下記については右のコマンドで確認可「$ cat ~/.aws/credentials」)
AWS Access Key ID [None]: AWSアカウントで発行したアクセスキー IDを入力
AWS Secret Access Key [None]: AWSアカウントで発行したシークレットアクセスキーを入力
(※下記については右のコマンドで確認可「$ cat ~/.aws/credentials」)
Default region name [None]: ap-northeast-1など利用したいリージョン名を入力
Default output format [None]: jsonを入力

問題なく初期化できました。

$ terraform init
Initializing the backend...

Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.

Initializing provider plugins...

〜省略〜

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

Terraform has been successfully initialized!

終わりに

アクセスキーを発行しない方法についても今後色々と試していきたいと思います!

3
0
0

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
3
0