This page describes the steps to install and configure Terraform for Google Cloud in Cloud Shell and in a local shell. Cloud Shell is an interactive shell environment for Google Cloud that lets you learn and experiment with Google Cloud and manage your projects and resources from your web browser.
Cloud Shell
To use an online terminal with the gcloud CLI and Terraform already set up, activate Cloud Shell:
At the bottom of this page, a Cloud Shell session starts and displays a command-line prompt. It can take a few seconds for the session to initialize.
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
To provision Google Cloud resources using Terraform, you must enable the corresponding APIs:
gcloud services enable "API"
Replace API with the API you want to enable.
To provision Google Cloud resources using Terraform, you require Identity and Access Management roles that are specific to these resources.
- From the IAM roles reference page, determine the required role(s).
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
gcloud projects add-iam-policy-binding PROJECT_ID --member="USER_IDENTIFIER" --role=ROLE
- Replace
PROJECT_ID
with your project ID. -
Replace
USER_IDENTIFIER
with the identifier for your user account. For example,user:myemail@example.com
. - Replace
ROLE
with each individual role.
- Replace
Run the following command to verify that Terraform is available:
terraform
The output should be similar to the following:
Usage: terraform [global options] <subcommand> [args] The available commands for execution are listed below. The primary workflow commands are given first, followed by less common or more advanced commands. Main commands: init Prepare your working directory for other commands validate Check whether the configuration is valid plan Show changes required by the current configuration apply Create or update infrastructure destroy Destroy previously-created infrastructure
Local shell
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
Enable the required APIs:
gcloud services enable "API"
Where API is the API you want to enable.
To provision Google Cloud resource using Terraform, you require Identity and Access Management roles that are specific to these resources.
- From the IAM roles reference page, determine the required role(s).
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
gcloud projects add-iam-policy-binding PROJECT_ID --member="USER_IDENTIFIER" --role=ROLE
- Replace
PROJECT_ID
with your project ID. -
Replace
USER_IDENTIFIER
with the identifier for your user account. For example,user:myemail@example.com
. - Replace
ROLE
with each individual role.
- Replace
Install Terraform.
Run the following command to verify that Terraform is available:
terraform
The output should be similar to the following:
Usage: terraform [global options] <subcommand> [args] The available commands for execution are listed below. The primary workflow commands are given first, followed by less common or more advanced commands. Main commands: init Prepare your working directory for other commands validate Check whether the configuration is valid plan Show changes required by the current configuration apply Create or update infrastructure destroy Destroy previously-created infrastructure
What's next
- Work through the Terraform for Google Cloud quickstart
- Learn about the basic Terraform commands.