建立以 Deployment Manager 為基礎的解決方案
為貴機構的使用者建立 Service Catalog 解決方案時,您可以建立 Deployment Manager (DM) 解決方案,讓使用者使用 Deployment Manager 範本啟動解決方案。建立解決方案後,您可以將其新增至目錄,與使用者共用。
事前準備
您必須擁有與已啟用服務目錄的 Google Cloud 專案相關聯的 Google Cloud機構組織的「目錄管理員」(
roles/cloudprivatecatalogproducer.admin
) 或「目錄管理員」(roles/cloudprivatecatalogproducer.manager
) 角色。如果您不具備這個角色,請與機構管理員聯絡,要求取得存取權。-
Enable the Cloud Deployment Manager and Compute Engine APIs.
準備部署範本
如要在 Service Catalog 中建立 Deployment Manager 解決方案,請先準備要上傳的 Deployment Manager 範本 .zip 檔案,該檔案必須包含下列檔案:
- 結尾為
.jinja
副檔名的 Jinja 範本檔案,或結尾為.py
副檔名的 Python 範本檔案。 - 結構定義檔案:如果是 Jinja 範本,副檔名結尾為
.jinja.schema
;如果是 Python 範本,副檔名結尾為py.schema
。
ZIP 檔案的名稱必須與結構定義和 Jinja 或 Python 檔案的名稱相符。舉例來說,如果 ZIP 檔案名稱為 android-dev-environment.zip
,則 ZIP 檔案中的 Jinja 結構定義檔案名稱必須為 android-dev-environment.jinja.schema
,而 Jinja 範本的名稱則必須為 android-dev-environment.jinja
。
以下程式碼範例說明如何使用結構定義檔案建立部署表單:
info:
title: Single Google Compute Engine Machine
author: Google Inc.
description: Creates a virtual machine based on zone and machine type selection.
required:
- machinetype
- zone
properties:
machinetype:
title: Machine type
type: string
enum:
- n2-standard-2
- n2-standard-4
- n2-standard-8
- n2-highmem-2
- n2-highmem-4
- n2-highmem-8
- n2-highcpu-2
- n2-highcpu-4
- n2-highcpu-8
zone:
title: Zone
type: string
enum:
- us-central1-a
- us-central1-c
- us-east1-b
- us-east1-c
- us-west1-a
- us-west1-b
- us-west1-c
以下程式碼範例說明如何使用 Jinja 檔案建立永久性 VM:
# Creates a Persistent VM
resources:
- type: compute.v1.instance
name: vm-{{ env["deployment"] }}
properties:
zone: {{ properties["zone"] }}
# Note the machineType definition at the end. n2-custom-4-5120 specifies n2 machine family with 4 CPUs and 5GB (5120 MB) of RAM. For custom machine types, refer to https://cloud.google.com/compute/docs/instances/creating-instance-with-custom-machine-type
machineType: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/zones/{{ properties["zone"] }}/machineTypes/{{ properties["machinetype"] }}
disks:
- deviceName: boot
type: PERSISTENT
boot: true
autoDelete: true
initializeParams:
diskName: disk-{{ env["deployment"] }}
sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-9
networkInterfaces:
- network: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/global/networks/default
# Access Config required to give the instance a public IP address
accessConfigs:
- name: External NAT
type: ONE_TO_ONE_NAT
在 Service Catalog 中建立解決方案
如要建立以 Deployment Manager 範本為基礎的解決方案,請按照下列步驟操作:
前往 Google Cloud 控制台的「服務目錄管理」解決方案頁面。
前往「解決方案」頁面按一下「選取」,選擇 Google Cloud 專案。
按一下「建立解決方案」。在下拉式清單中,選取「建立 DM 解決方案」。
輸入解決方案的名稱、說明和標語。標語是使用者瀏覽 Service Catalog 時看到的解決方案簡短說明。
上傳內含部署設定檔案的 ZIP 檔案。
您可以選擇上傳解決方案的圖示。建議的圖示尺寸為 80 x 80 像素。
視需要輸入創作者的支援連結和聯絡資訊。
視需要新增解決方案的說明文件連結。
點選「建立」。
下圖說明如何建立以 DM 為基礎的解決方案:

後續步驟
- 將解決方案指派給目錄,以便機構中的使用者存取及部署解決方案。