LoginSignup
16
13

More than 5 years have passed since last update.

バックエンドが S3 の terraform で init 時に profile 指定する

Posted at

 terraform のバックエンドの S3 にアクセスするときにも当たり前ですが、credential が必要です。複数の profile を使っているときに、デフォルトじゃないものに切り替えたいシチュエーションは結構あるのではないかなと思います。

 そのような場合は以下のように partial configuration を用いて profile 指定してあげれば OK です。

terraform init -backend-config="profile=${aws_profile}"

 ただ、backend に直接記述してしまえば、そもそもあまりこういう心配しなくてすみます。チームで profile 名統一しておいて、 README にこのプロファイル名で設定するという規約を作っておくと、よいのかなと思います。

terraform {
  backend "s3" {
    bucket         = "******"
    key            = "******"
    dynamodb_table = "******"
    region         = "ap-northeast-1"
    shared_credentials_file = "~/.aws/credentials"
    profile = "53ningen"
  }
}

 terraform の公式ドキュメント的にはこのあたりを参照。このように指定した場合 aws provider にも profile 指定しておくと複数人による開発がスムーズに進んで良いと思います。

16
13
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
16
13