What is the Correct Terraform Provider Configuration for Google Cloud Platform Resources with Beta Arguments

0 votes

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?

Apr 5, 2022 in GCP by Rahul
• 3,380 points
2,320 views

1 answer to this question.

0 votes
You should use both google and google-beta providers. It is safe to use both these providers within the same provders.tf.

Terraform sends requests for any resource requiring the google-beta provider to the beta endpoint https://. . .googleapis.com/v1beta1/. Using the google beta provider is similar to using beta gcloud group.. .;
answered Apr 6, 2022 by Korak
• 5,820 points

Related Questions In GCP

0 votes
1 answer

where is drop down menu for the google cloud platform

It is important that you are signed ...READ MORE

answered Sep 20, 2019 in GCP by Sirajul
• 59,230 points
1,745 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
0 answers

organization won't appear in the Google Cloud Platform Console as a choice for migration

I'm trying to migrate an existing Google ...READ MORE

Mar 2, 2022 in GCP by Rahul
• 2,120 points
422 views
0 votes
1 answer

Using the Google Cloud Platform SDK CLI to List all Active Resources Under a Given Project

For a specific organization, folder, or project, ...READ MORE

answered Nov 7, 2022 in GCP by Tejashwini
• 3,820 points
867 views
0 votes
2 answers
0 votes
1 answer

Is it possible to change the region of a Google Cloud Platform project?

There is no such thing as a ...READ MORE

answered Apr 6, 2022 in GCP by Korak
• 5,820 points
3,030 views
0 votes
1 answer

What is the difference between Google Cloud Dataflow and Google Cloud Dataproc?

Cloud Dataflow and Dataproc can both be ...READ MORE

answered Apr 6, 2022 in GCP by Korak
• 5,820 points
2,314 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP