Skip to main content

Deploying Resources with Google Cloud Deployment Manager

Hands-On Lab

 

Photo of Matthew Ulasien

Matthew Ulasien

Team Lead Google Cloud in Content

Length

01:00:00

Difficulty

Intermediate

In this hands-on lab, we will introduce ourselves to working with Google Cloud Deployment Manager. We will start with a simple single-VM deployment, move on to a more complex deployment with multiple dependencies, and finish by deploying a group of imported template configurations in a single deployment.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Deploying Resources with Google Cloud Deployment Manager

Introduction

In this hands-on lab, we will introduce ourselves to working with Google Cloud Deployment Manager. We will start with a simple single-VM deployment, move on to a more complex deployment with multiple dependencies, and finish by deploying a group of imported template configurations in a single deployment.

Solution

Be sure to launch your lab in an incognito window (or other private web browser) to avoid issues with cached logins.

Download configuration files used for this lab

We will perform the majority of our activities in Cloud Shell.

  • From the web console, open Cloud Shell from the top-right
  • Download the configuration files we will use for this lab by copy/pasting the following command:

    gsutil -m cp -r gs://la-gcp-labs-resources/deployment-manager-basic/* .

> Note: The period at the end of the command is required.

Create your first single VM deployment

Before we create our first deployment, we must first edit our configuration file to reflect the current project.

  • From Cloud Shell, open the editor window by clicking the pencil icon in the top-right.

  • In the new window that appears, click on vm-web.yaml.

  • In the vm-web.yaml file, change all (YOUR_PROJECT) fields to reflect your current project ID. There should be 2 total.

    • Your project ID can be found here on the GCP Console page in the Project info section
  • Back in the command prompt, deploy your first deployment by typing the following:

    gcloud deployment-manager deployments create single-vm --config vm-web.yaml
  • Once the deployment completes, go to the web console and verify that a Compute Engine instance has been created. You should be able to click the external IP address to view its website.

  • Still in the web console, delete your deployment by going to the top-left menu > Deployment Manager. Select your deployment and click DELETE.

Deploy complex deployment with dependencies

We are now going to deploy a more complex deployment manager configuration that requires deploying resources in a certain order.

  • Back in the Cloud Shell Editor, select the file depedences.yaml.
  • Under the resource for server-1, scroll down to the NetworkInterfaces properties and notice that the network and subnetwork have a reference field supplied. This tells Deployment Manager that deploying this instance depends on other resources in the same deployment being created first. You can view other dependencies throughout the rest of the config file.
  • As before, change all (YOUR_PROJECT) to your current project ID.
  • Back in command prompt, deploy this configuration by typing the following:

    gcloud deployment-manager deployments create vpcs --config dependencies.yaml

View deployment manifest and delete deployment

After deployment is complete, let's view the manifest:

  • Still in command prompt, view details of your deployment:

    gcloud deployment-manager deployments describe vpcs
  • Look for a field in the form of manifest-(TIMESTAMP). Copy this field.

  • Type in the following to view the full manifest, supplying the manifest ID you copied above:

    gcloud deployment-manager manifests describe (manifest-(TIMESTAMP)) --deployment vpcs
  • You can also view the same manifests in the web console > Deployment Manager.

  • Delete your deployment using the following command:

    gcloud deployment-manager deployments delete vpcs

Create deployment with templates

  • In Cloud Shell, browse to your templates directory:

    cd templates
  • In the Code Editor, view the template-config.yaml and the template .jinja files.

  • This time, we do not need to change the project ID because the template files are able to automatically resolve the current project ID.

  • Deploy your template-enabled configuration by typing:

    gcloud deployment-manager deployments create templates --config template-config.yaml
  • View results in web console, and attempt to open website via external IP.

  • Delete deployment using one of the methods above.

Conclusion

Congratulations, you've completed this hands-on lab!