環境
- tfevnいれてる
アップグレード方法
- 0.12系から一気に0.15系へアップグレードすることはできないみたい
- 0.12→0.13→0.14→0.15と順を追っていく必要がある
v0.12.29→v0.13.7
現在
.terraform-version
.terraform-version
0.12.29
変更する
.terraform-version
.terraform-version
0.13.7
providerの箇所
- 0.12系の書き方に住居
provider.tf
provider "aws" {
region = var.region
version = "= 3.1"
profile = "vamdemic"
}
terraform {
backend "s3" {
bucket = "vamdemic-terraform"
region = "ap-northeast-1"
profile = "terraformer"
key = "terraform/terraform.tfstate"
encrypt = true
}
}
upgrade実行
rm -fr .terraform
terraform init -upgrade
planして、リソースの差分などが出たら手動で直す
terraform plan
v0.13.7→0.14.11
.terraform-version
.terraform-version
0.14.11
upgrade実行
terraform init -upgrade
エラー発生
Warning: Version constraints inside provider configuration blocks are deprecated
on main.tf line 3, in provider "aws":
3: version = "= 3.1"
Terraform 0.13 and earlier allowed provider version constraints inside the
provider configuration block, but that is now deprecated and will be removed
in a future version of Terraform. To silence this warning, move the provider
version constraint into the required_providers block.
Error: Invalid legacy provider address
This configuration or its associated state refers to the unqualified provider
"aws".
You must complete the Terraform 0.13 upgrade process before upgrading to later
versions.
文法が変わっているので書き換えてあげる
provider.tf
provider "aws" {
region = local.region
profile = "vamdemic"
}
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "= 3.36.0"
}
}
backend "s3" {
bucket = "vamdemic-terraform"
region = "ap-northeast-1"
profile = "terraformer"
key = "terraform/terraform.tfstate"
encrypt = true
}
}
providerを書き換える
URLというか名称が変わっているらしいので
terraform state replace-provider registry.terraform.io/-/aws hashicorp/aws
再度upgrade実行
terraform init -upgrade
planして、リソースの差分などが出たら手動で直す
terraform plan
v0.14.11→v0.15.3
.terraform-version
.terraform-version
0.15.3
upgrade実行
terraform init -upgrade
planして、リソースの差分などが出たら手動で直す
terraform plan