Creating a Configuration

The first step in creating your deployment is to create a configuration. A configuration is a list of resources, and their respective properties, that will be part of your deployment.

A configuration file contains a top-level resources: section, which contains a list of resource entries, each with the following fields:

  • name: A name that you define for this resource. For example, "myfirstvm" or "dev-vm."
  • type: Specifies the base type of this resource. For example, a virtual machine would have type compute.v1.instance. Similarly, a Cloud SQL instance has the type sql.v1beta4.instance. See a full list of available resource types.
  • properties: Specifies the properties of the resource. The properties required to create the resource are the same properties required in the respective resource’s API. For example, when you create a Compute Engine virtual machine instance through the Compute Engine service, you must provide a machine type, an image, a network interface, and a boot disk specification. The same properties are also required in the properties section to create a virtual machine instance through Deployment Manager.

For this guide, let's define a configuration that creates a deployment with two instances.

Create your YAML file

Change to the directory you created in Installation and Setup:

cd step-by-step-dm

Start writing your configuration

Create a file called two-vms.yaml and start your configuration by declaring the resources string, followed by the first virtual machine instance’s type and name:

resources:
- name: the-first-vm
  type: compute.v1.instance

Add properties to your resource

Add properties of the virtual machine instance. This instance uses the f1-micro machine type, a Debian 9 image, with an ephemeral external IP address.

resources:
- name: the-first-vm
  type: compute.v1.instance
  properties:
    zone: us-central1-f
    machineType: https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/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/myproject/global/networks/default
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT

Add a second resource

Add the second instance by adding the following lines to the end of the file. This instance is slightly different from the first virtual machine, using the g1-small machine type rather than the f1-micro.

- name: the-second-vm
  type: compute.v1.instance
  properties:
    zone: us-central1-f
    machineType: https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/machineTypes/g1-small
    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/myproject/global/networks/default
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT

At the end, your YAML file should look like this:

# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

resources:
- name: the-first-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/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/[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
    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/[MY_PROJECT]/global/networks/default
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT

Save your changes

That’s it! This simple configuration file that you have just created is all you need to create a deployment. You just need to declare the resources you want in a file (in this case, two virtual machine instances that had different machine types) and Deployment Manager will handle the resource creation process under the hood.

In the next step, let's use this configuration and deploy new resources.

Next: Deploy Your Resources

Related topics

¿Te ha resultado útil esta página? Enviar comentarios:

Enviar comentarios sobre...

Cloud Deployment Manager Documentation