Overview of Terraform on Google Cloud

Hashicorp Terraform is an Infrastructure as code (IaC) tool that lets youprovision and manage cloud infrastructure. Terraform provides plugins calledproviders that lets you interact with cloud providers and otherAPIs. You can use theTerraform provider for Google Cloud toprovision and manage Google Cloud infrastructure.

Benefits of using Terraform

This section explains some of the benefits of using Terraform to provision andmanage Google Cloud infrastructure:

  • Terraform is the most commonly used tool to provision and automateGoogle Cloud infrastructure. You can use theGoogle Cloud providerto configure and manage all Google Cloud resources using the samedeclarative syntax and tooling.
  • Terraform lets you specify your preferred end state for your infrastructure.You can then deploy the same configuration multiple times to createreproducible development, test, and production environments.
  • Terraform lets you generate an execution plan that shows what Terraform willdo when you apply your configuration. This lets you avoid any surprises whenyou modify your infrastructure through Terraform.
  • Terraform lets you package and reuse common code in the form ofmodules.Modules present standard interfaces for creating cloud resources. Theysimplify projects by increasing readability and allow teams to organizeinfrastructure in readable blocks. Additionally, Google Cloudpublishes a number of opinionated deployable modules asblueprints andgetting-started examples asJump StartSolutions.
  • Terraform records the current state of your infrastructure and lets youmanage state effectively. The Terraform state file keeps track of allresources in a deployment.

Using Terraform

Terraform has a declarative and configuration-oriented syntax, which you can usetoauthor the infrastructurethat you want to provision. Using this syntax, you'll define your preferredend-state for your infrastructure in aTerraform configuration file. You'll thenuse theTerraform CLI to provisioninfrastructure based on the configuration file.

The following steps explain how Terraform works:

  1. You describe the Google Cloud infrastructure you want to provisionin a Terraform configuration file. You don't need to author codedescribinghow to provision this configuration.
  2. You run theterraform plan command, which evaluates your configurationand generates an execution plan. You can review the plan and make changes asneeded.
  3. Then, you run theterraform apply command, which performs the followingactions:
    • It provisions your infrastructure based on your execution plan by invokingthe corresponding Google Cloud APIs in the background.
    • It creates aTerraform state file, which is a JSON formatted mapping ofresources in your configuration file to the resources in thereal world infrastructure. Terraform uses this file to know the lateststate of your infrastructure, and to determine when to create, update, anddestroy resources.
  4. Subsequently, when you runterraform apply, Terraform uses the mapping inthe state file to compare the existing infrastructure to the code, and makeupdates as necessary:
    • If a resource object defined in the configuration file does not exist inthe state file, Terraform creates it.
    • If a resource object exists in the state file, but has a differentconfiguration from your configuration file, Terraform updates theresource to match your configuration file.
    • If a resource object in the state file matches your configurationfile, Terraform leaves the resource unchanged.

Google Cloud providers

There are two providers that let you provision and manage Google Cloudinfrastructure:

  • google: Use this provider to provision and manageGoogle Cloud APIs.
  • google-beta: Use this provider to provision and manageGoogle Cloud beta APIs.

For instructions on using these providers, see theGoogle Cloud provider configuration reference.

google andgoogle-beta providers are developed using a tool calledMagic Modules. Magic Modules allows contributors to make changes against asingle codebase and develop bothgoogle andgoogle-beta providerssimultaneously.

You can contribute to the Google Cloud providers using MagicModules by following the instructions in theMagic Modules contribution guide.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-18 UTC.