Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Hashicorp Terraform es una herramienta de infraestructura como código (IaC) que te permite aprovisionar y administrar la infraestructura de nube. Terraform proporciona complementos llamados proveedores que te permiten interactuar con proveedores de servicios en la nube y otras APIs. Puedes usar el proveedor de Terraform para Google Cloud (proveedor deGoogle Cloud ) para aprovisionar y administrar la infraestructura de Google Cloud.
Beneficios de usar Terraform
En esta sección, se explican algunos de los beneficios de usar Terraform para aprovisionar y administrar la infraestructura de Google Cloud :
Terraform es la herramienta más usada para aprovisionar y automatizar la infraestructura deGoogle Cloud . Puedes usar el proveedor deGoogle Cloud para configurar y administrar todos los recursos de Google Cloud con la misma sintaxis y herramientas declarativas.
Terraform te permite especificar el estado final que prefieras para tu infraestructura.
Luego, puedes implementar la misma configuración varias veces para crear entornos de desarrollo, prueba y producción reproducibles.
Terraform te permite generar un plan de ejecución que muestre lo que hará Terraform cuando apliques tu configuración. Esto te permite evitar sorpresas cuando modificas tu infraestructura a través de Terraform.
Terraform te permite empaquetar y reutilizar el código común en forma de módulos.
En los módulos, se presentan interfaces estándar para crear recursos en la nube. Simplifican los proyectos mediante el aumento de la legibilidad y permiten que los equipos organicen la infraestructura en bloques legibles. Además, Google Cloud
publica una serie de módulos implementables como planos y
ejemplos de inicio como Soluciones de inicio rápido.
Terraform registra el estado actual de la infraestructura y te permite administrar el estado de manera efectiva. El archivo de estado de Terraform realiza un seguimiento de todos los recursos en una implementación.
Con Terraform
Terraform tiene una sintaxis declarativa y orientada a la configuración que puedes usar para autorizar la infraestructura que deseas aprovisionar. Con esta sintaxis, definirás el estado final preferido de tu infraestructura en un archivo de configuración de Terraform. Luego, usarás la CLI de Terraform para aprovisionar la infraestructura basada en el archivo de configuración.
En los siguientes pasos, se explica cómo funciona Terraform:
Describe la Google Cloud infraestructura que deseas aprovisionar
en un archivo de configuración de Terraform. No es necesario crear un código que describa cómo aprovisionar esta configuración.
Ejecuta el comando terraform plan, que evalúa tu configuración y genera un plan de ejecución. Puedes revisar el plan y realizar cambios según sea necesario.
Luego, ejecuta el comando terraform apply, que realiza las siguientes acciones:
Aprovisiona tu infraestructura según tu plan de ejecución mediante la invocación de las APIs de Google Cloud correspondientes en segundo plano.
Crea un archivo de estado de Terraform, que es una asignación con formato JSON de los recursos del archivo de configuración a los recursos en la infraestructura del mundo real. Terraform usa este archivo para conocer el estado más reciente de la infraestructura y determinar cuándo crear, actualizar y destruir recursos.
Luego, cuando ejecutes terraform apply, Terraform usa la asignación en el archivo de estado para comparar la infraestructura existente con el código y realizar actualizaciones según sea necesario:
Si un objeto de recurso definido en el archivo de configuración no existe en el archivo de estado, Terraform lo crea.
Si existe un objeto de recurso en el archivo de estado, pero tiene una configuración diferente de tu archivo de configuración, Terraform actualiza el recurso para que coincida con tu archivo de configuración.
Si un objeto de recurso en el archivo de estado coincide con tu archivo de configuración, Terraform deja el recurso sin cambios.
Google Cloud proveedores
Existen dos proveedores que te permiten aprovisionar y administrar la infraestructura de Google Cloud:
google: Usa este proveedor para aprovisionar y administrar las APIs de Google Cloud .
google-beta: Usa este proveedor para aprovisionar y administrar las APIs beta de Google Cloud.
Los proveedores de google y google-beta se desarrollan mediante una herramienta llamada Magic Modules. Magic Modules permite a los colaboradores realizar cambios en una sola base de código y desarrollar proveedores google y google-beta de forma simultánea.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[[["\u003cp\u003eTerraform is an Infrastructure as Code (IaC) tool for provisioning and managing cloud infrastructure, particularly effective for Google Cloud through its dedicated providers.\u003c/p\u003e\n"],["\u003cp\u003eUsing Terraform on Google Cloud offers benefits such as creating reproducible environments, generating execution plans, reusing code through modules, and effectively managing the state of your infrastructure.\u003c/p\u003e\n"],["\u003cp\u003eTerraform utilizes a declarative syntax where you define your desired infrastructure end-state, and it uses its CLI to provision and manage your configuration accordingly.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eterraform apply\u003c/code\u003e command provisions infrastructure based on an execution plan, interfacing with Google Cloud APIs and maintaining a state file to track resource changes.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egoogle\u003c/code\u003e and \u003ccode\u003egoogle-beta\u003c/code\u003e providers are used to provision and manage both general and beta Google Cloud APIs, respectively, and are developed using the Magic Modules tool.\u003c/p\u003e\n"]]],[],null,["# Overview of Terraform on Google Cloud\n\nHashicorp Terraform is an Infrastructure as code (IaC) tool that lets you\nprovision and manage cloud infrastructure. Terraform provides plugins called\n*providers* that lets you interact with cloud providers and other\nAPIs. You can use the *Terraform provider for Google Cloud*\n(*Google Cloud provider*) to provision and manage Google Cloud\ninfrastructure.\n\nBenefits of using Terraform\n---------------------------\n\nThis section explains some of the benefits of using Terraform to provision and\nmanage Google Cloud infrastructure:\n\n- Terraform is the most commonly used tool to provision and automate Google Cloud infrastructure. You can use the [Google Cloud\n provider](https://registry.terraform.io/providers/hashicorp/google/latest/docs) to configure and manage all Google Cloud resources using the same declarative syntax and tooling.\n- Terraform lets you specify your preferred end state for your infrastructure. You can then deploy the same configuration multiple times to create reproducible development, test, and production environments.\n- Terraform lets you generate an execution plan that shows what Terraform will do when you apply your configuration. This lets you avoid any surprises when you modify your infrastructure through Terraform.\n- Terraform lets you package and reuse common code in the form of [modules](https://registry.terraform.io/namespaces/terraform-google-modules). Modules present standard interfaces for creating cloud resources. They simplify projects by increasing readability and allow teams to organize infrastructure in readable blocks. Additionally, Google Cloud publishes a number of opinionated deployable modules as [blueprints](/docs/terraform/blueprints/terraform-blueprints) and getting-started examples as [Jump Start\n Solutions](/solutions?jump-start-solutions#section-3).\n- Terraform records the current state of your infrastructure and lets you manage state effectively. The Terraform state file keeps track of all resources in a deployment.\n\nUsing Terraform\n---------------\n\nTerraform has a declarative and configuration-oriented syntax, which you can use\nto [author the infrastructure](https://developer.hashicorp.com/terraform/language)\nthat you want to provision. Using this syntax, you'll define your preferred\nend-state for your infrastructure in a *Terraform configuration file* . You'll then\nuse the [Terraform CLI](/docs/terraform/basic-commands) to provision\ninfrastructure based on the configuration file.\n\nThe following steps explain how Terraform works:\n\n1. You describe the Google Cloud infrastructure you want to provision in a Terraform configuration file. You don't need to author code describing *how* to provision this configuration.\n2. You run the `terraform plan` command, which evaluates your configuration and generates an execution plan. You can review the plan and make changes as needed.\n3. Then, you run the `terraform apply` command, which performs the following actions:\n - It provisions your infrastructure based on your execution plan by invoking the corresponding Google Cloud APIs in the background.\n - It creates a *Terraform state file*, which is a JSON formatted mapping of resources in your configuration file to the resources in the real world infrastructure. Terraform uses this file to know the latest state of your infrastructure, and to determine when to create, update, and destroy resources.\n4. Subsequently, when you run `terraform apply`, Terraform uses the mapping in the state file to compare the existing infrastructure to the code, and make updates as necessary:\n - If a resource object defined in the configuration file does not exist in the state file, Terraform creates it.\n - If a resource object exists in the state file, but has a different configuration from your configuration file, Terraform updates the resource to match your configuration file.\n - If a resource object in the state file matches your configuration file, Terraform leaves the resource unchanged.\n\nGoogle Cloud providers\n----------------------\n\nThere are two providers that let you provision and manage Google Cloud\ninfrastructure:\n\n- `google`: Use this provider to provision and manage Google Cloud APIs.\n- `google-beta`: Use this provider to provision and manage Google Cloud beta APIs.\n\nFor instructions on using these providers, see the\n[Google Cloud provider configuration reference](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference).\n\n`google` and `google-beta` providers are developed using a tool called\n*Magic Modules* . Magic Modules allows contributors to make changes against a\nsingle codebase and develop both `google` and `google-beta` providers\nsimultaneously.\n\nYou can contribute to the Google Cloud providers using Magic Modules\nby following the instructions in the\n[Magic Modules contribution guide](https://googlecloudplatform.github.io/magic-modules/get-started/generate-providers/).\n\nWhat's next\n-----------\n\n- Learn how to [create a basic web server on Compute Engine using Terraform](/docs/terraform/get-started-with-terraform)\n- Learn how to [store Terraform state in a Cloud Storage bucket](/docs/terraform/resource-management/store-state)\n- Look through the various [Terraform for Google Cloud samples](/docs/samples?language=terraform)\n- Look through the [Terraform modules and blueprints for Google Cloud](/docs/terraform/blueprints/terraform-blueprints)"]]