Résoudre les problèmes liés à gcloud beta terraform vet
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Pourquoi un problème de non-respect auquel je m'attendais ne génère-t-il pas d'erreur ?
Si vous testez votre logique de validation et constatez que la contrainte ne génère pas d'erreur alors qu'elle le devrait, cela peut être dû à un ou plusieurs des éléments suivants :
Votre bibliothèque de règles est-elle correctement configurée ? Vérifiez que votre bibliothèque de règles contient un répertoire policies/constraints dans lequel se trouve la contrainte devant générer un cas de non-respect.
La ressource Terraform qui contient le problème de non-respect est-elle une ressource acceptée ?gcloud beta terraform vet ne peut vérifier les non-respects que pour les ressources compatibles avec sa version. Exécutez à nouveau la commande avec --verbosity=debug et vérifiez si la sortie contient un message tel que celui-ci : unsupported resource:
google_resource_name. Vous pouvez également vérifier si votre ressource figure dans la liste des ressources compatibles.
Votre contrainte cible-t-elle la ressource Terraform appropriée ?
Vérifiez le champ kind de la contrainte. Il doit ressembler à ceci : GCPAppengineLocationConstraintV1
Dans le répertoire policies/templates, recherchez une règle possédant une valeur identique à spec.crd.spec.names.kind.
Dans le champ rego, recherchez une valeur semblable à celle-ci : asset.asset_type ==
"appengine.googleapis.com/Application". Il s'agit du type d'élément CAI ciblé par la contrainte.
Pourquoi une erreur indique-t-elle qu'aucun projet n'est défini ?
L'ancêtre d'une ressource permet de créer un nom d'élément CAI précis. Si gcloud beta terraform vet ne parvient pas à déterminer automatiquement l'ancêtre d'un élément CAI, il renvoie une erreur indiquant : project: required field is not set. Vous pouvez spécifier un projet par défaut avec l'option --project ou en définir un à l'aide de gcloud config.
Pourquoi une erreur s'affiche-t-elle indiquant getting resource ancestry for project PROJECT_ID: googleapi: Error 403: The caller does not have permission, forbidden ?
Exécutez la commande avec --verbosity=debug et recherchez un message tel que Terraform
is using this identity:. Il doit être suivi d'une adresse e-mail, qui est le compte utilisé pour les requêtes API.
Si la bonne adresse e-mail s'affiche, vérifiez qu'elle dispose des autorisations suivantes pour le projet :
getIamPolicy
resourcemanager.projects.get
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\u003ePre-General Availability (Pre-GA) products and features are governed by the "Pre-GA Offerings Terms" in the General Service Terms.\u003c/p\u003e\n"],["\u003cp\u003ePre-GA offerings are provided "as is" with potentially limited support, as detailed in the launch stage descriptions.\u003c/p\u003e\n"],["\u003cp\u003eConstraint violations may not trigger errors if the policy library is incorrectly set up, the resource is unsupported, or the constraint targets the wrong resource type.\u003c/p\u003e\n"],["\u003cp\u003eThe error "project: required field is not set" indicates that the tool cannot determine the CAI Asset's ancestry and requires a project to be specified.\u003c/p\u003e\n"],["\u003cp\u003eA "permission denied" error when getting resource ancestry suggests an authentication issue or insufficient permissions for the specified identity.\u003c/p\u003e\n"]]],[],null,["# Troubleshoot gcloud beta terraform vet\n\n| **Preview**\n|\n|\n| This product or feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products and features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nWhy is a violation I expected not throwing an error?\n----------------------------------------------------\n\nIf you test your validation logic and find that the constraint isn't throwing an\nerror when it should be, this might be a result of one or more of the following:\n\n- **Is your policy-library set up correctly?** Verify that your policy library contains a `policies/constraints` directory, which contains the constraint you are expecting to cause a violation.\n- **Is the Terraform resource that contains the violation a supported\n resource?** `gcloud beta terraform vet` can only check for violations for resources that are supported in its version. Re-run your command with `--verbosity=debug` and look for a message like: `unsupported resource:\n google_resource_name`. Or you can check whether your resource is in the list of [supported resources](/docs/cloud-asset-inventory/overview#supported_resource_types).\n- **Is your constraint targeting the correct Terraform resource?**\n\n 1. Check the `kind` field of the constraint. It should be something like: `GCPAppengineLocationConstraintV1`\n 2. Search the `policies/templates` directory for a policy that has the same value for `spec.crd.spec.names.kind`\n 3. In the `rego` field, look for something like: `asset.asset_type ==\n \"appengine.googleapis.com/Application\"`. This is the [CAI Asset Type](/asset-inventory/docs/supported-asset-types) that the constraint targets.\n 4. Make sure that the CAI Asset Type is in the list of [supported resources](/docs/cloud-asset-inventory/overview#supported_resource_types).\n\nWhy am I getting an error saying that no project is defined?\n------------------------------------------------------------\n\nResource Ancestry is used to build an accurate CAI Asset Name. If\n`gcloud beta terraform vet` can't automatically determine the ancestry for a CAI Asset,\nit will return an error saying: `project: required field is not set`. You can\nprovide a default project with the `--project` flag or by setting one using\n[`gcloud config`](/sdk/gcloud/reference/config).\n\nWhy am I getting an error saying `getting resource ancestry for project PROJECT_ID: googleapi: Error 403: The caller does not have permission, forbidden`?\n----------------------------------------------------------------------------------------------------------------------------------------------------------\n\nRun the command with `--verbosity=debug` and look for a message like `Terraform\nis using this identity:`. It should be followed by an email address, which is\nthe account being used for API requests.\n\n- If there is no email address, then [make sure that your authentication is working properly](/sdk/gcloud/reference/auth).\n- If there is an email address, but it's not the service account that you wanted to impersonate, then [make sure that your service account impersonation is set up correctly](/sdk/gcloud/reference#--impersonate-service-account)\n- If the correct email address is showing, make sure that it has the following permissions on the project:\n - `getIamPolicy`\n - `resourcemanager.projects.get`"]]