Article · part of a guide
Getting Started with the Google Cloud Terraform Provider
How to configure and authenticate the Google Cloud provider for Terraform, with examples.

Key takeaways
- The Terraform Google Cloud provider gives engineers a common declarative interface to define and deploy GCP resources through the GCP API.
- The provider ships in two variants: google for the generally available version and google-beta for testing upcoming GCP features.
- By default the provider authenticates using Application Default Credentials via gcloud; you can also use a service account key file, environment variables, or an OAuth 2.0 access token.
- Setting project, region, and zone at the provider level supplies sensible defaults, while default_labels applies a label set to every resource the provider creates.
The Google Cloud provider in brief
The Terraform provider for Google Cloud Platform lets you define, configure, and deploy resources in a GCP account. Like every Terraform provider, the GCP provider gives engineers a common interface to the GCP API. Because the interface is shared, you can work across several clouds without learning a separate, provider-specific configuration language for each one (AWS CloudFormation, Azure Bicep, and so on).
The Google provider is a little different in that it ships in two versions:
google: the generally available versiongoogle-beta: the beta version
Having two variants lets engineers and organisations try upcoming GCP features early and get ready for a change before it lands in the GA provider.
Configuration
I've split configuration into two parts: authentication and general configuration.
Authentication
Like most providers on the Terraform Registry, this one can be configured and authenticated in several ways. By default, the provider tries to authenticate with GCP using User Application Default Credentials (ADCs) via the gcloud CLI utility.
The provider exposes the credentials argument so you can point it at a service account key file. This file must be in JSON format. You can also use environment variables, listed here in order of precedence:
GOOGLE_CREDENTIALSGOOGLE_CLOUD_KEYFILE_JSONGOOGLE_KEYFILE_JSON
Authentication is automatically available when running Terraform commands if:
- they are being run on a GCE instance
- or on a workstation where the
gcloud auth application-default logincommand has been executed.
These are the simplest ways to authenticate with GCP.
On top of those credential-based approaches, you can also authenticate with an OAuth 2.0 access token. You set this token with the access_token property or the GOOGLE_OAUTH_ACCESS_TOKEN environment variable. You can learn more about generating an access token here.
General Configuration
The provider lets you set values like:
projectregionzonedefault_labels
These aren't all the options, but they're the most useful.
Setting the project at the provider level means engineers don't need to set the project on each resource. You can still override the project at a resource level. Both region and zone let you set the defaults for where resources (e.g., virtual machines) get provisioned. The most useful option, in my opinion, is default_labels, which applies a set of default labels to every resource this instance of the provider creates. In other providers, that's not so easy to do.
Examples
For both examples, assume that the gcloud auth application-default login command has been run.
Here's the provider in its most basic form:
provider "google" {
project = "example"
region = "australia-southeast2"
zone = "australia-southeast2-b"
}This sets the project, region, and zone properties, so we don't have to configure them on each resource.
The next example runs an instance of both the GA and Beta providers. This lets you configure resources differently, or use different resources entirely.
provider "google" {
project = "example"
region = "australia-southeast2"
zone = "australia-southeast2-b"
}
provider "google-beta" {
project = "example"
region = "australia-southeast2"
zone = "australia-southeast2-b"
}
resource "google_container_cluster" "ga" {
provider = google
name = "ga-cluster"
initial_node_count = 1
timeouts {
create = "30m"
update = "40m"
}
}
resource "google_container_cluster" "beta" {
provider = google-beta
name = "beta-cluster"
initial_node_count = 1
timeouts {
create = "30m"
update = "40m"
}
}This code has two instances of google_container_cluster. The first uses the GA version of the GCP provider (google). The second uses the Beta version of the GCP provider (google-beta). The example doesn't show any configuration differences between GA and Beta for this resource type, but if there were any, this is how you'd handle them.
Where to go next
For authentication, the main mechanisms are ADCs and temporary OAuth access tokens. I generally recommend ADCs configured automatically via GCE instance identity. For general configuration, set project, region, zone, and default_labels at the provider level so every resource the Terraform Google provider creates starts from sensible defaults. For all the details on the provider configuration, read through the Google Provider Configuration Reference.
Frequently asked questions
How do I authenticate the Terraform Google Cloud provider?
By default the provider uses Application Default Credentials via the gcloud CLI, so running gcloud auth application-default login on a workstation, or running Terraform on a GCE instance, is the simplest setup. You can also point the credentials argument at a JSON service account key file, use environment variables like GOOGLE_CREDENTIALS, or supply an OAuth 2.0 access token via access_token or GOOGLE_OAUTH_ACCESS_TOKEN.
What is the difference between the google and google-beta Terraform providers?
The google provider is the generally available version, while google-beta exposes upcoming GCP features that haven't reached GA yet. You can run both in the same configuration and set provider = google-beta on specific resources to try new features early and prepare before they land in the GA provider.
How do I set default project, region, and zone in the Google Terraform provider?
Set project, region, and zone in the provider block so you don't have to repeat them on every resource; you can still override them at the resource level. The default_labels option is also useful because it applies a set of labels to every resource that instance of the provider creates.
Which Google Cloud provider environment variables does Terraform check?
For credentials the provider checks GOOGLE_CREDENTIALS, GOOGLE_CLOUD_KEYFILE_JSON, and GOOGLE_KEYFILE_JSON, in that order of precedence. An OAuth 2.0 access token can be supplied through GOOGLE_OAUTH_ACCESS_TOKEN instead of a key file.
About the author

solutions engineer at Scalr
Brendan Thompson is a solutions engineer at Scalr, specializing in Terraform and cloud infrastructure.
Part of this guide
16 sheets
Terraform Providers: Complete Configuration and Management Guide
- How to Manage GitLab with Terraform
- How to use the Terraform Okta Provider
- Mastering Kubernetes with Terraform: A Provider Deep Dive
- Top 10 Most Popular Terraform Providers [2026]
- What are Terraform Lock Files
- AzureRM Terraform Provider Overview
- Kubernetes Terraform Provider
- Terraform Random Provider
- How to use the Bitbucket Terraform Provider
- How to use Terraform or OpenTofu to Manage Datadog
- Getting Started with Terraform Providers
- How to use Terraform to manage Okta
- New Feature: Provider Configurations
- Using A Custom Terraform Provider In Scalr