0
votes

We deployed a MongoDb cluster on GCE a few years ago, and need to create an identical cluster in dev in order to test upgrading to MongoDB v3.6 and v4. The v3.4 cluster deployment template is no longer in the marketplace (v4 is available now), so I would like to either:

  1. Find the old template
  2. Create an identical one of my own in the GCE Deployment Manager

I've never used jinja or python templates before so this is a little challenging. When I look at the previous deployment in the GCE Deployment Manager it provides me with a "Layout", a "Config", and an "Expanded Config". It also provides links to the various imports.

The Config looks a lot like a json version of the Schema, and the Layout kinda looks like a jinja template to my untrained eye. So I tried to create a new Composite Type in the GCE Deployment Manager by converting the "Config" to yaml and providing the "Layout" as the jinja. This fails and if I look in the dev tools, I find this error:

[{
"code":"INVALID_FIELD_VALUE",
"location":"template.schema",
"message":"Template fetching failed: Type common/deployment_coordinator.jinja is not a valid template type, missing required fields"}]

Which suggest to me that it doesn't know what "common" is -- which is a problem because I don't know either.

Do I need to create my own Composite Types for each of the imports? GCE does not give me a URL for them, but does display the contents if I click on them. What is my next step?

Here is the content of the "Config":

imports:
- name: deployment_coordinator.jinja
  path: common/deployment_coordinator.jinja
- name: path_utils.jinja
  path: common/path_utils.jinja
- path: mongodb.jinja
resources:
- name: deployment_coordinator
  type: deployment_coordinator.jinja
  properties:
    package: mongodb
    zone: us-east1-b
    network: default
    subnetwork: default
- name: mongodb
  type: mongodb.jinja
  properties:
    zone: us-east1-b
    replicaSetName: rs0
    numReplicas: 3
    machineType: custom-2-5120
    dataDiskType: pd-ssd
    dataDiskSizeGb: 250
    numArbiters: 0
    arbMachineType: f1-micro
    network: default
    subnetwork: default

and here is the "Layout":

resources:
- name: deployment_coordinator
  properties:
    network: default
    package: mongodb
    subnetwork: default
    zone: us-east1-b
  resources:
  - name: mongo-backbone-prod-coord
    type: compute.v1.instance
  type: deployment_coordinator.jinja
- name: mongodb
  outputs:
  - finalValue: mongo-backbone-prod-server-1
    name: initialPrimaryName
    value: mongo-backbone-prod-server-1
  - finalValue: https://www.googleapis.com/compute/v1/projects/***/zones/us-east1-b/instances/mongo-backbone-prod-server-1
    name: initialPrimarySelfLink
    value: $(ref.mongo-backbone-prod-server-1.selfLink)
  - finalValue: c2d
    name: x-status-type
    value: c2d
  properties:
    arbMachineType: f1-micro
    dataDiskSizeGb: 250
    dataDiskType: pd-ssd
    machineType: custom-2-5120
    network: default
    numArbiters: 0
    numReplicas: 3
    replicaSetName: rs0
    subnetwork: default
    zone: us-east1-b
  resources:
  - name: mongo-backbone-prod-server
    properties:
      addedDiskResources:
      - name: mongo-backbone-prod-server-1-data
        properties:
          sizeGb: 250
          type: https://www.googleapis.com/compute/v1/projects/***/zones/us-east1-b/diskTypes/pd-ssd
          zone: us-east1-b
        type: compute.v1.disk
      - name: mongo-backbone-prod-server-2-data
        properties:
          sizeGb: 250
          type: https://www.googleapis.com/compute/v1/projects/***/zones/us-east1-b/diskTypes/pd-ssd
          zone: us-east1-b
        type: compute.v1.disk
      - name: mongo-backbone-prod-server-3-data
        properties:
          sizeGb: 250
          type: https://www.googleapis.com/compute/v1/projects/***/zones/us-east1-b/diskTypes/pd-ssd
          zone: us-east1-b
        type: compute.v1.disk
      bootDiskType: pd-standard
      canIpForward: true
      disks:
      - autoDelete: true
        boot: false
        deviceName: data
        diskSizeGb: 250
        diskType: pd-ssd
        type: PERSISTENT
      instanceName: mongo-backbone-prod-server
      machineType: custom-2-5120
      metadata:
        items:
        - key: startup-script
          value: /opt/c2d/startup-script.sh
        - key: ISMONGODBSERV
          value: 'True'
        - key: ISMONGODBARB
          value: 'False'
        - key: MONGO_REPLICASET_NAME
          value: rs0
        - key: MONGODB_SERVERS
          value: mongo-backbone-prod-server-1|mongo-backbone-prod-server-2|mongo-backbone-prod-server-3|
        - key: MONGODB_ARBITERS
          value: ''
        - key: ENV_DEPLOY_INSTALL_TEMP
          value: /tmp/mongo
      network: default
      numberOfVMReplicas: 3
      sourceImage: https://www.googleapis.com/compute/v1/projects/click-to-deploy-images/global/images/mongodb-3-4-debian-8-jessie-20170822-101032
      subnetwork: default
      tags:
        items:
        - mongodb
        - mongodb-db
        - cluster-deployed-from-google-developer-console
      zone: us-east1-b
    resources:
    - name: mongo-backbone-prod-server-1
      type: compute.v1.instance
    - name: mongo-backbone-prod-server-2
      type: compute.v1.instance
    - name: mongo-backbone-prod-server-3
      type: compute.v1.instance
    - name: mongo-backbone-prod-server-1-data
      type: compute.v1.disk
    - name: mongo-backbone-prod-server-2-data
      type: compute.v1.disk
    - name: mongo-backbone-prod-server-3-data
      type: compute.v1.disk
    type: vm_multiple_instances.py
  type: mongodb.jinja

Here are the imports:

c2d_deployment_configuration.json
common.py
default.py
deployment_coordinator.jinja
mongodb.jinja
mongodb.jinja.display
mongodb.jinja.schema
password.py
path_utils.jinja
resources/en/mongodb_logo.png
resources/en/mongodb_overview.png
test_config.yaml
vm_instance.py
vm_instance.py.schema
vm_multiple_instances.py
1

1 Answers

1
votes

Turns out the UI in GCE is not that helpful and you don't need to fiddle with the templates. The best option is to use the gcloud command line tool.
To replicate a previous deployment:

  1. Go to https://console.cloud.google.com/dm/deployments and download your 'Expanded Config' from the UI's overview section in your previous deployment as a YAML file.
  2. Make whatever changes you wish to the YAML (probably just changing the names of your deployed resources).
  3. Open a command line where you can use the gcloud tool.
  4. gcloud deployment-manager deployments create name-of-new-deployment --config yourUpdatedExpandedConfig.yaml

More info: https://cloud.google.com/sdk/gcloud/reference/deployment-manager/

and particularly: https://cloud.google.com/sdk/gcloud/reference/deployment-manager/deployments/