Deployment manager : Adding Templates

  • date 10th July, 2021 |
  • by Prwatech |
  • 0 Comments

Adding templates in Deployment Manager configuration

Adding templates in Deployment Manager configuration files enables users to modularize their infrastructure-as-code (IaC) deployments in Google Cloud Platform (GCP). Templates allow users to define reusable configurations for cloud resources, promoting consistency, efficiency, and maintainability in deployment workflows.

Templates in files typically follow either YAML or Jinja2 syntax, allowing users to define resource configurations, properties, and dependencies in a structured manner. Users can create templates for individual resources, such as virtual machines, networks, or storage buckets, as well as for more complex deployments involving multiple resources and dependencies.

To add templates in Deployment Manager configuration files, users can define template files containing the desired resource configurations and properties. These template files can then be referenced and included within the main configuration file using the imports or templates sections, depending on the syntax being used.

Creating a basic template

A template is a file you create, written in either Jinja or Python

Create a file with extension .jinja.

Paste the below code

resources:
- name: vm-template
  type: compute.v1.instance
  properties:
    zone: us-central1-a
    machineType: zones/us-central1-a/machineTypes/n1-standard-1
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: projects/debian-cloud/global/images/family/debian-9
    networkInterfaces:
    - network: global/networks/default

Press ctrl+x  then y  then enter. The file will be saved.

Type $   pwd. It will show the path of file located.

Create a configuration file with extension .yaml

$       nano vm-config.yaml

Paste the below code

imports:
- path: path/my_vm_template.jinja
resources:
- name: my-first-virtual-machine
  type: path/to/my_vm_template.jinja

Press ctrl+x  then y  then enter. The file will be saved.

Then you can deploy the configuration file that contains the templates.

Deploying templates directly with the command-line tool

$   gcloud deployment-manager deployments create a-single-vm   --template vm_template.jinja

 

Quick Support

image image