Terraforming any Google Cloud Platform (GCP) resource defined by any beta arguments requires the google-beta provider. Should the google-beta provider be used instead of or in tandem with the google provider?
In other words, say a certain Google Kubernetes Engine (GKE) cluster $GKE_CLUSTER_NAME exists within a GCP project $GCP_PROJECT_NAME:
gcloud container clusters list \
--format="value(name)" \
--project=$GCP_PROJECT_NAME
#=>
. . .
$GKE_CLUSTER_NAME
. . .
with Config Connector enabled:
gcloud container clusters describe $GKE_CLUSTER_NAME \
--format=“value(addonsConfig.configConnectorConfig.enabled)” \
--zone=$GKE_CLUSTER_ZONE
#=>
True
Terraforming $GKE_CLUSTER_NAME requires a google_container_cluster resource definition within container_cluster.tf that includes both the config_connector_config argument (within the addons_config block; more here) and the provider argument (missing from the official reference documentation):
resource "google_container_cluster" "test" {
addons_config {
config_connector_config {
enabled = true
}
. . .
}
. . .
provider = google-beta
. . .
}
but does not require a google-beta provider definition in providers.tf:
provider "google" {
project = ". . ."
}
terraform {
required_providers {
google = {
version = "~> 3.83.0"
}
}
}
This and the lack of a provider argument from other resource definitions, such as a google_container_node_pool found in container_node_pool.tf, results in the following output from the providers command:
terraform providers
Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/google] ~> 3.83.0
└── provider[registry.terraform.io/hashicorp/google-beta]
Providers required by state:
provider[registry.terraform.io/hashicorp/google]
provider[registry.terraform.io/hashicorp/google-beta]
after an apply command has refreshed the terraform.tfstate state file.
Is the more correct and less error-prone method of Terraforming GCP resources with beta arguments? Or, should I run a replace-provider subcommand instead:
terraform state replace-provider \
-auto-approve \
"hashicorp/google" \
"hashicorp/google-beta"
#=>
Terraform will perform the following actions:
~ Updating provider:
- registry.terraform.io/hashicorp/google
+ registry.terraform.io/hashicorp/google-beta
Changing 2 resources:
google_container_node_pool.$GKE_NODE_POOL_NAME
Successfully replaced provider for 1 resources.
and modify providers.tf:
provider "google-beta" {
project = ". . ."
}
terraform {
required_providers {
google-beta = {
version = "~> 3.83.0"
}
}
}
so that the output of the providers command is:
terraform providers
#=>
Providers required by configuration:
.
└── provider[registry.terraform.io/hashicorp/google-beta] ~> 3.83.0
Providers required by state:
provider[registry.terraform.io/hashicorp/google-beta]
after an apply command refreshes the state in terraform.state?