[祝]TerraformがついにGAになりました

2021.06.08

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

Terraform 1.0が先程発表されました。つまりGA(Generally Available)です。

何が変わったの?

特に変更点はありません。 CHANGELOGに以下記載があります。

Terraform v1.0.0 intentionally has no significant changes compared to Terraform v0.15.5. You can consider the v1.0 series as a direct continuation of the v0.15 series; we do not intend to issue any further releases in the v0.15 series, because all of the v1.0 releases will be only minor updates to address bugs.

(筆者訳)Terraform v1.0.0 にはv0.15.5(=1つ前のバージョン)と比較して意図的に大きな変更を加えていません。v1.0シリーズをv0.15シリーズから直接続くものと捉えていただいて構いません。v1.0リリースはすべて、バグに対処するマイナーアップデートになるので、v0.15シリーズでこれ以上のリリースをする予定はありません。

次のマイナーリリースになるv1.1.0で新機能が追加されるそうです。

0.15についての主要な変更点は先日まとめましたので以下をご覧ください。以下では0.15.4までしか言及していませんが、その後の 0.15.5はBug Fixのみでした。

さて、1.0になって特に変更点はないと言いましたが、公式ブログでは以下の点が言及されていました。

Terraform Stateの相互運用性の向上

Terraformのバージョン 0.14.x, 0.15.x, 1.0.x間でStateファイルに相互互換性があります。また、Remote State Data SourceのVersion間互換も0.12.30, 0.13.6, 0.14.0, 0.15.0, 1.0.xの間であります。これは例えば 1.0のTerraformから、0.12.30のStateファイルを参照してその中のリソースの情報を参照できるということです。つまり、古いコードは残したまま、新しく作るところだけ最新バージョンにしても、古いコードと連携することが簡単になります。

Upgradeエクスペリエンスの改良

v0.15を使っている場合は、v1.x を使用するために、アップグレードツール、リファクタリング、またはその他の変更を行う必要はありません。

メンテナンス期間の拡張

今後の1.xのリリースには最低18ヶ月のメンテナンス期間が設けられます。

じゃあGAに何の意味があるの?

Terraform提供元会社であるHashiCorpには、プロダクトをGAにするにあたり4つの基準があるそうです。今回すべての基準を満たしたと判断できたので、v1.0を発表することにしたそうです。

  1. 長年プロダクション環境下で広くデプロイされていること
  2. 主要なユースケースが理解され、よくサポートされていること
  3. 明確に定義されたユーザーエクスペリエンス
  4. プロダクトの技術的なアーキテクチャーが成熟しており安定していること

やってみた

v0.15でVPCをひとつ作成するだけのコードをもっていたので、これを1.0.0に変更してみたいと思います。

tfenvを使っているので、プロジェクトルートに置いている.terraform-versionの中身を更新します。

- 0.15.2
+ 1.0.0

Terraformのコードも修正します。といってもrequired_versionだけですね。

 terraform {
-  required_version = "~> 0.15.1"
+  required_version = "~> 1.0.0"
 
   backend "s3" {
     bucket = "kazue-terraform-sandbox"
     key    = "hoge/main.tfstate"
     region = "ap-northeast-1"
   }
 
   required_providers {
     aws = {
       source  = "hashicorp/aws"
       version = "3.38.0"
     }
   }
 }
 
 provider "aws" {
   region = "ap-northeast-1"
 }
 
 resource "aws_vpc" "tokyo-vpc" {
   cidr_block = "10.0.0.0/16"
   tags = {
     Name = "test"
   }
 }

init --upgradeします。

% terraform init --upgrade
version '1.0.0' is not installed (set by /Users/kazue.masaki/project/kazue-sandboxes/terraform015/015/.terraform-version). Installing now as TFENV_AUTO_INSTALL==true
Installing Terraform v1.0.0
Downloading release tarball from https://releases.hashicorp.com/terraform/1.0.0/terraform_1.0.0_darwin_amd64.zip
########################################################################################################################### 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.0.0/terraform_1.0.0_SHA256SUMS
No keybase install found, skipping OpenPGP signature verification
Archive:  tfenv_download.LREX6s/terraform_1.0.0_darwin_amd64.zip
  inflating: /usr/local/Cellar/tfenv/2.0.0/versions/1.0.0/terraform  
Installation of terraform v1.0.0 successful. To make this your default version, run 'tfenv use 1.0.0'

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/aws versions matching "3.38.0"...
- Using previously-installed hashicorp/aws v3.38.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.

applyします。

 % terraform apply         

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  + create

Terraform will perform the following actions:

  # aws_vpc.tokyo-vpc will be created
  + resource "aws_vpc" "tokyo-vpc" {
      + arn                              = (known after apply)
      + assign_generated_ipv6_cidr_block = false
      + cidr_block                       = "10.0.0.0/16"
      + default_network_acl_id           = (known after apply)
      + default_route_table_id           = (known after apply)
      + default_security_group_id        = (known after apply)
      + dhcp_options_id                  = (known after apply)
      + enable_classiclink               = (known after apply)
      + enable_classiclink_dns_support   = (known after apply)
      + enable_dns_hostnames             = (known after apply)
      + enable_dns_support               = true
      + id                               = (known after apply)
      + instance_tenancy                 = "default"
      + ipv6_association_id              = (known after apply)
      + ipv6_cidr_block                  = (known after apply)
      + main_route_table_id              = (known after apply)
      + owner_id                         = (known after apply)
      + tags                             = {
          + "Name" = "test"
        }
      + tags_all                         = {
          + "Name" = "test"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_vpc.tokyo-vpc: Creating...
aws_vpc.tokyo-vpc: Creation complete after 2s [id=vpc-0c533b9e2aa898dd0]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

特に問題なく完了しました。簡単ですね。0.15を使われている方はノーストレスで移行できるかと思います。試してませんが0.14のStateファイルも互換性があるので、0.14からの移行も問題なくできるかと思います。

参考