Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Pour utiliser Terraform dans votre environnement Google Distributed Cloud (GDC) isolé, vous devez le télécharger et le configurer pour qu'il gère les ressources Kubernetes.
Vérifiez
que vous disposez d'un bucket de stockage GDC. Si vous n'avez pas de bucket de stockage, créez-en un.
Assurez-vous que votre système peut reconnaître le certificat de l'autorité de certification (CA) utilisé par le stockage d'objets.
Gérer le fichier d'état
Dans Terraform, le fichier d'état permet d'enregistrer l'état actuel du déploiement et de le mapper à la configuration Terraform. Étant donné que le stockage d'objets GDC est implémenté à l'aide de S3, vous pouvez utiliser l'API Terraform S3 pour effectuer la synchronisation avec un fichier d'état partagé. Pour ce faire, vous devez configurer Terraform pour qu'il se synchronise avec l'état à distance :
Ajoutez la configuration suivante à un fichier Terraform stocké localement, tel que le fichier main.tf :
Vous devez définir skip_credentials_validation et force_style_path sur true, car GDC n'est pas compatible avec la validation des identifiants et utilise le point de terminaison de style chemin d'accès.
Initialisez les nouvelles modifications du fichier d'état dans le bucket de stockage que vous avez spécifié à l'étape précédente :
terraforminit
Terraform peut demander une région AWS comme entrée obligatoire, mais la valeur n'est pas utilisée, car vous utilisez le stockage d'objets GDC.
Saisissez n'importe quelle région AWS pour répondre à l'exigence.
Définir des autorisations
En plus des autorisations requises pour effectuer une tâche spécifique à l'aide de Terraform, comme la création d'un projet GDC, vous devez également disposer des autorisations nécessaires pour afficher les définitions de ressources personnalisées à ce niveau. Appliquez les autorisations requises pour utiliser Terraform :
Créez la ressource de rôle de cluster crd-viewer :
Remplacez KUBECONFIG par le fichier kubeconfig du serveur d'API ou du cluster qui héberge la ressource que vous gérez avec Terraform. Par exemple, la plupart des ressources s'exécutent sur le serveur de l'API Management. Pour les charges de travail de conteneur, définissez le fichier kubeconfig de votre cluster Kubernetes. Veillez à définir le serveur d'API global si vous gérez une ressource globale.
Associez le rôle de cluster défini à l'étape précédente à l'utilisateur :
Initialisez votre répertoire de travail Terraform pour installer le fournisseur :
terraforminit
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)."],[[["\u003cp\u003eTerraform must be downloaded and configured to manage Kubernetes resources within a Google Distributed Cloud (GDC) air-gapped environment.\u003c/p\u003e\n"],["\u003cp\u003eTo manage state files, you must configure Terraform to sync with a remote state file on GDC object storage using the Terraform S3 API, setting parameters such as bucket details, access keys, and specific flags.\u003c/p\u003e\n"],["\u003cp\u003eUsers need specific permissions, including a \u003ccode\u003ecrd-viewer\u003c/code\u003e cluster role, to view custom resource definitions when performing tasks with Terraform on GDC, which must be bound to their user account.\u003c/p\u003e\n"],["\u003cp\u003eThe Kubernetes provider is required to provision and manage Kubernetes resources, and must be added to the required providers block in the terraform configuration file, and initialized with the command \u003ccode\u003eterraform init\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Configure Terraform\n\nTo use Terraform in your Google Distributed Cloud (GDC) air-gapped environment, you must\ndownload it and configure it to handle Kubernetes resources.\n\nBefore you begin\n----------------\n\n- Download Terraform to your workstation following the documentation provided by\n HashiCorp:\n \u003chttps://developer.hashicorp.com/terraform/install\u003e.\n\n- [Verify](/distributed-cloud/hosted/docs/latest/gdch/platform/pa-user/create-storage-buckets#verify_bucket_and_related_resource_creation)\n you have an existing GDC storage bucket. If you don't\n have a storage bucket,\n [create one](/distributed-cloud/hosted/docs/latest/gdch/platform/pa-user/create-storage-buckets#create_a_bucket).\n\n- Make sure your system can recognize the Certificate Authority (CA) certificate\n used by object storage.\n\nManage the state file\n---------------------\n\nThe state file in Terraform is used to record the current state of the\ndeployment and map it to the Terraform configuration. Since\nGDC object storage is implemented using S3, you can use\nthe Terraform S3 API to sync with a shared state file. To do this, you must\nconfigure Terraform to sync with the remote state:\n\n1. Add the following configuration to a Terraform file that is stored locally,\n such as the `main.tf` file:\n\n terraform {\n backend \"s3\" {\n bucket = \"\u003cvar translate=\"no\"\u003eBUCKET_FQN\u003c/var\u003e\"\n key = \"\u003cvar translate=\"no\"\u003eTF_STATE_PATH\u003c/var\u003e\"\n endpoint = \"\u003cvar translate=\"no\"\u003eBUCKET_ENDPOINT\u003c/var\u003e\"\n skip_credentials_validation = true\n force_path_style = true\n access_key = \"\u003cvar translate=\"no\"\u003eACCESS_KEY\u003c/var\u003e\"\n secret_key = \"\u003cvar translate=\"no\"\u003eSECRET_KEY\u003c/var\u003e\"\n ...\n }\n }\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eBUCKET_FQN\u003c/var\u003e: the fully qualified name from the\n `Bucket` custom resource.\n\n - \u003cvar translate=\"no\"\u003eTF_STATE_PATH\u003c/var\u003e: the location of the Terraform\n state file to store in the storage bucket.\n\n - \u003cvar translate=\"no\"\u003eBUCKET_ENDPOINT\u003c/var\u003e: the endpoint from the `Bucket`\n custom resource.\n\n - \u003cvar translate=\"no\"\u003eACCESS_KEY\u003c/var\u003e: the access key acquired from the\n secret containing your access credentials. Follow\n [Obtain bucket access credentials](/distributed-cloud/hosted/docs/latest/gdch/platform/pa-user/grant-obtain-storage-access#getting_bucket_access_credentials)\n to acquire the access key.\n\n - \u003cvar translate=\"no\"\u003eSECRET_KEY\u003c/var\u003e: the secret key acquired from the\n secret containing your access credentials. Follow\n [Obtain bucket access credentials](/distributed-cloud/hosted/docs/latest/gdch/platform/pa-user/grant-obtain-storage-access#getting_bucket_access_credentials)\n to acquire the secret key.\n\n You must set `skip_credentials_validation` and `force_style_path` to `true`\n since GDC does not support the credential validation\n and uses the path style endpoint.\n | **Note:** We recommend using environment variables to store the credentials. If credentials are hardcoded, they are stored within the `.terraform` directory and in plan files.\n2. Initialize the new state file edits in the storage bucket you specified in\n the previous step:\n\n terraform init\n\n Terraform might ask for an AWS region as a required input, but the value is\n not used since you're using GDC object storage.\n Input any AWS region to satisfy the requirement.\n\nSet permissions\n---------------\n\nBesides the permissions required to perform a specific task using Terraform,\nsuch as creating a GDC project, you must also have\npermissions to view custom resource definitions at that scope. Apply the\nrequired permissions to use Terraform:\n\n1. Create the `crd-viewer` cluster role resource:\n\n kubectl apply --kubeconfig \u003cvar translate=\"no\"\u003eKUBECONFIG\u003c/var\u003e -f - \u003c\u003cEOF\n apiVersion: rbac.authorization.k8s.io/v1\n kind: ClusterRole\n metadata:\n name: crd-viewer\n rules:\n - apiGroups: [\"apiextensions.k8s.io\"]\n resources: [\"customresourcedefinitions\"]\n verbs: [\"get\", \"list\", \"watch\"]\n EOF\n\n Replace \u003cvar translate=\"no\"\u003eKUBECONFIG\u003c/var\u003e with the kubeconfig file of the\n API server or cluster that hosts the resource you're managing with\n Terraform. For example, most resources run on the Management API server. For\n container workloads, set your Kubernetes cluster kubeconfig file. Be sure to\n set the global API server if you're managing a global resource.\n2. Bind the cluster role defined in the previous step to the user:\n\n kubectl apply --kubeconfig \u003cvar translate=\"no\"\u003eKUBECONFIG\u003c/var\u003e -f - \u003c\u003cEOF\n apiVersion: rbac.authorization.k8s.io/v1\n kind: ClusterRoleBinding\n metadata:\n name: crd-viewer-binding\n subjects:\n - kind: User\n name: \u003cvar translate=\"no\"\u003eUSER_EMAIL\u003c/var\u003e\n roleRef:\n kind: ClusterRole\n name: crd-viewer\n apiGroup: rbac.authorization.k8s.io\n EOF\n\nRepeat these steps for each API server or cluster you want to set Terraform\npermissions for.\n\nInstall and configure Terraform provider\n----------------------------------------\n\nYou must install the\n[Kubernetes Provider](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs)\nto provision and manage Kubernetes resources.\n\n1. In a Terraform file within your module, such as the `main.tf` file, insert\n the following `required_providers` block:\n\n terraform {\n required_providers {\n kubernetes = {\n source = \"hashicorp/kubernetes\"\n version = \"~\u003e2.6.1\"\n }\n }\n }\n\n2. Initialize your Terraform working directory to install the provider:\n\n terraform init"]]