设计和部署 SaaS 产品

借助 Application Design Center 和 App Lifecycle Manager,您可以标准化和扩缩多租户 SaaS 交付,而无需为每个客户手动配置基础设施。您可以在 App Design Center 中将可重复使用的 Terraform 模块组装成复合应用模板,然后在 App Lifecycle Manager 中将这些模板打包成代管式 SaaS 产品。

在本教程中,您将预配隔离的租户环境,并自动执行渐进式更新和发布。此工作流专为平台工程师、企业架构师和 DevOps 运维人员设计。

目标

  • 准备一个包含 Cloud Run 和 Cloud Storage Terraform 模块的 GitHub 代码库。
  • 使用 Developer Connect 将 GitHub 代码库关联到 Google Cloud 。
  • 导入 Terraform 模块,以便在 App Design Center 中创建组件模板并将其编入目录。
  • 设计一个包含组件模板的复合应用模板。
  • 打包模板并在 App Lifecycle Manager 中部署客户环境。
  • 在客户环境中自动执行渐进式发布。

费用

在本文档中,您将使用 Google Cloud的以下收费组件:

如需根据您的预计使用量来估算费用,请使用价格计算器。

新 Google Cloud 用户可能有资格申请免费试用。

完成本文档中描述的任务后,您可以通过删除所创建的资源来避免继续计费。如需了解详情,请参阅清理。

准备工作

  1. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  2. Verify that billing is enabled for your Google Cloud project.

  3. Enable the Developer Connect, Secret Manager, App Lifecycle Manager, Infrastructure Manager, and Cloud Run APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  4. 确保您在项目中具有以下 Identity and Access Management (IAM) 角色:
    • Application Design Center Admin (roles/designcenter.admin) 和 Service Usage Admin (roles/serviceusage.serviceUsageAdmin) 角色,才能执行设置。
    • SaaS Service Management Admin (roles/saasservicemgmt.admin)
    • Developer Connect Admin (roles/developerconnect.admin)
    • Project IAM Admin (roles/resourcemanager.projectIamAdmin) 或 Security Admin (roles/iam.securityAdmin),用于创建服务账号和授予 IAM 角色。
    • Cloud Run Admin (roles/run.admin)
    • Storage Admin (roles/storage.admin)
    • Service Account Admin (roles/iam.serviceAccountAdmin)
  5. 安装 Google Cloud CLI,然后对其进行初始化:
    gcloud init
    确保您已安装 beta 组件:
    gcloud components install beta
  6. 使用单项目应用管理边界在项目上完成Application Design Center 设置。此设置会启用应用管理、为 Terraform 预配存储桶,并创建 default-space 空间和 default-catalog 目录。
  7. 在本地机器上安装 Git。
  8. 确保您拥有一个有权创建代码库和生成个人访问令牌的 GitHub 账号。

设置环境和源代码库

如需为本教程设置环境,请指定变量值并配置 GitHub 代码库。

指定教程变量

在本教程和命令终端中设置变量。

  1. 设置以下变量,以更新本教程中的命令:

    变量 说明 值
    PROJECT_ID 您的 Google Cloud 项目 ID PROJECT_ID
    REGION App Design Center 资源、Developer Connect、App Lifecycle Manager 产品和租户基础架构的部署区域 us-central1
  2. 在命令终端中,配置活跃的 Google Cloud 项目:

    gcloud config set project PROJECT_ID
    
  3. 检索您的 Google Cloud 项目编号并将其存储在环境变量中:

    PROJECT_NUM=$(gcloud projects describe PROJECT_ID --format="value(projectNumber)")
    

创建 Terraform 配置文件

为 Cloud Run 和 Cloud Storage 编写模块化 Terraform 定义。稍后,您会将这些模块导入 App Design Center,以便将其打包成可重复使用的架构组件。

  1. 为 Terraform 模块创建本地目录结构:

    mkdir -p adc-alm-starter/infra/cloud-run
    mkdir -p adc-alm-starter/infra/cloud-storage
    cd adc-alm-starter
    
  2. 在 infra/cloud-run/main.tf 中,创建 Cloud Run 模块定义:

    terraform {
      required_version = ">= 1.5.0"
      required_providers {
        google = {
          source  = "hashicorp/google"
          version = ">= 5.0.0"
        }
      }
    }
    
    variable "project_id" {
      type        = string
      description = "The Google Cloud project ID."
    }
    
    variable "region" {
      type        = string
      description = "The deployment region."
      default     = "us-central1"
    }
    
    variable "service_name" {
      type        = string
      description = "Name of the Cloud Run service."
      default     = "sample-app"
    }
    
    variable "bucket_name" {
      type        = string
      description = "Name of the Cloud Storage bucket to connect."
      default     = ""
    }
    
    resource "google_service_account" "app_sa" {
      account_id   = "${var.service_name}-sa"
      display_name = "Service Account for ${var.service_name}"
      project      = var.project_id
    }
    
    resource "google_cloud_run_v2_service" "app_service" {
      name                = var.service_name
      location            = var.region
      project             = var.project_id
      deletion_protection = false
    
      template {
        service_account = google_service_account.app_sa.email
        containers {
          image = "us-docker.pkg.dev/cloudrun/container/hello"
          env {
            name  = "STORAGE_BUCKET"
            value = var.bucket_name
          }
          resources {
            limits = {
              cpu    = "1"
              memory = "512Mi"
            }
          }
        }
      }
    }
    
    output "service_url" {
      description = "URL of the deployed Cloud Run service."
      value       = google_cloud_run_v2_service.app_service.uri
    }
    
    output "service_account_email" {
      description = "Email of the Cloud Run service account."
      value       = google_service_account.app_sa.email
    }
    
  3. 在 infra/cloud-run/metadata.yaml 中,创建模块元数据定义:

    apiVersion: blueprints.cloud.google.com/v1alpha1
    kind: BlueprintMetadata
    metadata:
      name: cloud-run-component
    spec:
      info:
        title: Cloud Run Component
        version: 0.1.0
        actuationTool:
          flavor: Terraform
          version: ">= 1.5.0"
      interfaces:
        variables:
          - name: project_id
            description: The Google Cloud project ID.
            varType: string
            required: true
          - name: region
            description: The deployment region.
            varType: string
            defaultValue: us-central1
          - name: service_name
            description: Name of the Cloud Run service.
            varType: string
            defaultValue: sample-app
          - name: bucket_name
            description: Name of the Cloud Storage bucket to connect.
            varType: string
            defaultValue: ""
        outputs:
          - name: service_url
            description: URL of the deployed Cloud Run service.
          - name: service_account_email
            description: Email of the Cloud Run service account.
    
  4. 在 infra/cloud-storage/main.tf 中,创建 Cloud Storage 模块定义:

    terraform {
      required_version = ">= 1.5.0"
      required_providers {
        google = {
          source  = "hashicorp/google"
          version = ">= 5.0.0"
        }
        random = {
          source  = "hashicorp/random"
          version = ">= 3.5.0"
        }
      }
    }
    
    variable "project_id" {
      type        = string
      description = "The Google Cloud project ID."
    }
    
    variable "region" {
      type        = string
      description = "The deployment region."
      default     = "us-central1"
    }
    
    variable "bucket_name_prefix" {
      type        = string
      description = "Prefix for the Cloud Storage bucket."
      default     = "app-data"
    }
    
    variable "writer_service_account" {
      type        = string
      description = "Service account email granted objectAdmin permissions."
      default     = ""
    }
    
    resource "random_id" "bucket_suffix" {
      byte_length = 4
    }
    
    resource "google_storage_bucket" "bucket" {
      name                        = "${var.bucket_name_prefix}-${random_id.bucket_suffix.hex}"
      location                    = var.region
      project                     = var.project_id
      uniform_bucket_level_access = true
      force_destroy               = true
    }
    
    resource "google_storage_bucket_iam_member" "writer_grant" {
      count  = var.writer_service_account != "" ? 1 : 0
      bucket = google_storage_bucket.bucket.name
      role   = "roles/storage.objectAdmin"
      member = "serviceAccount:${var.writer_service_account}"
    }
    
    output "bucket_name" {
      description = "Name of the created storage bucket."
      value       = google_storage_bucket.bucket.name
    }
    
  5. 在 infra/cloud-storage/metadata.yaml 中,创建模块元数据定义:

    apiVersion: blueprints.cloud.google.com/v1alpha1
    kind: BlueprintMetadata
    metadata:
      name: cloud-storage-component
    spec:
      info:
        title: Cloud Storage Component
        version: 0.1.0
        actuationTool:
          flavor: Terraform
          version: ">= 1.5.0"
      interfaces:
        variables:
          - name: project_id
            description: The Google Cloud project ID.
            varType: string
            required: true
          - name: region
            description: The deployment region.
            varType: string
            defaultValue: us-central1
          - name: bucket_name_prefix
            description: Prefix for the Cloud Storage bucket.
            varType: string
            defaultValue: app-data
          - name: writer_service_account
            description: Service account email granted objectAdmin permissions.
            varType: string
            defaultValue: ""
        outputs:
          - name: bucket_name
            description: Name of the created storage bucket.
    

将 Terraform 推送到 GitHub

将 Terraform 配置提交到 GitHub 代码库,并通过 Developer Connect 将该代码库连接到 Google Cloud 。通过该连接,应用设计中心可以安全地访问源代码控制系统,直接从中导入基础设施修订版本。

  1. 在网络浏览器中,创建一个名为 adc-alm-starter 的新 GitHub 代码库。

  2. 在 GitHub 中创建精细的个人访问令牌,以对 git push 命令进行身份验证。选择 adc-alm-starter 代码库,并授予内容:读写权限。

  3. 在命令终端中,在 adc-alm-starter 目录中初始化 Git,提交文件,然后推送到 GitHub:

    cd adc-alm-starter
    git init
    git add infra/
    git commit -m "feat: initialize Cloud Run and Cloud Storage modules"
    git branch -M main
    git remote add origin https://github.com/GITHUB_USER_OR_ORG/adc-alm-starter.git
    git push -u origin main
    

    当系统提示您进行身份验证时,请输入您的 GitHub 用户名和个人访问令牌。

  4. 在 Google Cloud 控制台中,前往 Developer Connect 页面:

    前往 Developer Connect

  5. 在 us-central1 区域中为您的 GitHub 账号创建连接,并关联您的代码库。如需查看详细说明,请参阅连接到 GitHub。

  6. 确定关联代码库的连接 ID 和 Git 代码库链接 ID,并更新以下变量:

    • CONNECTION_ID:Developer Connect 连接标识符。
    • GIT_REPO_LINK_ID:关联的 Git 代码库标识符。

在 App Design Center 中编写模板

如需设计 Google Cloud 基础设施,请将 Terraform 模块作为组件模板导入 App Design Center。然后,创建一个包含这些组件的复合应用模板。

验证您的空间和目录

如果您在 Google Cloud 控制台中完成了 App Design Center 设置,系统会自动创建默认空间和目录。

如果您使用 gcloud CLI 完成了设置,请执行以下操作:

  1. 验证您所在的区域是否存在 default-space:

    gcloud design-center spaces describe "default-space" \
        --location="us-central1"
    

    将 default-space 替换为您的 App Design Center 空间 ID。

  2. 如果该空间不存在,请创建空间和目录:

    gcloud design-center spaces create "default-space" \
        --location="us-central1" \
        --display-name="Default Space"
    
    gcloud design-center spaces catalogs create "default-catalog" \
        --space="default-space" \
        --location="us-central1" \
        --display-name="Default Catalog"
    

    将 default-catalog 替换为您的目录 ID。

创建组件模板

组件模板可将单个 Terraform 模块转换为可添加到多服务应用模板的构建块。

根据 Git 代码库中的 Terraform 模块创建组件模板:

  1. 为 Cloud Run 创建目录模板:

    gcloud design-center spaces catalogs templates create "cloud-run-component" \
        --space="default-space" \
        --catalog="default-catalog" \
        --location="us-central1" \
        --display-name="Cloud Run Component" \
        --template-category=component-template
    

    将 cloud-run-component 替换为 Cloud Run 组件模板的标识符。

  2. 为 Cloud Storage 创建目录模板:

    gcloud design-center spaces catalogs templates create "cloud-storage-component" \
        --space="default-space" \
        --catalog="default-catalog" \
        --location="us-central1" \
        --display-name="Cloud Storage Component" \
        --template-category=component-template
    

    将 cloud-storage-component 替换为 Cloud Storage 组件模板标识符。

  3. 通过从 Git 代码库导入 Cloud Run Terraform 模块来创建模板修订版本:

    gcloud design-center spaces catalogs templates revisions create r-1 \
        --template="cloud-run-component" \
        --catalog="default-catalog" \
        --space="default-space" \
        --location="us-central1" \
        --developer-connect-repo="projects/PROJECT_ID/locations/us-central1/connections/CONNECTION_ID/gitRepositoryLinks/GIT_REPO_LINK_ID" \
        --developer-connect-repo-dir="infra/cloud-run" \
        --developer-connect-repo-ref="refs/heads/main"
    

    替换以下内容:

    • CONNECTION_ID:您的 Developer Connect 连接 ID。
    • GIT_REPO_LINK_ID:关联的 Git 代码库链接 ID。
  4. 通过从 Git 代码库导入 Cloud Storage Terraform 模块来创建模板修订版本:

    gcloud design-center spaces catalogs templates revisions create r-1 \
        --template="cloud-storage-component" \
        --catalog="default-catalog" \
        --space="default-space" \
        --location="us-central1" \
        --developer-connect-repo="projects/PROJECT_ID/locations/us-central1/connections/CONNECTION_ID/gitRepositoryLinks/GIT_REPO_LINK_ID" \
        --developer-connect-repo-dir="infra/cloud-storage" \
        --developer-connect-repo-ref="refs/heads/main"
    

    替换以下内容:

    • CONNECTION_ID:您的 Developer Connect 连接 ID。
    • GIT_REPO_LINK_ID:关联的 Git 代码库链接 ID。
  5. 列出空间中的共享模板,以检索其共享模板 ID:

    gcloud design-center spaces shared-templates list \
        --space="default-space" \
        --location="us-central1"
    

    在命令输出中,记下 cloud-run-component 和 cloud-storage-component 的 name 字段 (projects/PROJECT_ID/locations/us-central1/spaces/default-space/sharedTemplates/SHARED_TEMPLATE_ID) 中的 SHARED_TEMPLATE_ID 段。

创建复合应用模板

将组件模板组合成复合应用模板,并配置参数连接。App Lifecycle Manager 使用复合模板将应用拓扑作为 SaaS 产品进行管理。您需要指定输出和输入,以确保 Cloud Run 服务自动接收存储桶名称和访问 Cloud Storage 所需的 IAM 权限。

  1. 创建复合应用模板:

    gcloud design-center spaces application-templates create "run-storage-app" \
        --space="default-space" \
        --location="us-central1" \
        --display-name="Cloud Run and Storage Multi-Tenant Application" \
        --composition-type=composite
    

    将 run-storage-app 替换为您的复合应用模板标识符。

  2. 将 Cloud Run 组件添加到应用模板:

    gcloud design-center spaces application-templates components create cloud-run-comp \
        --application-template="run-storage-app" \
        --space="default-space" \
        --location="us-central1" \
        --shared-template-revision-uri="projects/PROJECT_ID/locations/us-central1/spaces/default-space/sharedTemplates/RUN_SHARED_TEMPLATE_ID/revisions/r-1"
    

    将 RUN_SHARED_TEMPLATE_ID 替换为您检索到的 cloud-run-component 共享模板 ID。

  3. 将 Cloud Storage 组件添加到应用模板:

    gcloud design-center spaces application-templates components create cloud-storage-comp \
        --application-template="run-storage-app" \
        --space="default-space" \
        --location="us-central1" \
        --shared-template-revision-uri="projects/PROJECT_ID/locations/us-central1/spaces/default-space/sharedTemplates/STORAGE_SHARED_TEMPLATE_ID/revisions/r-1"
    

    将 STORAGE_SHARED_TEMPLATE_ID 替换为您检索到的 cloud-storage-component 共享模板 ID。

  4. 创建从 Cloud Run 服务到 Cloud Storage 存储桶的连接。这会将存储桶输出关联到服务环境变量,并向服务账号授予 IAM 访问权限:

    gcloud design-center spaces application-templates components connections create run-to-storage \
        --component=cloud-run-comp \
        --application-template="run-storage-app" \
        --space="default-space" \
        --location="us-central1" \
        --destination-component-uri="projects/PROJECT_ID/locations/us-central1/spaces/default-space/applicationTemplates/run-storage-app/components/cloud-storage-comp" \
        --source-component-parameters='[{"key": "bucket_name", "value": "module.cloud-storage-comp.bucket_name"}]' \
        --destination-component-parameters='[{"key": "writer_service_account", "value": "module.cloud-run-comp.service_account_email"}]'
    
  5. 提交应用模板以生成不可变的模板修订版本:

    gcloud design-center spaces application-templates commit "run-storage-app" \
        --space="default-space" \
        --location="us-central1"
    

    命令输出会确认生成的修订版本标识符(例如 r-1),您在 App Lifecycle Manager 中创建 SaaS 产品时将引用该标识符。


使用 App Lifecycle Manager 部署客户环境

使用 App Lifecycle Manager 将应用模板转换为可部署的产品,并为每个客户预配专用环境。

打包应用模板

向 App Lifecycle Manager 注册模板修订版本,以创建可部署的 SaaS 产品:

  1. 在 us-central1 中创建 SaaS 产品:

    gcloud beta app-lifecycle-manager saas create "saas-run-storage" \
        --location="us-central1" \
        --locations=name="us-central1" \
        --application-template="projects/PROJECT_ID/locations/us-central1/spaces/default-space/applicationTemplates/run-storage-app" \
        --application-template-revision="projects/PROJECT_ID/locations/us-central1/spaces/default-space/applicationTemplates/run-storage-app/revisions/r-1"
    

    将 saas-run-storage 替换为您的 SaaS 产品标识符。

  2. 列出生成的发布版本,以检索发行 ID、单元种类和输入变量:

    gcloud beta app-lifecycle-manager releases list \
        --location="us-central1"
    

    App Lifecycle Manager 会异步构建和打包复合模板的蓝图。如果列表为空,请等待几分钟,然后重新运行该命令。

    该命令会输出以下信息:

    • name 字段(例如 projects/PROJECT_ID/locations/us-central1/releases/r-r-1-06c6a0)。尾随片段是您的 RELEASE_ID(例如 r-r-1-06c6a0)。
    • unitKind 字段(例如 projects/PROJECT_ID/locations/us-central1/unitKinds/u-native-components-e97e0c)。尾随片段是您的 UNIT_KIND_ID(例如 u-native-components-e97e0c)。

创建部署服务账号

创建一个服务账号,以便授予 App Lifecycle Manager 代表您预配资源的权限:

  1. 创建执行服务账号:

    gcloud iam service-accounts create "tenant-actuation-sa" \
        --display-name="Tenant Actuation Service Account"
    

    将 tenant-actuation-sa 替换为您的执行服务账号的名称。

  2. 构建服务账号邮箱并检索 App Lifecycle Manager 服务代理身份:

    ACTUATION_SA="tenant-actuation-sa@PROJECT_ID."
    ALM_P4SA="service-${PROJECT_NUM}@gcp-sa-saasservicemgmt."
    INFRA_MANAGER_P4SA="service-${PROJECT_NUM}@gcp-sa-config."
    
  3. 向执行服务账号授予创建和管理租户基础架构所需的角色:

    gcloud projects add-iam-policy-binding "PROJECT_ID" \
        --member="serviceAccount:${ACTUATION_SA}" \
        --role="roles/run.admin" \
        --condition=None
    
    gcloud projects add-iam-policy-binding "PROJECT_ID" \
        --member="serviceAccount:${ACTUATION_SA}" \
        --role="roles/storage.admin" \
        --condition=None
    
    gcloud projects add-iam-policy-binding "PROJECT_ID" \
        --member="serviceAccount:${ACTUATION_SA}" \
        --role="roles/iam.serviceAccountAdmin" \
        --condition=None
    
    gcloud projects add-iam-policy-binding "PROJECT_ID" \
        --member="serviceAccount:${ACTUATION_SA}" \
        --role="roles/iam.serviceAccountUser" \
        --condition=None
    
    gcloud projects add-iam-policy-binding "PROJECT_ID" \
        --member="serviceAccount:${ACTUATION_SA}" \
        --role="roles/config.admin" \
        --condition=None
    
  4. 向 App Lifecycle Manager 和 Infra Manager 服务代理授予模拟执行启动操作的服务账号的权限:

    gcloud iam service-accounts add-iam-policy-binding "${ACTUATION_SA}" \
        --member="serviceAccount:${ALM_P4SA}" \
        --role="roles/iam.serviceAccountUser" \
        --condition=None
    
    gcloud iam service-accounts add-iam-policy-binding "${ACTUATION_SA}" \
        --member="serviceAccount:${ALM_P4SA}" \
        --role="roles/iam.serviceAccountTokenCreator" \
        --condition=None
    
    gcloud iam service-accounts add-iam-policy-binding "${ACTUATION_SA}" \
        --member="serviceAccount:${INFRA_MANAGER_P4SA}" \
        --role="roles/iam.serviceAccountUser" \
        --condition=None
    

为客户部署环境

创建客户环境并触发其专用基础设施的部署:

  1. 使用生成的单元种类创建一个代表隔离客户租户的环境 Unit:

    gcloud beta app-lifecycle-manager units create "tenant-1" \
        --location="us-central1" \
        --unit-kind="UNIT_KIND_ID"
    

    将 tenant-1 替换为您的租户单元标识符。

  2. 触发单元操作以预配租户基础设施:

    gcloud beta app-lifecycle-manager unit-operations create provision-tenant-1 \
        --location="us-central1" \
        --unit="projects/PROJECT_ID/locations/us-central1/units/tenant-1" \
        --provision \
        --provision-release="RELEASE_ID" \
        --provision-input-variables=variable=project_id,value="PROJECT_ID",type=string \
        --provision-input-variables=variable=project_number,value="${PROJECT_NUM}",type=string \
        --provision-input-variables=variable=actuation_sa,value="${ACTUATION_SA}",type=string \
        --provision-input-variables=variable=cloud-run-comp_project_id,value="PROJECT_ID",type=string \
        --provision-input-variables=variable=cloud-run-comp_region,value="us-central1",type=string \
        --provision-input-variables=variable=cloud-storage-comp_project_id,value="PROJECT_ID",type=string \
        --provision-input-variables=variable=cloud-storage-comp_region,value="us-central1",type=string
    
  3. 描述单元操作以监控预配状态,直到其达到 SUCCEEDED:

    gcloud beta app-lifecycle-manager unit-operations describe provision-tenant-1 \
        --location="us-central1"
    

在客户环境中自动执行更新

使用发布功能在所有客户环境中安全地部署应用更新。

选择更新策略

定义如何将更新交付到客户环境,例如一次性部署或分阶段部署:

  1. 创建一个 RolloutKind,为您的单元定义编排策略:

    gcloud beta app-lifecycle-manager rollout-kinds create "progressive-rollout" \
        --location="us-central1" \
        --unit-kind="projects/PROJECT_ID/locations/us-central1/unitKinds/UNIT_KIND_ID" \
        --rollout-orchestration-strategy="Google.Cloud.Simple.AllAtOnce"
    

    将 progressive-rollout 替换为发布种类标识符。

部署和跟踪更新

开始发布并监控其进度,直到部署完成:

  1. 触发发布,以便在符合条件的租户单元中部署您的版本:

    gcloud beta app-lifecycle-manager rollouts create "rollout-v1" \
        --location="us-central1" \
        --rollout-kind="projects/PROJECT_ID/locations/us-central1/rolloutKinds/progressive-rollout" \
        --release="projects/PROJECT_ID/locations/us-central1/releases/RELEASE_ID"
    

    将 rollout-v1 替换为发布的标识符。

  2. 描述发布以检查活跃执行并验证状态是否达到 SUCCEEDED:

    gcloud beta app-lifecycle-manager rollouts describe "rollout-v1" \
        --location="us-central1"
    

    发布输出会确认您的租户单元已更新为目标模板修订版本。

清理

为避免因本教程中使用的资源导致您的 Google Cloud 账号产生费用,请删除包含这些资源的项目,或者保留项目但删除各个资源。

删除项目

删除 Google Cloud 项目:

gcloud projects delete PROJECT_ID

删除各个资源

如果您将教程资源部署到了现有项目中,请按依赖关系的逆序删除各个资源,以防止产生意外费用:

  1. 取消预配客户环境基础设施,并等待完成:

    gcloud beta app-lifecycle-manager unit-operations create deprovision-tenant-1 \
        --location="us-central1" \
        --unit="projects/PROJECT_ID/locations/us-central1/units/tenant-1" \
        --deprovision
    
    gcloud beta app-lifecycle-manager unit-operations describe deprovision-tenant-1 \
        --location="us-central1"
    
  2. 删除 App Lifecycle Manager 客户环境:

    gcloud beta app-lifecycle-manager units delete "tenant-1" \
        --location="us-central1" \
        --quiet
    
  3. 按依赖项的反向顺序删除 App Lifecycle Manager 部署和发布资源:

    gcloud beta app-lifecycle-manager rollouts delete "rollout-v1" \
        --location="us-central1" \
        --quiet
    
    gcloud beta app-lifecycle-manager rollout-kinds delete "progressive-rollout" \
        --location="us-central1" \
        --quiet
    
    gcloud beta app-lifecycle-manager releases delete "RELEASE_ID" \
        --location="us-central1" \
        --quiet
    
    gcloud beta app-lifecycle-manager unit-kinds delete "UNIT_KIND_ID" \
        --location="us-central1" \
        --quiet
    
    gcloud beta app-lifecycle-manager saas delete "saas-run-storage" \
        --location="us-central1" \
        --quiet
    
  4. 删除 App Design Center 应用模板、目录条目和空间:

    gcloud design-center spaces application-templates delete "run-storage-app" \
        --space="default-space" \
        --location="us-central1" \
        --force \
        --quiet
    
    gcloud design-center spaces catalogs templates delete "cloud-run-component" \
        --space="default-space" \
        --catalog="default-catalog" \
        --location="us-central1" \
        --force \
        --quiet
    
    gcloud design-center spaces catalogs templates delete "cloud-storage-component" \
        --space="default-space" \
        --catalog="default-catalog" \
        --location="us-central1" \
        --force \
        --quiet
    
    gcloud design-center spaces delete "default-space" \
        --location="us-central1" \
        --force \
        --quiet
    
  5. 删除 Developer Connect Git 代码库链接和连接:

    gcloud developer-connect connections git-repository-links delete "GIT_REPO_LINK_ID" \
        --connection="CONNECTION_ID" \
        --location="us-central1" \
        --quiet
    
    gcloud developer-connect connections delete "CONNECTION_ID" \
        --location="us-central1" \
        --quiet
    
  6. 删除执行启动操作的服务账号:

    gcloud iam service-accounts delete "${ACTUATION_SA}" \
        --quiet
    

后续步骤