查看 Application Integration 支援的連接器

為 VM 建立 Terraform 部署模組

本頁面說明如何建立虛擬機器 (VM) 和 VM 的 Terraform 部署模組。

建立授權的 VM 映像檔

  1. 為確保開發 VM 不受影響,請執行下列 gcloud 指令,為 VM 中使用的磁碟建立副本:
    gcloud compute disks create CLONE_DISK \ --description="cloned disk" \ --source-disk=projects/PROJECT/zones/ZONE/disks/SOURCE_VM_DISK
  2. 建立 VM 的複本。詳情請參閱「建立與現有 VM 相似的 VM」。
  3. 在「Advanced options」部分中,連接複製的磁碟。
  4. 建立 VM。
  5. 確認伺服器是否正在為這個 VM 執行。開機指令碼可確保 VM 正在執行。
  6. 停止並移除 Docker 中的連接器服務。
  7. 移除主目錄和其他執行伺服器時不需要的檔案。系統會使用相同的磁碟建立 VM 映像檔,客戶稍後可存取該映像檔。這個 VM 必須只包含執行服務所需的程式庫。
  8. 編輯 VM 並選取「刪除規則」以「保留磁碟」
  9. 刪除這個 VM。
  10. 如要建立授權的圖片,請從 Producer Portal 取得授權。前往Producer Portal
  11. 建立新的虛擬機器產品。前往「部署套件」部分,並複製 VM 授權。
  12. 如要建立授權的 VM 映像檔,請執行下列指令:
  13. gcloud compute images create VM_IMAGE_NAME \
     --project PUBLIC_PROJECT_NAME \
     --source-disk projects/DEV_PROJECT_NAME/zones/ZONE/disks/SOURCE_VM_DISK \
     --licenses LICENSE \
     --description VM_IMAGE_DESCRIPTION

    詳情請參閱「建構 VM」一文。

建立 Terraform 部署模組

Marketplace 提供自動產生工具,可產生 Terraform 模組,用於在 Marketplace 上部署 VM 映像檔。

這項工具會使用 Autogen proto 定義產生部署作業。詳情請參閱「設定範例」。

  1. 新增解決方案詳細資料:
  2. solutionInfo:
      name: 
      packagedSoftwareGroups:
        - type: SOFTWARE_GROUP_OS
          components:
            - name: Ubuntu
              version: 16.04 LTS
        - components:
            - name: Apache
              version: 2.4.23
  3. 針對連接器,請使用 VM 建立模組。在公開專案中輸入映像檔的專案名稱、VM 映像檔名稱和標籤
  4. 使用 n2d-standard-2 做為預設機器類型,其中 CPU 最小值為 2,RAM 為 8 GB。N2d-standard 最適合中等流量的網路伺服器。預設的 VM 可設定為 2 個核心。如果客戶希望流量更高,可以在 Marketplace 中建立 VM 時變更這項設定。如要瞭解不同機器類型的定價,請參閱「VM 執行個體定價」。
        machineType:
          # Check http://cloud.google.com/compute/docs/machine-types for all available types
          defaultMachineType:
            gceMachineType: n2d-standard-2
          # Minimum CPU and memory constraints for the machine type to run your solution properly
          minimum:
            cpu: 2
            ramGb: 8
  5. 使用 pd-standard 做為預設磁碟類型。
        bootDisk:
          diskType:
            defaultType: pd-standard
  6. 將開機指令碼加入自動產生設定。將開機指令碼轉為字串,並新增至 bashScriptContent。
    gceStartupScript:
       bashScriptContent: 
  7. 定義輸入欄位,以便在建立 VM 時,將其視為客戶輸入內容。
        deployInput:
          sections:
            # The place int he Deployment Manager config that this section will appear. More details in deployment_package_autogen_spec.proto
            - placement: CUSTOM_TOP
              name: CONNECTOR_SETTINGS
              title: Connectors settings
              description: Connectors settings
              tooltip: Setting with which connector VM will be running
              # List of input fields that this section has
              fields:
                - required: false
                  name: TEST_DATA
                  title: Test Data
                  description: Test data
                  tooltip: random data for testing
                  string_box: {}
                - required: false
                  name: PORT
                  title: Port to run service
                  tooltip: Port to run connector service
                  string_box: {}
                - required: false
                  name: LOG_LEVEL
                  title: Log level
                  description: Log level for the web service. Allowed values are DEBUG, INFO, WARNING, ERROR. Default is INFO
                  string_box: {}

    請將刊登位置保留為 CUSTOM_TOP,名稱則為 CONNECTOR_SETTINGS

    定義欄位和所需的輸入類型。在本範例中,Marketplace 連接器的客戶會看到「Test Data」和「Port to run service」欄位。

  8. 定義 Compute Engine 中繼資料項目。定義 VM 中繼資料時,將輸入欄位的名稱對應至中繼資料鍵。
        gce_metadata_items:
          - key: CONNECTOR_ENV_PORT
            value_from_deploy_input_field: PORT
          - key: CONNECTOR_ENV_TEST_DATA
            value_from_deploy_input_field: TEST_DATA
    - key: CONNECTOR_ENV_LOG_LEVEL
            value_from_deploy_input_field: LOG_LEVEL
  9. 新增部署後會向客戶顯示的步驟詳細資料。
        postDeploy:
          # List of suggested action items for users, after deployment is successful
          actionItems:
            - heading: Create the Private service attachment
              description: Now the connector service is running on the VM, please create the PSC service attachment to create the connection. Follow https://cloud.google.com/integration-connectors/docs/configure-psc for the detailed guide.
            - heading: Create the connection
              description: After creating the connectors endpoint attachment, use the endpoint attachment to create a connection to the partner connector.
  10. 如要設定自動產生功能,請執行下列指令:
    alias autogen='docker run \
      --rm \
      --workdir /mounted \
      --mount type=bind,source="$(pwd)",target=/mounted \
      --user $(id -u):$(id -g) \
      gcr.io/cloud-Marketplace-tools/dm/autogen'
    
    autogen --help
  11. 如要產生 Terraform 模組,請執行下列指令:
    mkdir solution_folder
    
    autogen \
      --input_type YAML \
      --single_input example-config/solution.yaml \
      --output_type PACKAGE \
      --output solution_folder

    solution_folder 包含 terraform 模組。您可以在 Marketplace 上發布產品時使用這個模組。

後續步驟