LoginSignup
49
21

More than 1 year has passed since last update.

TerraformのAWS Provider v4メジャーアップデートは破壊的変更あり

Posted at

この記事の要約

2022/02/10に、TerraformからAWS Provider v4.0.0がリリースされました。このメジャーアップデートには破壊的変更が含まれおり、今まで利用していたTerraformのソースコードが動かなくなる恐れがあります。安易にAWS Provider
のバージョンを上げてしまうと今までのソースコードがエラーを吐くようになります。特にS3に関する破壊的変更は影響範囲が大きいと思われます。情報をまとめておければと思います。

S3に関する破壊的変更

v4.0.0の変更点の全容
リリースノート中にdeprecatedと書かれていますが破壊的変更です。ご注意を。

暫定対応

AWS Providerの最新リリースを利用しないように設定する。

公式サイトより
terraform {
  required_providers {
    aws  = "~> 3.74"
  }
}

エラー文言

エラーが発生するコードとそのエラー文言を https://github.com/hashicorp/terraform-provider-aws/issues/23103 より引用

s3.tf
resource "aws_s3_bucket" "mybucket" {
  bucket_prefix = "myname-"
  acl    = "private"
  versioning { enabled = true }
  server_side_encryption_configuration {
    rule {
      apply_server_side_encryption_by_default {
        sse_algorithm = "AES256"
      }
    }
  }
}
error_output
Error: Value for unconfigurable attribute

 with module.common.aws_s3_bucket.mybucket,
 on ../../s3.tf line 1, in resource "aws_s3_bucket" "mybucket":
 1: resource "aws_s3_bucket" "mybucket" {

 Can't configure a value for "server_side_encryption_configuration": its value will be decided automatically based on the result of applying this configuration.
╵
╷
│ Error: Value for unconfigurable attribute
│
│ with module.common.aws_s3_bucket.mybucket,
│ on ../../s3.tf line 1, in resource "aws_s3_bucket" "mybucket":
│ 1: resource "aws_s3_bucket" "mybucket" {
│
│ Can't configure a value for "versioning": its value will be decided automatically based on the result of applying this configuration.


 Error: Value for unconfigurable attribute

 with module.common.aws_s3_bucket.mybucket,
 on ../../s3.tf line 3, in resource "aws_s3_bucket" "mybucket":
 3: acl = "private"

 Can't configure a value for "acl": its value will be decided automatically based on the result of applying this configuration.

v4系へのアップグレードガイド

公式アップグレードガイド
特にS3リソースのアップグレードはこちら

そもそもなんでこういう変更を加えたのか

v4.0.0に関する公式ブログ
aws_s3_bucketリソースは最も古くて大きくてよく使われているけれど、バケットの設定や管理に関するAPIの呼び出しを、この一つのリソースの中で設定するとかなり複雑になってしまい、ユーザにとっても大変である。設定をよりシンプルに、きめ細かくできるよう、aws_s3_bucketリソース一つで負っていた責務を分散することにした。」
という感じ(適当訳)

参考になったIssueなど

v4へのアップデートに関して書かれた良い記事↓
https://www.infoq.com/news/2022/02/terraform-aws-provider-s3/

https://github.com/hashicorp/terraform-provider-aws/issues/20433
https://github.com/hashicorp/terraform-provider-aws/issues/23103
https://github.com/hashicorp/terraform-provider-aws/issues/23106
https://github.com/hashicorp/terraform-provider-aws/issues/23125

私見

上にあげたようなIssueの他にも、今回のメジャーバージョンアップデートによる影響と思われるIssueが、この数日でいくつも挙げられています。私自身、情報が追えておらず、突然動かなくなってびっくりしました。(バージョン管理が甘かった。)

S3自体はAWSの中でも最も古いサービスの1つだと思うので、長年のAWS側の機能拡張をterraform側に取り込んできたことによって、aws_s3_bucketの設定項目が複雑化・肥大化してしまい、分割せざるを得なかったのだろうと感じます。

それにしても、破壊的な変更は・・・とか、巨大組織で既に運用されてるtfファイルを簡単に移行できないよ・・・とか、terraformより良いツールあるよ・・・とか、今回のメジャーアップデートに関してはみなさん色々な意見があると思います。

気づいたことがあればコメントください。熱が冷めていないうちは記事を更新します。

49
21
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
49
21