公式ドキュメント
公式ドキュメントに詳しく書いてあります。
じっくり作業できる方は公式ドキュメントに従って作業してください。
(このメモも公式ドキュメントを見て作業したものです)
Upgrading to Terraform v0.12
概要
- 0.12からHCLの構文が変わる
- アップグレード前に実行するチェックリストツールが用意されている
- 自動アップグレードツールが用意されている
手順
- Terraform v0.11.14とv0.12.0を用意しておく
- tfファイルをv0.11.14対応版にしておく
-
terraform apply
で差分が無い状態にしておく - v0.11.14のアップグレード前チェックリストツールでチェックする
- プロバイダのバージョンアップ(0.12対応版)を行う
- tfファイルのバージョンを変更して
terraform init
する
- tfファイルのバージョンを変更して
- プロバイダのバージョンアップ(0.12対応版)を行う
- v0.12.0の自動アップグレードツールを実行する
手順のメモ
Terraform v0.11.14とv0.12.0を用意しておく
両方のバージョンをダウンロードし、terraform11とterraform12としてカレントディレクトリに置いた。
https://releases.hashicorp.com/terraform/0.12.0/
https://releases.hashicorp.com/terraform/0.11.14/
tfenvを使っても良い。
v0.11.14のアップグレード前チェックリストツールでチェックする
問題なし
$ ~/terraform11 0.12checklist
Looks good! We did not detect any problems that ought to be
addressed before upgrading to Terraform v0.12.
This tool is not perfect though, so please check the v0.12 upgrade
guide for additional guidance, and for next steps:
https://www.terraform.io/upgrade-guides/0-12.html
templateプロバイダを対応バージョンに更新する必要あり
$ ~/terraform11 0.12checklist
After analyzing this configuration and working directory, we have identified some necessary steps that we recommend you take before upgrading to Terraform v0.12:
- [ ] Upgrade provider "template" to version 2.1.2 or newer.
No currently-installed version is compatible with Terraform 0.12. To upgrade, set the version constraint for this provider as follows and then run `terraform init`:
version = "~> 2.1.2"
Taking these steps before upgrading to Terraform v0.12 will simplify the upgrade process by avoiding syntax errors and other compatibility problems.
v0.12.0の自動アップグレードツールを実行する
googleプロバイダを対応バージョンに更新する必要あり
$ ~/terraform12 0.12upgrade
This command will rewrite the configuration files in the given directory so
that they use the new syntax features from Terraform v0.12, and will identify
any constructs that may need to be adjusted for correct operation with
Terraform v0.12.
We recommend using this command in a clean version control work tree, so that
you can easily see the proposed changes as a diff against the latest commit.
If you have uncommited changes already present, we recommend aborting this
command and dealing with them before running this command again.
Would you like to upgrade the module in the current directory?
Only 'yes' will be accepted to confirm.
Enter a value: yes
-----------------------------------------------------------------------------
Error: error resolving providers:
- provider.google: no suitable version installed
version requirements: "2.6.0"
versions installed: none
tfファイルのバージョンを変更してterraform init
しておく
$ ~/terraform12 init
Initializing the backend...
Initializing provider plugins...
- Checking for available provider plugins...
- Downloading plugin for provider "google" (terraform-providers/google) 2.7.0...
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
アップグレード成功
$ ~/terraform12 0.12upgrade
This command will rewrite the configuration files in the given directory so
that they use the new syntax features from Terraform v0.12, and will identify
any constructs that may need to be adjusted for correct operation with
Terraform v0.12.
We recommend using this command in a clean version control work tree, so that
you can easily see the proposed changes as a diff against the latest commit.
If you have uncommited changes already present, we recommend aborting this
command and dealing with them before running this command again.
Would you like to upgrade the module in the current directory?
Only 'yes' will be accepted to confirm.
Enter a value: yes
-----------------------------------------------------------------------------
Upgrade complete!
The configuration files were upgraded successfully. Use your version control
system to review the proposed changes, make any necessary adjustments, and
then commit.