Skip to content

Instantly share code, notes, and snippets.

@ryu1kn
Created August 20, 2019 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryu1kn/3f53143e743e2553030f3d7e93b0684e to your computer and use it in GitHub Desktop.
Save ryu1kn/3f53143e743e2553030f3d7e93b0684e to your computer and use it in GitHub Desktop.
Google Cloud Deployment Manager sample

Google Cloud Deployment Manager samples

Usage

Creating

Using configuration

gcloud deployment-manager deployments create sample-deployment --config vm_config.yaml

Using template directly by providing parameters on command line

gcloud deployment-manager deployments create sample-deployment --template vm_template.py \
    --properties zone:australia-southeast1-a,foo:bar

To deploy Jinja version of template, just change .py to .jinja

Deleting

gcloud deployment-manager deployments delete sample-deployment

Refs

imports:
- path: vm_template.jinja
resources:
- name: my-vm
type: vm_template.jinja
properties:
zone: australia-southeast1-a
resources:
- type: compute.v1.instance
name: {{env["project"]}}-deployment-vm
properties:
zone: {{properties["zone"]}}
machineType: https://www.googleapis.com/compute/v1/projects/{{env["project"]}}/zones/{{properties["zone"]}}/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/family/debian-9
networkInterfaces:
- network: https://www.googleapis.com/compute/v1/projects/{{env["project"]}}/global/networks/default
accessConfigs:
- name: External NAT
type: ONE_TO_ONE_NAT
import base64
def generate_config(context):
return {
'resources': [
{
'type': 'compute.v1.instance',
'name': context.env['project'] + '-deployment-vm',
'properties': {
'zone': context.properties['zone'],
'description': base64.b64encode('testing base64 encoding'),
'machineType': 'https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/machineTypes/f1-micro'.format(
project = context.env['project'],
zone = context.properties['zone']
),
'disks': [
{
'deviceName': 'boot',
'type': 'PERSISTENT',
'boot': True,
'autoDelete': True,
'initializeParams': {
'sourceImage': 'https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-9'
}
}
],
'networkInterfaces': [
{
'network': 'https://www.googleapis.com/compute/v1/projects/{0}/global/networks/default'.format(context.env['project']),
'accessConfigs': [
{
'name': 'External NAT',
'type': 'ONE_TO_ONE_NAT'
}
]
}
]
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment