En esta página, se describen los pasos para instalar y configurar Terraform para Google Cloud en Cloud Shell y en una shell local. Cloud Shell es un entorno de shell interactivo para Google Cloud que te permite aprender y experimentar con Google Cloud, además de administrar tus proyectos y recursos desde tu navegador web.
Cloud Shell
Para usar una terminal en línea con gcloud CLI y Terraform ya configurados, activa Cloud Shell.
En la parte inferior de esta página, se inicia una sesión de Cloud Shell y se muestra una instrucción de línea de comandos. La sesión puede tardar unos segundos en inicializarse.
-
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 aprovisionar recursos de Google Cloud con Terraform, debes habilitar las APIs correspondientes:
gcloud services enable "API"
Reemplaza API por la API que deseas habilitar.
Para aprovisionar recursos de Google Cloud con Terraform, necesitas roles de Identity and Access Management específicos de estos recursos.
- En Referencia de los roles de IAM determina los roles necesarios.
-
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: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
Ejecuta el siguiente comando para verificar que Terraform esté disponible:
terraform
El resultado debería ser similar al siguiente ejemplo:
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
Habilita las API necesarias:
gcloud services enable "API"
En las que API es la API que deseas habilitar.
Para aprovisionar recursos de Google Cloud con Terraform, necesitas roles de Identity and Access Management específicos de estos recursos.
- En Referencia de los roles de IAM determina los roles necesarios.
-
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: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
Instala Terraform.
Ejecuta el siguiente comando para verificar que Terraform esté disponible:
terraform
El resultado debería ser similar al siguiente ejemplo:
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
¿Qué sigue?
- Revisa la Guía de inicio rápido de Terraform para Google Cloud
- Obtén información sobre los comandos básicos de Terraform.