Stay organized with collections Save and categorize content based on your preferences.
To apply your Terraform configuration in a Google Cloud project, complete the steps in the following sections.
Prepare Cloud ShellSet the default Google Cloud project where you want to apply your Terraform configurations.
You only need to run this command once per project, and you can run it in any directory.
export GOOGLE_CLOUD_PROJECT=PROJECT_ID
Environment variables are overridden if you set explicit values in the Terraform configuration file.
Each Terraform configuration file must have its own directory (also called a root module).
.tf
extension—for example main.tf
. In this tutorial, the file is referred to as main.tf
.
mkdir DIRECTORY && cd DIRECTORY && touch main.tf
If you are following a tutorial, you can copy the sample code in each section or step.
Copy the sample code into the newly created main.tf
.
Optionally, copy the code from GitHub. This is recommended when the Terraform snippet is part of an end-to-end solution.
terraform init
Optionally, to use the latest Google provider version, include the -upgrade
option:
terraform init -upgrade
terraform plan
Make corrections to the configuration as necessary.
yes
at the prompt:
terraform apply
Wait until Terraform displays the "Apply complete!" message.
To reformat your Terraform configuration in the standard style, enter the following command:
terraform fmtValidate
To check whether your configuration is valid, enter the following command:
terraform validateDelete changes
Remove resources previously applied with your Terraform configuration by running the following command and entering yes
at the prompt:
terraform destroySpecify the project ID
If you run the export GOOGLE_CLOUD_PROJECT
command, most resources can infer the project_id
.
Some resources, such as project_iam_*
, cannot infer the project ID. As a workaround, some samples use the data "google_project"
data source. You can replace this data source with the project ID string or a variable.
For a sample that uses this workaround, see sql_instance_iam_condition.
What's nextExcept as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-02 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-02 UTC."],[[["Terraform configurations are applied within a designated Google Cloud project, initiated by setting the `GOOGLE_CLOUD_PROJECT` environment variable in Cloud Shell."],["Each Terraform configuration requires its own directory, where you will need to create a `.tf` file, such as `main.tf`, and then initialize Terraform using the `terraform init` command."],["Before applying changes, you must use the `terraform plan` command to review the planned resource changes and verify that the resources Terraform is going to create or update match your expectations."],["To apply changes to your Google Cloud project, use the `terraform apply` command and confirm the action, or use `terraform destroy` to remove previously applied resources."],["You can utilize the `terraform fmt` and `terraform validate` commands to reformat and check if your Terraform configuration is valid, respectively."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4