Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Hashicorp Terraform ist ein IaC-Tool (Infrastructure as Code), mit dem Sie eine Cloud-Infrastruktur bereitstellen und verwalten können. Terraform bietet Plug-ins, die als Anbieter bezeichnet werden und mit denen Sie mit Cloud-Anbietern und anderen APIs interagieren können. Sie können den Terraform-Anbieter für Google Cloud (Google Cloud Anbieter) verwenden, um die Google Cloud-Infrastruktur bereitzustellen und zu verwalten.
Vorteile von Terraform
In diesem Abschnitt werden einige der Vorteile von Terraform zum Bereitstellen und Verwalten der Google Cloud Infrastruktur erläutert:
Terraform ist das am häufigsten verwendete Tool zur Bereitstellung und Automatisierung derGoogle Cloud -Infrastruktur. Mit dem Google Cloud-Anbieter können Sie alle Google Cloud -Ressourcen mit derselben deklarativen Syntax und denselben Tools konfigurieren und verwalten.
Mit Terraform können Sie den bevorzugten Endzustand für Ihre Infrastruktur angeben.
Sie können dann dieselbe Konfiguration mehrmals bereitstellen, um reproduzierbare Entwicklungs-, Test- und Produktionsumgebungen zu erstellen.
Mit Terraform können Sie einen Ausführungsplan generieren, der zeigt, was Terraform beim Anwenden Ihrer Konfiguration tut. Dadurch können Sie Überraschungen vermeiden, wenn Sie Ihre Infrastruktur über Terraform ändern.
Mit Terraform können Sie gemeinsamen Code in Form von Modulen verpacken und wiederverwenden.
Module bieten Standardschnittstellen zum Erstellen von Cloud-Ressourcen. Sie vereinfachen Projekte, da sie die Lesbarkeit verbessern und ermöglichen es Teams, die Infrastruktur in lesbaren Blöcken zu organisieren. Darüber hinaus veröffentlicht Google Cloudeine Reihe von speziell konzipierten bereitstellbaren Modulen als Blueprints und Beispiele für die ersten Schritte als Schnellstartlösungen.
Terraform zeichnet den aktuellen Status Ihrer Infrastruktur auf und ermöglicht Ihnen, den Zustand effektiv zu verwalten. Die Terraform-Zustandsdatei verfolgt alle Ressourcen in einer Bereitstellung.
Terraform verwenden
Terraform hat eine deklarative, konfigurationsorientierte Syntax, mit der Sie die Infrastruktur erstellen können, die Sie bereitstellen möchten. Mit dieser Syntax definieren Sie den bevorzugten Endzustand für Ihre Infrastruktur in einer Terraform-Konfigurationsdatei. Anschließend verwenden Sie die Terraform-Befehlszeile, um Infrastruktur basierend auf der Konfigurationsdatei bereitzustellen.
In den folgenden Schritten wird die Funktionsweise von Terraform erläutert:
Sie beschreiben die Google Cloud Infrastruktur, die Sie bereitstellen möchten, in einer Terraform-Konfigurationsdatei. Sie müssen keinen Code schreiben, der beschreibt, wie diese Konfiguration bereitgestellt wird.
Sie führen den Befehl terraform plan aus, der Ihre Konfiguration auswertet und einen Ausführungsplan generiert. Sie können den Plan prüfen und bei Bedarf Änderungen vornehmen.
Anschließend führen Sie den Befehl terraform apply aus, der die folgenden Aktionen ausführt:
Ihre Infrastruktur wird basierend auf Ihrem Ausführungsplan bereitgestellt, indem die entsprechenden Google Cloud APIs im Hintergrund aufgerufen werden.
Es wird eine Terraform-Zustandsdatei erstellt, eine JSON-formatierte Zuordnung von Ressourcen in Ihrer Konfigurationsdatei zu den Ressourcen in der realen Infrastruktur. Terraform verwendet diese Datei, um den neuesten Status Ihrer Infrastruktur zu kennen und zu bestimmen, wann Ressourcen erstellt, aktualisiert und gelöscht werden müssen.
Wenn Sie anschließend terraform apply ausführen, verwendet Terraform die Zuordnung in der Zustandsdatei, um die vorhandene Infrastruktur mit dem Code zu vergleichen und bei Bedarf Aktualisierungen vorzunehmen:
Wenn ein in der Konfigurationsdatei definiertes Ressourcenobjekt in der Zustandsdatei nicht vorhanden ist, erstellt Terraform es.
Wenn ein Ressourcenobjekt in der Zustandsdatei vorhanden ist, aber eine andere Konfiguration als die Konfigurationsdatei hat, aktualisiert Terraform die Ressource entsprechend Ihrer Konfigurationsdatei.
Wenn ein Ressourcenobjekt in der Zustandsdatei mit der Konfigurationsdatei übereinstimmt, lässt Terraform die Ressource unverändert.
Google Cloud Anbieter
Es gibt zwei Anbieter, mit denen Sie die Google Cloud
Infrastruktur bereitstellen und verwalten können:
google: Mit diesem Anbieter Google Cloud APIs bereitstellen und verwalten.
google-beta: Mit diesem Anbieter Beta-APIs bereitstellen und verwalten Google Cloud
google- und google-beta-Anbieter werden mit einem Tool namens Magic Modules entwickelt. Mit Magic Modules können Mitwirkende Änderungen an einer einzigen Codebasis vornehmen und gleichzeitig google- und google-beta-Anbieter entwickeln.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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)"]]