
確認したいこと
module に対して alias 名を指定した provider を付与している場合に、これを削除するとどうなるのかを検証したい。
モチベーションとしては公式サイトを見ると provider を明示的に渡す必要が無いので、それにならいたい感じ。
結論
alias を削除しても、plan / apply などに差分はでないが、terraform state ファイル内の provider の記載が変更になる。
環境
❯ terraform version Terraform v1.0.6 on darwin_arm64 + provider registry.terraform.io/hashicorp/google v4.3.0
ディレクトリレイアウト
. ├── main.tf ├── terraform.tfstate └── test └── test.tf
各ファイル
terraform {
required_version = "~> 1.0.6"
backend "local" {}
}
provider "google" {
alias = "test1"
project = "hogehoge"
region = "asia-northeast1"
}
module "test" {
source = "./test"
providers = {
google = google.test1
}
}
terraform {
required_providers {
google = {
version = "~> 4.3.0"
}
}
}
resource "google_compute_global_address" "this" {
name = "test-address"
}
試す
上記のファイルを使ってリソースを作成した後に、以下の修正を加える。
内容としては呼び出し元で required_provider で定義して、alias の削除や明示的に provider を渡す設定を削除する。
terraform {
required_version = "~> 1.0.6"
required_providers {
google = {
version = "~> 4.3.0"
}
}
backend "local" {}
}
provider "google" {
# alias = "test1"
project = "hogehoge"
region = "asia-northeast1"
}
module "test" {
source = "./test"
# providers = {
# google = google.test1
# }
}
# terraform {
# required_providers {
# google = {
# version = "~> 4.3.0"
# }
# }
# }
resource "google_compute_global_address" "this" {
name = "test-address"
}
ファイルを修正後 terraform plan / apply / refresh をしたが、特に差分は出力されなかった。
ただし terraform.state ファイルにて以下の差分が存在していた。
4c4 < "serial": 2, --- > "serial": 1, 13c13 < "provider": "provider[\"registry.terraform.io/hashicorp/google\"]", --- > "provider": "provider[\"registry.terraform.io/hashicorp/google\"].test1",