GCP | How to create VM with Deployment Manager

Deployment Manager in GCP automates the creation and management of Google Cloud resources. With Deployment Manager Python or Jinja2 templates can be used for parametrization.

  • Login to Google Cloud Console
  • Click Activate Cloud Shell to open Cloud Shell.
  • Create and navigate to directory "test-vm"
  • 
    mkdir test-vm
    cd test-vm
    
    

  • Create config file with name "vm-config.yaml"
  • 
    nano vm-config.yaml
    
    

  • Write following code in "vm-config.yaml"
  • 
    imports:
      - path: vm.jinja
    resources:
    - name: test-instance
      type: vm.jinja
      properties:
        zone: us-central1-f
        machineType: f1-micro
    
    

  • Create template with name "vm.jinja"
  • 
    nano vm.jinja
    
    

  • Write following code in "vm.jinja"
  • 
    resources:
    - type: compute.v1.instance
      name: {{ env["deployment"] }}-instance
      properties:
         machineType: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/zones/{{ properties["zone"] }}/machineTypes/{{ properties["machineType"] }}
         zone: {{ properties["zone"] }}
         networkInterfaces:
         - subnetwork: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/regions/us-central1/subnetworks/default
         disks:
          - deviceName: boot
            type: PERSISTENT
            boot: true
            initializeParams:
              sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-9
    
    

  • Deploy the configuration with following command
  • 
    gcloud deployment-manager deployments create testinfra --config=vm-config.yaml
    
    

  • Successful execution should produce following output
  • 
    Create operation operation-1587****862-5a*******ad104-bacbcabb-7*****bc completed successfully.
    NAME                TYPE                 STATE      ERRORS  INTENT
    testinfra-instance  compute.v1.instance  COMPLETED  []
    
    

    Categories: GCP