Stay organized with collections Save and categorize content based on your preferences.
Template modules are helper files that perform specific functions that can make your templates more efficient. For example, you can have a module that generates unique names for your resources. Deployment Manager can execute any module written in Python or Jinja.
Before you beginA template module is treated as a regular template file and can be written in Jinja or Python.
For example, the following is a helper template that generates a name given a prefix and suffix.
Jinja
In Jinja, this helper template (in this example, named helpers/common.jinja) would look like the following:
You can then import this template and use it as a module. In your Jinja template, you could use the module like so:
The configuration must then import both files (including the helpers/common.jinja
file):
The Deployment Manager service will expand the configuration and the final configuration looks like this:
resources:
- name: myfrontend-prod
type: compute.v1.instance
properties:
zone: us-central1-f
machineType: https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/machineTypes/f1-micro
disks:
- deviceName: boot
type: PERSISTENT
boot: true
autoDelete: true
initializeParams:
sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-9
networkInterfaces:
- network: https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default
accessConfigs:
- name: External NAT
type: ONE_TO_ONE_NAT
Python
In Python, the helper template (in this example, named helpers/common.py) would look like this:
To use it in your Python template:
The configuration must then import both files (including the helpers/common.py
file):
Here is a more complicated helper module:
What's nextExcept 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."],[[["Template modules are helper files that enhance template efficiency by performing specific functions, such as generating unique resource names."],["Deployment Manager can utilize template modules written in either Jinja or Python, offering flexibility in coding preference."],["A template module can be imported and used within other templates, like the example provided where a Jinja template uses a module to generate a machine name with a given prefix and suffix."],["The configuration must import all used files, which include both the main template and any helper template modules, for the Deployment Manager service to properly expand it."],["The same principles apply to modules in Python, and the content shows examples of using a python module to generate names in a python template, as well as a more complicated python module example."]]],[]]
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