1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

terraform 0.12checklistを実行してGoogleProviderのバージョンを段階的に上げる

Posted at

terraformを0.12以上にアップデートしたい

現在使用しているterraformは0.11.4とする。
なお、今回実行したい 0.12checklist コマンドは0.12にはなく、また、0.11.xであっても、0.11.14が望ましい。

Upgrading to Terraform 0.12 - Terraform by HashiCorp

理由はこちらの公式情報のとおり。
Pre-upgrade Checklistにあるとおり、事前確認ができる。
ここでの警告に対応後、terraformを0.12にあげて terrafrom init する。

その後、今度は0.12.x付属の terraform 0.12upgrade を使うとよい。
※ こちらの実行は別記事で。

providerのバージョンアップも必要

今回はGoogle providerを使っていたのでproviderのバージョンアップも視野にいれた。
なお、低すぎると今回のように

Terraform Google Provider 2.0.0 Upgrade Guide - Terraform by HashiCorp

1.2.0 -> 2.0.0 -> 2.5.0以上を段階的に意識する必要がある。


terraform 0.12checklist

terraform付属のコマンドに0.12以上にバージョンアップするための準備コマンドがある。

terraform_help
All other commands:
    0.12checklist      Checks whether the configuration is ready for Terraform v0.12
terraform(0.11.4)
% terraform 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 "google" to version 2.17.0 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.17.0"

Taking these steps before upgrading to Terraform v0.12 will simplify the upgrade process by avoiding syntax errors and other compatibility problems.
  • Upgrade provider "google" to version 2.17.0 or newer.

テスト実行した環境でGCPを使用。
Google Cloud StorageGoogle Cloud IAM を管理していた。
このバージョン以上にアップデートかつ固定したほうがよい。
(0.11.14では想定していないとういこととみる。)

terraform moduleのバージョンを見る

まずは現在のmoduleのバージョン。

% terraform -v
Terraform v0.11.14
+ provider.google v1.20.0

Your version of Terraform is out of date! The latest version
is 0.12.10. You can update by downloading from www.terraform.io/downloads.html

provider.google v1.20.0

Provider: Google Cloud Platform - Terraform by HashiCorp

公式情報より、0.12意識であれば2.5.0以上が必要そうだ。
terraform-provider-google/CHANGELOG.md at master · terraform-providers/terraform-provider-google

2.5.0 より Terraform 0.12 supportとある。

openstack providerをバージョンアップする

基本はバージョンを指定してから terraform initしたほうがよい。
つまりは管理したほうがよい。
方法はこちらにまとめた。

Terraformの使用バージョンを固定する - Qiita

providerに以下設定をしておく。
しかし、その前にバージョンが低すぎるので段階的にアップデートする必要ありだった。

google provider 1.2.0 -> 2.0.0

Terraform Google Provider 2.0.0 Upgrade Guide - Terraform by HashiCorp

example
provider "google" {
  # ... other configuration ...

  version = "~> 1.20.0"
}

公式よりこのような指定から。今回の環境はこの設定をしていた。

これを

provider "google" {
  # ... other configuration ...

  version = "~> 2.0.0"
}

まずはこのバージョンにするところから。
設定は以下の差分となった。

--- google_provider.tf
+++ google_provider.tf
@@ -1,5 +1,5 @@
 provider "google" {
-  version = "~> 1.20.0"
+  version = "~> 2.0.0"
   project = "goope-170607"
   region  = "asia-northeast1"
 }

この状態で terraform init する。

% terraform init

Initializing the backend...

Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "google" (2.0.0)...

Terraform has been successfully initialized!

今回は無事にアップデートされた。
問題は terraform plan
この変更によるつまずきどころは段階的に対応する。

なお、このとき注意なのがGoogle IAMに大幅な変更が加わり、未管理だった設定もインポート対象となるため、活用している人はご注意。

google provider 2.0.0 -> 2.5.0(2.7.0以上にする)

terraform0.12対応のversionにアップデートする。
先ほどと同様で今度は 2.5.0以上 とすればよい。

1
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?