Virtual machine (VM) products offered through Google Cloud Marketplace are custom VM instances that you can run on Compute Engine. For an overview of Compute Engine concepts, visit the Compute Engine documentation.
Some VM products on Google Cloud Marketplace support deployment through the command-line interface (CLI) using Terraform, an open-source tool for provisioning and managing infrastructure. For more information on Terraform, visit Get started with Terraform.
Overview
This page describes the steps for deploying VM products through the CLI by using Terraform. At a high level, you:
Visit the Command-line deployment tab from the product's Google Cloud Marketplace listing.
Optionally, select or create the service account that you want to use for your command-line deployment.
Optionally, set up service account impersonation.
Configure your
gcloud
environment for Terraform.Verify the resource name of the VM image that you want to deploy through the CLI.
Generate a code snippet to deploy the VM product through the CLI by using Terraform.
Use the code snippet to deploy the VM product.
Visit the command-line deployment tab
To start deploying a VM product through the CLI:
In Cloud Marketplace, visit the product listing page for the VM product that you want to deploy through the CLI.
Verify that the product supports command-line deployment. If the product supports command-line deployment, you see a Deploy with CLI button.
Click Deploy with CLI to visit the Command-line deployment tab.
(Optional) Select or create your service account
Within the Command-line deployment tab, you can choose to select or create the service account that you want to use for your command-line deployment. If you haven't selected or created a service account in the Command-line deployment tab when you generate your code snippet, you must manually edit the generated Terraform snippet to add a service account before you use it. For more information about service accounts, visit Creating and managing service accounts.
If you want to deploy a Cloud Marketplace VM product through the CLI, the
service account that you use must have the
Compute Admin (roles/compute.admin
) Identity and Access Management (IAM) role.
If you create a new service account from the Command-line deployment tab,
Google Cloud Marketplace automatically grants this role to the new service account. If
you select an existing service account from the Command-line deployment tab,
you must verify that the service account has this role.
To select or create your service account:
From the Command-line deployment tab of the VM product's Google Cloud Marketplace listing, under Configure a service account (optional), click the Configure button.
Under Service account requesting permissions, you can click to Select an existing service account, or Create a new service account.
Select an existing service account
To select an existing service account:
Under Select a service account, select the service account that you want to use. The list contains all of your existing service accounts that have the Compute Admin (
roles/compute.admin
) role.If none of your existing service accounts have the Compute Admin (
roles/compute.admin
) role, the list is empty. If the list is empty, you can grant this role to one of your existing service accounts and then return to this tab, or you can choose to create a new service account instead.Click the Submit button.
Create a new service account
To create a new service account:
Choose a name for your service account, and add it in the Service account name field.
Choose an ID for your service account, and add it in the Service account ID field.
Add a description for your service account to the Service account description field.
Click the Create service account button.
After you've created your service account, you can continue to manage the service account's access control by using IAM.
(Optional) Set up service account impersonation
We recommend that you use service account impersonation to manage access to
your command-line deployment. If you use impersonation, instead of creating
service account keys that anyone can use to access your deployment, you manage
access by granting or revoking the
Service Account Token Creator (roles/iam.serviceAccountTokenCreator
) IAM role
to specific principals.
To learn how to grant and revoke roles on a service accounts, see Manage access to service accounts. To learn more about service account impersonation, see Service account impersonation.
Configure your gcloud environment for Terraform
In the Command-line deployment tab, under Configure gcloud, you see a
series of commands. To configure your gcloud
environment for Terraform, you
can copy and run the provided commands.
Verify the resource name of the VM image you want to deploy
To deploy a VM image from Cloud Marketplace through the CLI, you need the resource name of the VM image.
When you use the Command-line deployment tab to generate a code snippet for deploying a VM image through the CLI, Google Cloud Marketplace uses the resource name of the default VM image for the product in the code snippet.
If you want to use the code snippet to deploy a VM image that isn't the product's default VM image, you must replace the resource name of the VM image in the code snippet with the resource name of the VM image that you want to deploy through the CLI.
To locate the resource name of the VM image you want to deploy:
From the Command-line deployment tab of the VM product's Cloud Marketplace listing, under Review VM images, review the list of VM images.
To copy the resource name of the VM image that you want to deploy through the CLI, click the Copy icon.
Generate a code snippet to use to deploy the product
To generate a code snippet:
From the Command-line deployment tab of the VM product's Cloud Marketplace listing, click the Generate code button. This generates a code snippet that you can copy and use with Terraform to deploy a VM with Terraform.
To copy the code snippet, click Copy to clipboard.
Use the code snippet to deploy the VM product
To use the generated code snippet to deploy the VM product through the CLI:
Verify that the code snippet includes the service account you want to use. If you've configured a service account for your command-line deployment, that service account's information is included in the generated code snippet. If you haven't configured a service account, you must edit the generated code snippet to specify the service account that you want to use.
Verify that the code snippet specifies the resource name of the VM image that you want to deploy. If you want to deploy a VM image that isn't the default VM image for the product you're deploying, you must locate the resource name of the VM image that you want to deploy and edit the code snippet to specify that resource name.
Create a new file named
main.tf
on the machine where you've installed Terraform.Paste the generated code snippet, with any edits you've made to it, into the
main.tf
file you created.Run the following commands:
terraform init
terraform apply
Next steps
For information on managing your CLI deployments of VM products, visit Manage CLI deployments of VM products.