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
- 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:
gcloud compute disks create CLONE_DISK \ --description="cloned disk" \ --source-disk=projects/PROJECT/zones/ZONE/disks/SOURCE_VM_DISK
- Create the clone of the VM. For information, see Create a VM similar to an existing VM.
- In the Advanced options section, attach the cloned disk.
- Create the VM.
- Verify that the server is running for this VM. The startup script ensures that the VM is running.
- Stop and remove connector-service in docker.
- 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.
- Edit the VM and select the deletion rule to Keep disk
- Delete this VM.
- For creating the licensed image, get the license from the producer portal. Visit Producer portal
- Create a new Virtual Machine product. Visit the Deployment Package section and copy the VM license.
- To create the licensed VM image, run the following command:
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
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.
- Add the details of your solution:
- For connectors, create a module with a VM. Enter the project name, VM image name and labels for the image in your public project.
- 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
- Use pd-standard as the default disk type.
bootDisk: diskType: defaultType: pd-standard
- Add the startup script to the autogen config. Stringify the startup script and add it in bashScriptContent.
gceStartupScript: bashScriptContent:
- 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: 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: {}
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.
- 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
- 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: 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.
- To setup the autogen, run the following command:
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
- To generate the terraform module, run the following command:
mkdir solution_folder autogen \ --input_type YAML \ --single_input example-config/solution.yaml \ --output_type PACKAGE \ --output solution_folder
The solution_folder contains the terraform module. This module will be used while publishing products on Marketplace.
solutionInfo: name:packagedSoftwareGroups: - type: SOFTWARE_GROUP_OS components: - name: Ubuntu version: 16.04 LTS - components: - name: Apache version: 2.4.23
What's next
- Learn how to submit the VM image for approval.