Provisionner des ressources Config Sync avec Terraform
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
HashiCorp Terraform est un outil IaC (Infrastructure as Code) qui vous permet de provisionner et de gérer l'infrastructure cloud. Terraform fournit des plug-ins appelés fournisseurs qui vous permettent d'interagir avec des fournisseurs cloud et d'autres API. Vous pouvez utiliser le fournisseur Terraform pour Google Cloud afin de provisionner et de gérer les ressources Google Cloud , y compris Config Sync.
Cette page vous présente l'utilisation de Terraform avec Config Sync. Elle inclut une introduction au fonctionnement de Terraform et des ressources pour vous aider à commencer à utiliser Terraform avec Google Cloud. Vous trouverez également des liens vers la documentation de référence Terraform pour Config Sync, des exemples de code et des guides pour utiliser Terraform afin de provisionner des ressources Config Sync.
Terraform possède une syntaxe déclarative et axée sur la configuration qui vous permet de décrire l'infrastructure que vous souhaitez provisionner dans votre projet Google Cloud . Après avoir créé cette configuration dans un ou plusieurs fichiers de configuration Terraform, vous pouvez utiliser la CLI Terraform pour appliquer cette configuration à vos ressources Config Sync.
Les étapes suivantes expliquent le fonctionnement de Terraform :
Vous devez décrire l'infrastructure que vous souhaitez provisionner dans un fichier de configuration Terraform. Vous n'avez pas besoin d'écrire de code décrivant comment provisionner l'infrastructure. Terraform provisionne l'infrastructure pour vous.
Vous exécutez la commande terraform plan, qui évalue votre configuration et génère un plan d'exécution. Vous pouvez examiner le plan et apporter les modifications nécessaires.
Vous exécutez la commande terraform apply, qui effectue les actions suivantes :
Il provisionne votre infrastructure en fonction de votre plan d'exécution en appelant les API Config Sync correspondantes en arrière-plan.
Il crée un fichier d'état Terraform, qui est un fichier JSON qui mappe les ressources de votre fichier de configuration avec les ressources de l'infrastructure réelle. Terraform utilise ce fichier pour conserver un enregistrement de l'état le plus récent de votre infrastructure et pour déterminer quand créer, mettre à jour et détruire des ressources.
Lorsque vous exécutez terraform apply, Terraform utilise le mappage dans le fichier d'état pour comparer l'infrastructure existante au code et effectuer les mises à jour si nécessaire :
Si un objet de ressource est défini dans le fichier de configuration, mais n'existe pas dans le fichier d'état, Terraform le crée.
Si un objet de ressource existe dans le fichier d'état, mais possède une configuration différente de celle contenue dans votre fichier de configuration, Terraform met à jour la ressource en fonction de votre fichier de configuration.
Si un objet de ressource dans le fichier d'état correspond à votre fichier de configuration, Terraform laisse la ressource telle quelle.
Ressources Terraform pour Config Sync
Les ressources sont les éléments fondamentaux du langage Terraform. Chaque bloc de ressources décrit un ou plusieurs objets d'infrastructure, tels que des réseaux virtuels ou des instances de calcul.
Le tableau suivant recense les ressources Terraform disponibles pour Config Sync :
Ce guide explique comment utiliser Config Sync et Terraform pour créer de manière dynamique des ressources au niveau de l'équipe sur un parc de clusters.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[],[],null,["# Provision Config Sync resources with Terraform\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 let you interact with cloud providers and other APIs. You can\nuse the *Terraform provider for Google Cloud* to provision and manage\nGoogle Cloud resources, including Config Sync.\n\nThis page introduces you to using Terraform with Config Sync, including an\nintroduction to how Terraform works and some resources to help you get started using\nTerraform with Google Cloud. You'll also find links to Terraform reference docs for\nConfig Sync, code examples, and guides for using Terraform to provision\nConfig Sync resources.\n\nFor instructions on how to get started with Terraform for Google Cloud, see\n[Install and configure Terraform](/docs/terraform/install-configure-terraform) or the\n[Terraform for Google Cloud quickstart](/docs/terraform/create-vm-instance).\n\nHow Terraform works\n-------------------\n\nTerraform has a declarative and configuration-oriented syntax, which you can\nuse to describe the infrastructure that you want to provision in your\nGoogle Cloud project. After you author this configuration in one or more\nTerraform configuration files, you can use the Terraform CLI to apply this\nconfiguration to your Config Sync resources.\n\nThe following steps explain how Terraform works:\n\n1. You describe the infrastructure you want to provision in a *Terraform\n configuration file*. You don't need to write code describing how to provision the infrastructure. Terraform provisions the infrastructure for you.\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. You run the `terraform apply` command, which performs the following\n actions:\n\n 1. It provisions your infrastructure based on your execution plan by invoking the corresponding Config Sync APIs in the background.\n 2. It creates a *Terraform state file*, which is a JSON file that maps the resources in your configuration file to the resources in the real-world infrastructure. Terraform uses this file to keep a record of the most recent state of your infrastructure, and to determine when to create, update, and destroy resources.\n 3. When you run `terraform apply`, Terraform uses the mapping in\n the state file to compare the existing infrastructure to the code, and make\n updates as necessary:\n\n - If a resource object is defined in the configuration file, but doesn't 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\nTerraform resources for Config Sync\n-----------------------------------\n\n*Resources* are the fundamental elements in the Terraform language. Each\nresource block describes one or more infrastructure objects, such as virtual\nnetworks or compute instances.\n\nThe following table lists the Terraform resources available for\nConfig Sync:\n\n\n\u003cbr /\u003e\n\nTerraform-based guides for Config Sync\n--------------------------------------\n\nThe following table lists Terraform-based how-to guides and tutorials for\nConfig Sync:\n\n\n\u003cbr /\u003e\n\nWhat's next\n-----------\n\n- [Terraform code samples for Config Sync](/docs/samples?language=terraform)\n- [Terraform on Google Cloud documentation](/docs/terraform)\n- [Google Cloud provider documentation in HashiCorp](https://registry.terraform.io/providers/hashicorp/google/latest/docs)\n- [Infrastructure as code for Google Cloud](/docs/terraform/iac-overview)"]]