Nesta página, descrevemos as etapas para instalar e configurar o Terraform para Google Cloud no Cloud Shell e em um shell local. O Cloud Shell é um ambiente shell interativo para o Google Cloud que permite aprender e testar o Google Cloud e gerenciar projetos e recursos do seu navegador da Web.
Cloud Shell
Para usar um terminal on-line com a gcloud CLI e o Terraform já configurados, ative o Cloud Shell:
Na parte de baixo desta página, uma sessão do Cloud Shell é iniciada e exibe um prompt de linha de comando. A inicialização da sessão pode levar alguns segundos.
-
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.
Para provisionar recursos do Google Cloud usando o Terraform, você precisa: ativar as APIs correspondentes:
gcloud services enable "API"
Substitua API pela API que você quer ativar.
Para provisionar recursos do Google Cloud usando o Terraform, você precisa papéis do Identity and Access Management específicos a esses recursos.
- Na guia Referência dos papéis do IAM determinar os papéis necessários.
-
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
Execute o seguinte comando para verificar se o Terraform está disponível:
terraform
A saída será semelhante a esta:
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
Shell local
-
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
Ative as APIs necessárias:
gcloud services enable "API"
Em que API é a API que você quer ativar.
Para provisionar um recurso do Google Cloud usando o Terraform, você precisa papéis do Identity and Access Management específicos a esses recursos.
- Na guia Referência dos papéis do IAM determinar os papéis necessários.
-
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
Instalar o Terraform
Execute o seguinte comando para verificar se o Terraform está disponível:
terraform
A saída será semelhante a esta:
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
A seguir
- Trabalhe no Guia de início rápido do Terraform para Google Cloud
- Saiba mais sobre os comandos básicos do Terraform.