✏️

Cloud Deployment Manager Cheatsheet

Glossary

Configuration - describes all the resources you want for a single deployment. YAML. Must contain resources:.

Example
resources:
- name: the-first-vm
  type: compute.v1.instance
  properties:
    zone: us-central1-a
    machineType: https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/f1-micro
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20150423
    networkInterfaces:
    - network: https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT

Template - optional reusable individual building blocks of a Configuration. Python or Jinja2.

Example: Jinja2

A template vm-template.jinja:

- name: vm-template
  type: compute.v1.instance
  properties:
    zone: us-central1-a
    machineType: zones/us-central1-a/machineTypes/n1-standard-1
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: projects/debian-cloud/global/images/family/debian-9
    networkInterfaces:
    - network: global/networks/default

And a configuration my-configuration.yaml:

imports:
- path: vm_template.jinja

resources:
- name: vm-instance
  type: vm_template.jinja
  properties:
    zone: us-central1-a
    project: myproject

Translates into:

resources:
- name: vm-instance
  type: compute.v1.instance
  properties:
    machineType: zones/us-central1-a/machineTypes/n1-standard-1
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: projects/debian-cloud/global/images/family/debian-9
    networkInterfaces:
    - network: global/networks/default
    zone: us-central1-a
    project: myproject
Example: Python

It’s ugly. Don’t look at it. Just forget about Cloud Deployment Manager and use Terraform or gcloud CLI.

Resource - a single API resource, such as Compute Engine instance or a Cloud SQL instance. Each Resource must contain name, type and properties.

Type - single API resource, known as a base type (list of supported base types), or a template (aka “Composite type”).

Manifest - a record that contains the original fully expanded Configuration you provided.

Deployment - collection of resources deployed based on provided Configuration

Schema - defines a set of rules that a Configuration file must meet if it wants to use a particular Template. Structure.

Example
title: VM Template
  author: Jane
  description: Creates a new network and instance
  version: 1.0

imports:
- path: vm-instance.jinja # Must be a relative path

required:
- IPv4Range

properties:
  IPv4Range:
    type: string
    description: Range of the network

  description:
    type: string
    default: "My super great network"
    description: Description of network
vm-instance-with-network.jinja.schema

Outputs - key/value pairs that you can define in the Configuration or Templates that will show up in the Manifest after deployment. Example: IP address of a deployed VM.

Property - a static variable that you can use throughout Templates.

Reference - dynamic variables that are not defined until a Resource is created.

Example
resources:
- name: vm-a
  properties:
    zone: us-central1-f
    ...
    metadata:
      dependsOn:
      - vm-depends-on

# The second VM
- name: vm-depends-on
  properties:
    zone: $(ref.vm-a.zone)
    ...

Preview - shows resources that Deployment Manager would create if you create or update the Deployment. More.

Update Policy - how your resources are updated when you update the Deployment. More.

Best practices

Do not modify resources deployed with Deployment Manager using cloud console or gcloud. Instead, update the Deployment.

While it’s possible to include secret credentials in Configurations and Templates, and Deployment Manager will attempt to redact them, it’s still better to avoid doing so.

While Jinja2 is simpler and cleaner, it’s still recommended to use Python templates due to better flexibility. It looks ugly though... 🤢

Structure your Configuration file to use only one type, and use a top-level template to call all other templates... 🤮

Use labels. Duh...

Create many small Deployments, not one huge Deployment.

For large deployments arrange configs in a hierarchical structure in multiple files rather than single config per deployment.

Workflow

  1. Create config file. All static configs will be here.
  2. Create top-level template file, reference it in the config file.
  3. Open the Resources Types reference and map the services you need in the right order.
  4. Using the Resources Types reference, go to each of your deployment resources one by one and write static configuration for each of them.
  5. Run gcloud deployment-manager deployments create/update my-deployment --config deployment/deployment_config.yaml --preview to validate the deployment.
  6. Run gcloud deployment-manager deployments update my-deployment to release preview.
  7. Run gcloud deployment-manager deployments cancel-preview my-deployment to cancel preview.
  8. ...

Production-ready sample templates

Further reading:

Conclusion

Don’t use it