Skip to content

Commit

Permalink
Add DM Walkthrough tutorial (GoogleCloudPlatform#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
anitagarg authored and thackem committed Sep 13, 2019
1 parent e7513c7 commit e50c077
Show file tree
Hide file tree
Showing 18 changed files with 714 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This repository contains example templates for use with Deployment Manager.

For an overview of Deployment Manager, see https://cloud.google.com/deployment-manager/docs.

## Run the walkthrough tutorial

[![Open in Cloud Shell](http://gstatic.com/cloudssh/images/open-btn.svg)](https://console.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2FGoogleCloudPlatform%2Fdeploymentmanager-samples&cloudshell_tutorial=walkthroughtutorial.md)

## Try the samples

Clone this repostory into [Cloud Shell](https://cloud.google.com/shell/), edit the samples, and deploy them from within Cloud Shell, without installing anything.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory contains files that allow users to create helper scripts in the interactive tutorial.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Generates name of a VM."""


def GenerateMachineName(prefix, suffix):
return prefix + "-" + suffix

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
imports:
# common.py is imported below.
- path: common.py
- path: vm-template.py

resources:
- name: vm-1
type: vm-template.py

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Creates the virtual machine."""

# `common.py` is imported below.
import common

COMPUTE_URL_BASE = 'https://www.googleapis.com/compute/v1/'


def GenerateConfig(context):
"""Generates configuration of a VM."""
resources = [{
'name': common.GenerateMachineName('myfrontend', 'prod'),
'type': 'compute.v1.instance',
'properties': {
'zone': 'us-central1-f',
'machineType': COMPUTE_URL_BASE + 'projects/' + context.env['project']
+ '/zones/us-central1-f/machineTypes/f1-micro',
'disks': [{
'deviceName': 'boot',
'type': 'PERSISTENT',
'boot': True,
'autoDelete': True,
'initializeParams': {
'sourceImage': COMPUTE_URL_BASE + 'projects/'
'debian-cloud/global/images/family/debian-9'}
}],
'networkInterfaces': [{
'network': COMPUTE_URL_BASE + 'projects/' + context.env['project']
+ '/global/networks/default',
'accessConfigs': [{
'name': 'External NAT',
'type': 'ONE_TO_ONE_NAT'
}]
}]
}
}]
return {'resources': resources}

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ resources:
type: compute.v1.instance
properties:
zone: us-central1-f
machineType: https://www.googleapis.com/compute/v1/projects/[MY_PROJECT]/zones/us-central1-f/machineTypes/f1-micro
machineType: https://www.googleapis.com/compute/v1/projects/MY_PROJECT/zones/us-central1-f/machineTypes/f1-micro
disks:
- deviceName: boot
type: PERSISTENT
Expand All @@ -26,15 +26,15 @@ resources:
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/[MY_PROJECT]/global/networks/default
- network: https://www.googleapis.com/compute/v1/projects/MY_PROJECT/global/networks/default
accessConfigs:
- name: External NAT
type: ONE_TO_ONE_NAT
- name: the-second-vm
type: compute.v1.instance
properties:
zone: us-central1-f
machineType: https://www.googleapis.com/compute/v1/projects/[MY_PROJECT]/zones/us-central1-f/machineTypes/g1-small
machineType: https://www.googleapis.com/compute/v1/projects/MY_PROJECT/zones/us-central1-f/machineTypes/g1-small
disks:
- deviceName: boot
type: PERSISTENT
Expand All @@ -43,7 +43,7 @@ resources:
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/[MY_PROJECT]/global/networks/default
- network: https://www.googleapis.com/compute/v1/projects/MY_PROJECT/global/networks/default
accessConfigs:
- name: External NAT
type: ONE_TO_ONE_NAT
10 changes: 8 additions & 2 deletions examples/v2/step_by_step_guide/step4_use_references/two-vms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ resources:
type: compute.v1.instance
properties:
zone: us-central1-f
machineType: https://www.googleapis.com/compute/v1/projects/[MY_PROJECT]/zones/us-central1-f/machineTypes/f1-micro
machineType: https://www.googleapis.com/compute/v1/projects/MY_PROJECT/zones/us-central1-f/machineTypes/f1-micro
disks:
- deviceName: boot
type: PERSISTENT
Expand All @@ -26,6 +26,9 @@ resources:
initializeParams:
sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-9
networkInterfaces:
# The resource's "network value" has been replaced with a
# reference to the new network's "selfLink" property. The network
# resource has been added to the end of this file.
- network: $(ref.a-new-network.selfLink)
accessConfigs:
- name: External NAT
Expand All @@ -34,7 +37,7 @@ resources:
type: compute.v1.instance
properties:
zone: us-central1-f
machineType: https://www.googleapis.com/compute/v1/projects/[MY_PROJECT]/zones/us-central1-f/machineTypes/g1-small
machineType: https://www.googleapis.com/compute/v1/projects/MY_PROJECT/zones/us-central1-f/machineTypes/g1-small
disks:
- deviceName: boot
type: PERSISTENT
Expand All @@ -43,10 +46,13 @@ resources:
initializeParams:
sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-9
networkInterfaces:
# As in the resource above, the "network" value has been replaced with
# the new network's "selfLink" property.
- network: $(ref.a-new-network.selfLink)
accessConfigs:
- name: External NAT
type: ONE_TO_ONE_NAT
# The following network is a new resource added to the "two-vms.yaml" file.
- name: a-new-network
type: compute.v1.network
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ imports:
- path: vm-template.py
- path: vm-template-2.py

# In the resources section below, the properties of the resources are replaced
# with the names of the templates.
resources:
- name: vm-1
type: vm-template.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def GenerateConfig(unused_context):
'type': 'compute.v1.instance',
'properties': {
'zone': 'us-central1-f',
'machineType': ''.join([COMPUTE_URL_BASE, 'projects/[MY_PROJECT]',
'machineType': ''.join([COMPUTE_URL_BASE, 'projects/MY_PROJECT',
'/zones/us-central1-f/',
'machineTypes/g1-small']),
'disks': [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def GenerateConfig(unused_context):
'type': 'compute.v1.instance',
'properties': {
'zone': 'us-central1-f',
'machineType': ''.join([COMPUTE_URL_BASE, 'projects/[MY_PROJECT]',
'machineType': ''.join([COMPUTE_URL_BASE, 'projects/MY_PROJECT',
'/zones/us-central1-f/',
'machineTypes/f1-micro']),
'disks': [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""Creates the Compute Engine."""


def GenerateConfig(unused_context):
def GenerateConfig(context):
"""Creates the Compute Engine with network and firewall."""

resources = [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""Creates the firewall."""


def GenerateConfig(unused_context):
def GenerateConfig(context):
"""Creates the firewall."""

resources = [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""Creates the network."""


def GenerateConfig(unused_context):
def GenerateConfig(context):
"""Creates the network."""

resources = [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
COMPUTE_URL_BASE = 'https://www.googleapis.com/compute/v1/'


def GenerateConfig(unused_context):
def GenerateConfig(context):
"""Creates the second virtual machine."""

resources = [{
'name': 'the-second-vm',
'type': 'compute.v1.instance',
'properties': {
'zone': 'us-central1-f',
'machineType': ''.join([COMPUTE_URL_BASE, 'projects/[MY_PROJECT]',
'machineType': ''.join([COMPUTE_URL_BASE, 'projects/',context.env['project'],
'/zones/us-central1-f/',
'machineTypes/g1-small']),
'disks': [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
COMPUTE_URL_BASE = 'https://www.googleapis.com/compute/v1/'


def GenerateConfig(unused_context):
def GenerateConfig(context):
"""Creates the first virtual machine."""

resources = [{
'name': 'the-first-vm',
'type': 'compute.v1.instance',
'properties': {
'zone': 'us-central1-f',
'machineType': ''.join([COMPUTE_URL_BASE, 'projects/[MY_PROJECT]',
'machineType': ''.join([COMPUTE_URL_BASE, 'projects/',context.env['project'],
'/zones/us-central1-f/',
'machineTypes/f1-micro']),
'disks': [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ def GenerateConfig(context):
"""Creates the virtual machine with environment variables."""

resources = [{
# `the-first-vm` is replaced with `context.env[`name`]`
'name': context.env['name'],
'type': 'compute.v1.instance',
'properties': {
# All occurrences of `us-central1-f` are replaced with
# `context.properties[`zone`].
# All occurrences of the project ID are replaced with
# `context.env[`project`]`.
# `f1-micro` is replaced with `context.properties["machineType"].
'zone': context.properties['zone'],
'machineType': ''.join([COMPUTE_URL_BASE, 'projects/',
context.env['project'], '/zones/',
Expand All @@ -40,6 +46,8 @@ def GenerateConfig(context):
'images/family/debian-9'])
}
}],
# `$(ref.a-new-network.selfLink)` is replaced with
# `$(ref.` + context.properties[`network`] + `selfLink)`.
'networkInterfaces': [{
'network': '$(ref.' + context.properties['network']
+ '.selfLink)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Creates the virtual machine with environment variables and startup script."""


COMPUTE_URL_BASE = 'https://www.googleapis.com/compute/v1/'


Expand Down
Loading

0 comments on commit e50c077

Please sign in to comment.