使用自定义限制条件管理函数资源

本页面提供了有关为使用 Cloud Functions v2 API(例如通过 gcloud functions 命令)创建的函数设置自定义限制条件的补充信息。

限制

以下限制适用于为 Cloud Functions v2 API 函数使用自定义组织政策:

常见的组织政策示例

下表介绍了一些可能对您有用的自定义组织政策的语法:

说明 限制条件语法
禁止使用特定语言创建函数
    name: organizations/ORGANIZATION_ID/customConstraints/custom.cloudFunctionRuntimeBlock
    resource_types: cloudfunctions.googleapis.com/Function
    method_types:
      - CREATE
      - UPDATE
    condition: resource.buildConfig.runtime == "python312"
    action_type: DENY
    display_name: Deny functions using Python 3.12
    description: Functions cannot be created with Python 3.12 as the language runtime
要求函数使用特定的工作器池
    name: organizations/ORGANIZATION_ID/customConstraints/custom.cloudFunctionsWorkerPool
    resource_types: cloudfunctions.googleapis.com/Function
    method_types:
      - CREATE
      - UPDATE
    condition: resource.buildConfig.workerPool == "WORKER_POOL"
    action_type: DENY
    display_name: Require worker pool
    description: Functions must use a worker pool
WORKER_POOL 替换为您的 Cloud Build 工作器池的名称。
要求函数将所有容器映像存储在特定映像代码库中
    name: organizations/ORGANIZATION_ID/customConstraints/custom.cloudFunctionsRepository
    resource_types: cloudfunctions.googleapis.com/Function
    method_types:
      - CREATE
      - UPDATE
    condition: resource.buildConfig.dockerRepository.startsWith("REPO_PATH")
    action_type: DENY
    display_name: Image repository constraint
    description: Functions must push images to a central image repository under REPO_PATH
REPO_PATH 替换为您希望所有函数将其容器映像存储在其中的映像存储库网址的 URI。

后续步骤