Cloud Deployment Manager will reach end of support on December 31, 2025. If you currently use Deployment Manager, please migrate to Infrastructure Manager or an alternative deployment technology by December 31, 2025 to ensure your services continue without interruption.
Stay organized with collections
Save and categorize content based on your preferences.
For each of your deployments, Deployment Manager creates pre-defined
environment variables that contain information inferred from your deployment.
Use these environment variables in your Python or Jinja2 templates to get
information about your project or deployment.
The following environment variables are automatically set by Deployment Manager.
They are replaced everywhere you use them in your templates. For example,
use the project_number variable to add the project number to the name of a
service account.
Environment variable
Value
deployment
The name of the deployment.
name
The name declared in the configuration that is using the
template. This can be useful if you want the name you declare in the
configuration to be the name of the resource in the underlying
templates.
[[["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-09-04 UTC."],[[["\u003cp\u003eDeployment Manager automatically creates environment variables for each deployment, providing information about the project and deployment.\u003c/p\u003e\n"],["\u003cp\u003eThese environment variables, such as \u003ccode\u003edeployment\u003c/code\u003e, \u003ccode\u003eproject\u003c/code\u003e, and \u003ccode\u003eproject_number\u003c/code\u003e, can be used within Jinja2 or Python templates to dynamically configure resources.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ecurrent_time\u003c/code\u003e environment variable provides a UTC timestamp of when the deployment expansion started.\u003c/p\u003e\n"],["\u003cp\u003eTemplates utilize environment variables using the \u003ccode\u003e{{ env["variable_name"] }}\u003c/code\u003e syntax for Jinja2 and \u003ccode\u003econtext.env["variable_name"]\u003c/code\u003e for Python.\u003c/p\u003e\n"],["\u003cp\u003eEnvironment variables can be used to define or alter resource names and properties within a template, such as appending the deployment name to a VM instance.\u003c/p\u003e\n"]]],[],null,["# Using deployment-specific environment variables\n\nFor each of your deployments, Deployment Manager creates pre-defined\nenvironment variables that contain information inferred from your deployment.\nUse these environment variables in your Python or Jinja2 templates to get\ninformation about your project or deployment.\n\nBefore you begin\n----------------\n\n- If you want to use the command-line examples in this guide, install the [\\`gcloud\\` command-line tool](/sdk).\n- If you want to use the API examples in this guide, set up [API access](/deployment-manager/docs/reference/latest).\n- Understand how to [create a basic template](/deployment-manager/docs/configuration/templates/create-basic-template).\n- Understand how to [create a configuration](/deployment-manager/docs/configuration/create-basic-configuration)\n\nAvailable environment variables\n-------------------------------\n\nThe following environment variables are automatically set by Deployment Manager.\nThey are replaced everywhere you use them in your templates. For example,\nuse the `project_number` variable to add the project number to the name of a\nservice account.\n\nUsing an environment variable\n-----------------------------\n\nUse the following syntax to add an environment variable to your templates: \n\n```django/jinja\n{{ env[\"deployment\"] }} # Jinja\n\ncontext.env[\"deployment\"] # Python\n```\n\nIn your template, use the variables as in these examples: \n\n### Jinja\n\n```django/jinja\n- type: compute.v1.instance\n name: vm-{{ env[\"deployment\"] }}\n properties:\n machineType: zones/us-central1-a/machineTypes/f1-micro\n serviceAccounts:\n - email: {{ env['project_number'] }}-compute@developer.gserviceaccount.com\n scopes:\n - ...\n```\n\n### Python\n\n```python\ndef GenerateConfig(context):\n resources = []\n resources.append ({\n 'name': 'vm-' + context.env[\"deployment\"],\n 'type': 'compute.v1.instance',\n 'properties': {\n 'serviceAccounts': [{\n 'email': context.env['project_number'] + '-compute@developer.gserviceaccount.com',\n 'scopes': [...]\n }]\n }\n ...}]\n return {'resources': resources}\n```\n\nWhat's next\n-----------\n\n- Add a template permanently to your project as a [composite type](/deployment-manager/docs/configuration/templates/create-composite-types).\n- [Host templates externally](/deployment-manager/docs/configuration/templates/hosting-templates-externally) to share with others.\n- Add [schemas](/deployment-manager/docs/configuration/templates/using-schemas) to ensure users interact with your templates correctly."]]