Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Limiter les nouveaux déploiements par version de produit
.
Cloud Run Functions propose deux versions de produit : Cloud Run Functions (1re génération) et Cloud Run Functions créées via les APIGoogle Cloud Functions V2. Si votre organisation souhaite appliquer une limitation spécifiant qu'une seule des versions peut être utilisée pour déployer de nouvelles fonctions, vous pouvez définir une nouvelle règle d'administration avec la contrainteconstraints/cloudfunctions.restrictAllowedGenerations. Vous utilisez cette contrainte pour spécifier la génération (version) que vous souhaitez autoriser ou refuser dans le dossier ou le projet auquel la règle est appliquée.
La limitation ne s'applique qu'aux nouvelles fonctions déployées pour la première fois. Vous pourrez toujours redéployer les fonctions existantes, même si elles ne sont pas conformes à la règle.
Avant de commencer
Pour créer ou modifier des règles d'administration, votre compte doit disposer du rôle roles/orgpolicy.policyAdmin.
Utiliser une règle pour définir et appliquer des limitations
Vous pouvez utiliser Google Cloud CLI pour créer une règle qui limite le déploiement pour la première fois des nouvelles fonctions Cloud Run dans une organisation donnée à l'environnement spécifié.
Notez que la définition d'une règle ne s'applique pas aux fonctions existantes. Toutes les fonctions qui ont été déployées avant la règle peuvent être redéployées, mises à jour ou supprimées sans limitation.
Pour créer une stratégie qui limite les nouvelles fonctions Cloud Run, exécutez la commande suivante:
Où ORGANIZATION_NUMBER est le numéro de l'organisation à laquelle vous souhaitez appliquer la règle, et VERSION est la version de Cloud Run Functions à utiliser pour les nouveaux déploiements. La valeur attendue pour VERSION peut être l'une des suivantes :
1stGen : autorise seulement l'utilisation de Cloud Run Functions (1st gen).
2ndGen : autorise seulement l'utilisation de Cloud Run Functions (2nd gen).
Pour autoriser explicitement les deux environnements, spécifiez 1stGen et 2ndGen ensemble. Par défaut, les deux environnements sont autorisés lorsqu'aucune règle n'est définie.
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/03 (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/03 (UTC)."],[[["\u003cp\u003eCloud Run functions have two versions, 1st gen and 2nd gen, and organizations can restrict new deployments to a specific version using organization policies.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003econstraints/cloudfunctions.restrictAllowedGenerations\u003c/code\u003e constraint allows specifying which Cloud Run function version (1stGen or 2ndGen) can be used for new deployments within a folder or project.\u003c/p\u003e\n"],["\u003cp\u003eSetting this restriction only applies to new function deployments; existing functions can still be redeployed regardless of the policy.\u003c/p\u003e\n"],["\u003cp\u003eTo create or modify organization policies, the account must have the \u003ccode\u003eroles/orgpolicy.policyAdmin\u003c/code\u003e role.\u003c/p\u003e\n"],["\u003cp\u003eYou can use the Google Cloud CLI to enforce these restrictions by using the \u003ccode\u003egcloud resource-manager org-policies allow cloudfunctions.restrictAllowedGenerations\u003c/code\u003e command.\u003c/p\u003e\n"]]],[],null,["# Restrict new deployments by product version\n===========================================\n\n| **Note:** In this document, \"Cloud Run functions (2nd gen)\" refers to Cloud Run functions created with the Google Cloud Functions v2 APIs.\n\nCloud Run functions offers two product versions:\nCloud Run functions (1st gen) and Cloud Run functions created through the\nGoogle Cloud Functions v2 APIs. If your organization wants to enforce a\nrestriction specifying that only one of the versions can be used to deploy new\nfunctions, you can define a new\n[organization policy](/resource-manager/docs/organization-policy/overview)\nwith the\n[constraint](/resource-manager/docs/organization-policy/overview#constraints)\n`constraints/cloudfunctions.restrictAllowedGenerations`. You use this constraint\nto specify the generation (version) you want to allow or deny in the folder or\nproject the policy is applied to.\n\nThe restriction will only apply to new functions being deployed for the first\ntime. You will still be able to redeploy existing functions even if they\ndon't comply with the policy.\n\nBefore you begin\n----------------\n\nTo create or change organization policies, your account must have the\nrole\n[`roles/orgpolicy.policyAdmin`](/resource-manager/docs/organization-policy/using-constraints#required-roles).\n\nUse a policy to set and enforce restrictions\n--------------------------------------------\n\nYou can use Google Cloud CLI to create a policy restricting new\nCloud Run functions from being deployed for the first time within a given\norganization to the specified environment.\n\nNote that setting a policy does not apply to existing functions. All functions\nthat were deployed before the policy can be redeployed, updated, or deleted\nwithout restriction.\n\nTo create a policy that restricts new Cloud Run functions, run the following command: \n\n```bash\ngcloud resource-manager org-policies \\\n allow cloudfunctions.restrictAllowedGenerations \\\n --organization=ORGANIZATION_NUMBER VERSION\n```\n\nwhere \u003cvar translate=\"no\"\u003eORGANIZATION_NUMBER\u003c/var\u003e is the number of the\norganization to which you want to apply the policy, and\n\u003cvar translate=\"no\"\u003eVERSION\u003c/var\u003e is the Cloud Run functions version that must be\nused for new deployments. \u003cvar translate=\"no\"\u003eVERSION\u003c/var\u003e can be one of the\nfollowing:\n\n- `1stGen`: Allow the use of Cloud Run functions (1st gen) only.\n- `2ndGen`: Allow the use of Cloud Run functions (2nd gen) only.\n- To explicitly allow both environments, specify `1stGen` and `2ndGen` together. By default, both environments are allowed when no policy is set.\n\n| **Note:** you can also set the policy on a project or folder by replacing the `--organization` flag with `--project=\u003cPROJECT_ID\u003e` or \\`--folder= respectively."]]