2
1

More than 1 year has passed since last update.

TerraformでAWS Provider Versionが低くて困った話

Posted at

この記事は何?

Terraformでコード管理しているAWS環境にて、Aurora Serverlessのリソースを追加作成しようとした際に遭遇したエラーとその対応メモ。

Terraform環境

$ terraform --version
Terraform v0.12.29
+ provider.aws v3.37.0

経緯

AuroraServerlessのコーディング後、planはOKだったため、問題ないと思ったが、applyするとエラーに遭遇した。serverlessv2_scaling_configurationはサポートされていないとのこと。

│ Error: Unsupported block type
│ 
│   on rds.tf line 115, in resource "aws_rds_cluster" "serverless-stg-db-cluster":
│  115:   serverlessv2_scaling_configuration {
│ 
│ Blocks of type "serverlessv2_scaling_configuration" are not expected here.

確認するとserverlessv2_scaling_configurationは、AWS Provider4.12.0から追加されたリソースタイプのため、現在のAWS Providerのv3.37.0では実行できないことが判明した。

4.12.0 (April 28, 2022)
ENHANCEMENTS:
resource/aws_rds_cluster: Add serverlessv2_scaling_configuration argument to support Aurora Serverless v2 (#24363)

公式ドキュメントでもv3.37.0にはserverlessv2_scaling_configurationのリソースタイプが存在しないので、エラーになるのは必然でした。。
https://registry.terraform.io/providers/hashicorp/aws/3.37.0/docs/resources/rds_cluster

対応

AWS Providerのバージョン変更

provider "aws" {
- version = "~> 3.37.0"
+ version = "~> 4.12.0"
}

バージョンアップを適用させようとするも、今度はv4.12.0のプラグインがないと怒れられる。

$ terraform init -upgrade
Initializing provider plugins...
- Checking for available provider plugins...

No provider "aws" plugins meet the constraint "~> 4.12.0".

The version constraint is derived from the "version" argument within the
provider "aws" block in configuration. Child modules may also apply
provider version constraints. To view the provider versions requested by each
module in the current configuration, run "terraform providers".

To proceed, the version constraints for this provider must be relaxed by
either adjusting or removing the "version" argument in the provider blocks
throughout the configuration.

terraformのv0.12.29との互換性が影響しているのかと思い、v0.12.31にアップグレードさせるとProvider Versionをv4.12.1にアップグレードできた。

$ terraform --version
Terraform v0.12.31
+ provider.aws v4.12.1

applyが実行されエラー解消、Aurora Serverlessのリソースも無事作成できた。

最後に

terraformやAWS Providerのバージョンが低いことで、AWSのリソース作成のエラーになることが経験できた。
公式ドキュメントで、サポートされているリソースタイプか事前に確認することと、planが通っても安心してはいけないことを学んだ。

2
1
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
2
1