4

I'm trying to create an unmanaged instanceGroup with several VM's in it via Deployment Manager Configuration (YAML file).

I can easily find docs about addInstances via Google API, but couldn't find docs about how to do this in a YAML file:

instances

instanceGroups

What properties should be included in instances/instanceGroup resource to make it work?

Matthew Strawbridge
  • 19,940
  • 10
  • 72
  • 93
KrHubert
  • 1,030
  • 7
  • 17

4 Answers4

5

The YAML below will create a compute engine instance, create an unmanaged instance group, and add the instance to the group.

resources:
- name: instance-1
  type: compute.v1.instance
  properties:
    zone: australia-southeast1-a
    machineType: zones/australia-southeast1-a/machineTypes/n1-standard-1
    disks:
    - deviceName: boot
      type: PERSISTENT
      diskType: zones/australia-southeast1-a/diskTypes/pd-ssd
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: projects/debian-cloud/global/images/debian-9-stretch-v20180716
    networkInterfaces:
    - network: global/networks/default
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT

- name: ig-1
  type: compute.v1.instanceGroup
  properties:
    zone: australia-southeast1-a
    network: global/networks/default

- name: ig-1-members
  action: gcp-types/compute-v1:compute.instanceGroups.addInstances
  properties:
    project: YOUR_PROJECT_ID
    zone: australia-southeast1-a
    instanceGroup: ig-1
    instances: [ instance: $(ref.instance-1.selfLink) ]
mcourtney
  • 213
  • 2
  • 6
1

There is no possibility right now, to do it with gcloud deployment manager.

KrHubert
  • 1,030
  • 7
  • 17
1

This was tested and it seemed that while Google Deployment Manager was able to complete without issue having the following snippet:

{
  "instances":  [
    {
      "instance":  string
    }
  ]
}

it did not add the instances specified, but created the IGM.

However Terraform seems to be able to do it https://www.terraform.io/docs/providers/google/r/compute_instance_group.html

rsFF
  • 111
  • 7
1

I think @mcourtney answer is correct.

I just had this scenario and i used python template with yaml config to add instances to an un-managed instance group.

Here is the snippet of resource definition in my python template :

{
        'name': name + '-ig-members',
        'action': 'gcp-types/compute-v1:compute.instanceGroups.addInstances',
        'properties': {
            'project': '<YOUR PROJECT ID>',
            'zone' : context.properties['zone'], // Defined in config yaml
            'instanceGroup': '<YOUR Instance Group name ( not url )>',
            "instances": [
    {
      "instance": 'projects/<PROJECT ID>/zones/<YOUR ZONE>/instances/<INSTANCE NAME>'
    }
  ]            
        }
    }

Reference API is documented here :

https://cloud.google.com/compute/docs/reference/rest/beta/instanceGroups/addInstances

This is just an example. you can abstract all the hard coded things to either yaml configuration or variables at the top of python template.

user2117893
  • 111
  • 5