How to Configure VM instance using Deployment Manager Templates?

How to Configure VM instance using Deployment Manager Templates?



27 May 2019

What is Deployment Manager (DM)?

If you are not aware of what is Deployment Manager in GCP ecosystem, you might want to read What is Deployment Manager blog first.

Now, let’s see how to configure a VM instance using Deployment Manager (DM) templates in Google Cloud Platform.

Quickstart on Deployment Manager (DM)

This is just a quick start, on how to use Google Cloud Deployment Manager to deploy a virtual machine instance. The virtual machine is a resource, which can be added to a deployment configuration file. After creating a configuration file, you can use it to create a deployment, which is a collection of resources that can be created or managed together.

Your deployments will be containing dozens of resources from various Google Cloud services, and you will be using the Deployment Manager to manage them from a single file.

You can use Cloud Shell, where you can edit the sample configuration, and deploy your resources without installing anything on your computer: Open in Google Cloud Shell

What is a Template?

A template is a separate file from your configuration that defines a set of resources A template can be imported into your configuration. A cleaner, simpler configuration file is achievable as the deployment Manager expands the template and inlines the contents during deployment. After it has been imported, you can use a template in the same way you use a resource type.

In order to create more complex configurations, you can create a deployment using a configuration at any time. You should create and use templates for more flexible and robust configurations.

A template is created from the contents of the configuration. Then, importing it and using the template in your configuration to create a new deployment.

Finally, your new deployment will contain the same resources as your first deployment but the configuration file will be much simple.

configure VM instance using Deployment Manager Templates

Deployment Manager (DM)

The main advantage of Google Cloud Deployment Manager is that it allows you to specify all the resources needed for your application in a declarative format using yaml. It is also supported to use Python or Jinja2 templates to parameterize the configuration. The process of creating those resources can be repeated over and over with consistent results by creating configuration files which define the resources.

By default, Deployment Manager uses the credentials of the Google APIs service account to authenticate to other APIs. The Google APIs service account is specifically designed to run internal Google processes on your behalf.

Creating a Configuration

The primary step in creating your deployment is to creation of a configuration. A configuration is a list of resources and their respective properties. A configuration file starts with the resources string, followed by a list of resource entries, each with the following fields: Name, Type, Properties.

Resource Names

When a template is being used by you, your resource names are defined using the name field provided in the template, not the name in the configuration file.

Now, you will define a configuration that creates a deployment for single VM instance. By using the Cloud Shell Editor, create a yaml file by going to File > New > File and then naming your file. Start your configuration by declaring the resources string, followed by the virtual machine instance type and name.
Please note that “compute.v1.instance” is the type needed for creating a VM instance using Deployment Manager template.

Deploying the configuration

Suppose you named the deployment as “my-first-deployment” and the yaml file as “my-first-config.yaml”, deploy your configuration with the command “gcloud deployment-manager deployments create my-first-deployment –config my-first-config.yaml” in the Google Cloud Shell.


Deployment Manager is fine. It’s slightly hard to get started with it, as there are not many clear examples out there. Ironically, the ones that do exist sometimes not actually compatible with the latest APIs.

I wonder how Deployment Manager compares to its seemingly main competitor – HashiCorp’s Terraform. My gut feeling says that DM is probably less mature, but who knows. I probably should get to know Terraform better to be sure, but that will happen later. So far there are few interesting DM features to explore.

Now go forth and Automate All The Things!
If you implement these principles and methodologies in your application lifecycle management, you will make your life a lot easier. I hope you’ve found this blog post on “How to configure VM instance using Deployment Manager Templates” helpful.

Blog Categories
Request a quote