Let’s look at the Cloud Deployment Manager, an infrastructure automation tool from Google Cloud, Google’s Infrastructure as Code (IaC) offering, that automates the creation and management of Google Cloud resources. Infrastructure as Code (IaC) is the managing and provisioning of infrastructure through code instead of through manual processes like provision virtual machine instances in the cloud console.
With IaC, configuration files are created that contain our infrastructure specifics, which makes it easier to edit and distribute configurations. It also ensures that we provision the same environment every time.
This is the similar IaC offering to Amazon’s AWS CloudFormation, Microsoft’s Azure Resource Manager and the open-source IaC, Terraform (a cloud agnostic solution).
Cloud Deployment manager only works within Google Cloud Platform and has many similarities to the AWS CloudFormation template, albeit less mature.
Deployment is a Unit
One concept that is important to consider with Deployment Manager, is that the entire deployment is handled in a unit, called a deployment. In the AWS world with CloudFormation, this is known as a stack. For example, if your team’s development environment needs two virtual machines (VMs) and a database, you would define these resources in a configuration file (the unit), and use Deployment Manager to create, change, or delete these resources. You can make the configuration file part of your team’s code repository, so that anyone can create the same environment with consistent results.
The configuration file we will use to describe our resources is a YAML file, such as vmcreator.yaml. This file has a resources group where we define all resources within the unit. Each resource must contain three components:
- name: a user-defined string to identify this resource, such as quickstart-deployment-vm.
- type – The type of resource being deployed, such as compute.v1.instance.
- properties – The parameters for this resource type. They must match the properties for the type, such as disks.
Here is an example YAML configuration file from Google:
Supported Resource Types and Properties
As we noted, the type and properties within the YAML resource file need to be specific to supported values from Google. To get a list of supported types, goto: https://cloud.google.com/deployment-manager/docs/configuration/supported-resource-types
This document will show us a list of deployment types. In the list here you will note our example resource type, compute.v1.instance is listed as a valid type.
If you click Documentation for the type, you will see the supported properties. Note our example property, disks, is listed as a supported property.
How to Deploy Resources
Let’s look at deploying resources through the Google Cloud Shell. First, go to your Cloud Console and click Active Cloud Shell.
Once the Cloud Shell has been activated, click Open Editor and once opened, click Open in a new window
Create a New File and call it sample.YAML. Paste your YAML code into the file as seen here.
Click File -> Save
Now go back to the Cloud Shell, and run an ls to make sure you see your new file listed.
Next, find your project ID from the console dashboard as we will use it in our next command.
Now back in the console and type gcloud config set project <insert your project ID> to set the active project based on your project ID.
To deploy our YAML file, now type gcloud deployment-manager deployments create compute-gcs –config sample.YAML
The deployment should now be underway:
In the meantime, within the console we can open up Deployment Manager and note our deployment is underway:
And click the active deployment to view the status.
This console will also list any errors if they were to arise here.
You will also notice your resource should be created within the proper resource area, such as the virtual machine instance in Compute Engine: