Create a Terraform deployment module for the VM

This page describes how to create a virtual machine (VM) and Terraform deployment module for the VM.

Create the licensed VM Image

  1. To ensure that the development VM is non impacted, create a copy of the disk used in the VM by running the following gcloud command:
    gcloudcomputediskscreateCLONE_DISK\ --description="cloned disk"\ --source-disk=projects/PROJECT/zones/ZONE/disks/SOURCE_VM_DISK
  2. Create the clone of the VM. For information, see Create a VM similar to an existing VM.
  3. In the Advanced options section, attach the cloned disk.
  4. Create the VM.
  5. Verify that the server is running for this VM. The startup script ensures that the VM is running.
  6. Stop and remove connector-service in docker.
  7. Remove the home directory and any other file which is not required for running the server. The same disk will be used for creating the VM image and will be accessible by customers later. This VM must only have libraries required for running the service.
  8. Edit the VM and select the deletion rule to Keep disk
  9. Delete this VM.
  10. For creating the licensed image, get the license from the producer portal. Visit Producer portal.
  11. Create a new Virtual Machine product. Visit the Deployment Package section and copy the VM license.
  12. To create the licensed VM image, run the following command:
  13. gcloudcomputeimagescreateVM_IMAGE_NAME\
    --projectPUBLIC_PROJECT_NAME\
    --source-diskprojects/DEV_PROJECT_NAME/zones/ZONE/disks/SOURCE_VM_DISK\
    --licensesLICENSE\
    --descriptionVM_IMAGE_DESCRIPTION

    For more information, see Building your VM.

Create a terraform deployment module

Marketplace provides the Autogen tool to generate the terraform modules for the deployment of VM image on Marketplace.

This tool uses Autogen proto definition to generate the deployment. For more information, see Example config.

  1. Add the details of your solution:
  2. solutionInfo:
    name:
    packagedSoftwareGroups:
    -type:SOFTWARE_GROUP_OS
    components:
    -name:Ubuntu
    version:16.04LTS
    -components:
    -name:Apache
    version:2.4.23
  3. For connectors, create a module with a VM. Enter the project name, VM image name and labels for the image in your public project.
  4. Use n2d-standard-2 as the default machine type with min CPU as 2 and RAM as 8 Gb. N2d-standard is optimal for medium traffic web servers. The default VM can be set with 2 cores. If customers expect higher traffic, this can be changed during the VM creation from the Marketplace. For information about pricing for different machine types, see VM instance pricing.
    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. Use pd-standard as the default disk type.
    bootDisk:
    diskType:
    defaultType:pd-standard
  6. Add the startup script to the autogen config. Stringify the startup script and add it in bashScriptContent.
    gceStartupScript:
    bashScriptContent:
  7. Define the input fields which will be taken as input from customers during VM creation.
    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:Connectorssettings
    description:Connectorssettings
    tooltip:SettingwithwhichconnectorVMwillberunning
    # List of input fields that this section has
    fields:
    -required:false
    name:TEST_DATA
    title:TestData
    description:Testdata
    tooltip:randomdatafortesting
    string_box:{}
    -required:false
    name:PORT
    title:Porttorunservice
    tooltip:Porttorunconnectorservice
    string_box:{}
    -required:false
    name:LOG_LEVEL
    title:Loglevel
    description:Loglevelforthewebservice.AllowedvaluesareDEBUG,INFO,WARNING,ERROR.DefaultisINFO
    string_box:{}

    Keep the placement as CUSTOM_TOP and name as CONNECTOR_SETTINGS.

    Define the field, and the type of input required for them. In this example, the Test Data and Port to run service fields appear for the customers of the Marketplace connector.

  8. Define the Compute Engine metadata items. While defining the VM metadata. Map the name of the input field to the metadata key.
    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. Add the steps details which will be shown to customers post deployment.
    postDeploy:
    # List of suggested action items for users, after deployment is successful
    actionItems:
    -heading:CreatethePrivateserviceattachment
    description:NowtheconnectorserviceisrunningontheVM,pleasecreatethePSCserviceattachmenttocreatetheconnection.Followhttps://cloud.google.com/integration-connectors/docs/configure-pscforthedetailedguide.
    -heading:Createtheconnection
    description:Aftercreatingtheconnectorsendpointattachment,usetheendpointattachmenttocreateaconnectiontothepartnerconnector.
  10. To setup the autogen, run the following command:
    aliasautogen='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. To generate the terraform module, run the following command:
    mkdirsolution_folder
    autogen\
    --input_typeYAML\
    --single_inputexample-config/solution.yaml\
    --output_typePACKAGE\
    --outputsolution_folder

    The solution_folder contains the terraform module. This module will be used while publishing products on Marketplace.

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年12月09日 UTC.