A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/deployment-manager/docs/configuration/templates/create-basic-template below:

Creating a Basic Template | Cloud Deployment Manager Documentation

Creating a Basic Template

Stay organized with collections Save and categorize content based on your preferences.

A basic configuration file might be enough for simple workloads but for more complex architectures or for configurations that you plan to reuse, you can break your configuration into templates.

A template is a separate file that is imported and used as a type in a configuration. You can use as many templates as you want in a configuration.

Templates allow you to separate your configuration out into different pieces that you can use and reuse across different deployments. Templates can be as generalized or specific as you need. With templates, you can also take advantage of features like template properties, environment variables, modules, and other template functionality to create dynamic configuration and template files.

For examples of templates that you can use in your own deployments, see the Deployment Manager GitHub repository.

Before you begin Template syntax

Templates can be written in either Jinja 2.10.x or Python 3.x. Jinja maps more closely to the YAML syntax, so it might be easier to write templates in Jinja if you are more familiar with YAML.

You can also write template files in Python and take advantage of Python to programmatically generate parts of your templates. For example, you can use Python libraries to format template definitions. If you are familiar with Python, this might be a better format for you.

Deployment Manager accepts both Jinja and Python templates. You can import templates in both languages in the same configuration.

Creating a basic template

A template is a file you create, written in either Jinja or Python. For example, consider the following configuration file:

This configuration is valid, but you can further simplify the configuration by breaking different parts as individual template files that you can reuse. To create a template based on the configuration above, pull out section for the resource in question and create a new Jinja or Python file.

The following snippets show the sections of templates that can simplify your deployment. For the full templates, click View on GitHub.

Jinja Python

Your Python templates must meet these requirements:

Other than that, it is up to you to generate the contents of your template.

Example

For the full Python example, see the Deployment Manager GitHub repository.

Importing the template

After creating a template, import it into your configuration file to use it. To import a template, add an imports section in your configuration, followed by the relative or absolute path from the current directory. For example, you can import your virtual machine template from the previous step by adding the following line to the top of your configuration:

imports:
  - path: path/to/my_vm_template.jinja

If you have a long file path, you can provide an optional name property as an alias for the file. You can use this name to reference the template later. If you do not provide the name, the template can be referenced using the path.

imports:
  - path: path/to/my_vm_template.jinja
    name: my_renamed_template.jinja
Note: Template name and paths must end with a file extension, such as .py and .jinja. Non-template file extensions are also accepted, like .txt.

You can mix and match imports of multiple templates, regardless of whether the templates are Jinja or Python:

imports:
  - path: path/to/my_vm_template.jinja
    name: my_renamed_template.jinja
  - path: special_vm.py

If your template uses other templates as dependencies, import the dependent templates in your configuration as well:

imports:
  - path: path/to/my_vm_template.jinja
  - path: special_vm.py
  - path: base_vm.jinja

You can also import text files in order to inline the content. For example, if you create a file named resource_type.txt with the following string:

compute.v1.instance

Import it into your configuration and provide the content inline like so:

imports:
- path: resource_type.txt

resources:
- name: my-vm
  type: {{ imports["resource_type.txt"] }} # Resolves to "compute.v1.instance"
  properties:
    zone: us-central1-a
    machineType: zones/us-central1-a/machineTypes/f1-micro
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: projects/debian-cloud/global/images/family/debian-9
    networkInterfaces:
    - network: global/networks/default
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT
Deploying templates

Once you import a template, use it as a type in your configuration:

If you did not provide a name for your template, call the template using the template path:

imports:
- path: path/to/my_vm_template.jinja

resources:
- name: my-first-virtual-machine
  type: path/to/my_vm_template.jinja
Deploying templates directly with the command-line tool

Instead of creating a top-level configuration file, Deployment Manager offers the ability to deploy a template directly in the Google Cloud CLI.

For example, the following request deploys a template called vm-template.jinja:

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

If your template has template properties, you can also set these properties on the command-line using the --properties flag:

gcloud deployment-manager deployments create my-igm \
    --template vm-template.jinja \
    --properties zone:us-central1-a

Keep in mind that:

To specify multiple properties, provide comma-separated key:value pairs. It does not matter in what order you specify the pairs. For example:

gcloud deployment-manager deployments create my-igm 
--template vm-template.jinja
--properties zone:us-central1-a,machineType:n1-standard-1,image:debian-9

After running this command, Deployment Manager creates a deployment using the template you provided. You can confirm that the deployment has been created using the Google Cloud console or the gcloud CLI. For information on viewing a deployment, read Viewing a manifest.

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-07 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["Templates are separate files that can be imported and used as types in configurations, allowing for modular and reusable code in complex architectures."],["Templates can be written in either Jinja or Python, offering flexibility based on user familiarity and the need for programmatic generation of template parts."],["To use a template, it must be imported into a configuration file by specifying its path, with an option to assign a custom name for easier referencing."],["Deployment Manager allows the direct deployment of a template via the command-line tool, enabling the specification of template properties to be input directly."],["Templates can contain imports of other templates or text files, allowing for the creation of dependencies and inlining of text content."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4