Open3

既存リソースのterraform化

hamaguchihamaguchi
  1. terraform importでtfstateを更新
  2. tfファイルを更新
  3. terraform planで更新がないことを確認
hamaguchihamaguchi

既存のALBのterraform化

適当にALB作る

terraformerのインストール

$ brew install terraformer

対応しているリソース一覧

https://github.com/GoogleCloudPlatform/terraformer/blob/master/docs/aws.md

provider用意する

provider "aws" {
  region = "ap-northeast-1"
}
$ terraform init
$ terraformer import aws --regions=ap-northeast-1 --resources=alb --profile ""  

profileの設定のバグ?

https://github.com/GoogleCloudPlatform/terraformer/issues/940#issuecomment-870940551

やったぜ

upgrade

$ terraform state replace-provider -auto-approve "registry.terraform.io/-/aws" "hashicorp/aws"

https://github.com/GoogleCloudPlatform/terraformer#migration-state-version

tfファイルが生成された場所に移動してterraform init
terraform planで差分がないことを確認

  • before

  • after
$ terraform apply

完了