Cloud Deployment Manager dejará de estar disponible el 31 de diciembre de 2025. Si actualmente usas Deployment Manager, migra a Infrastructure Manager o a una tecnología de implementación alternativa antes del 31 de diciembre de 2025 para asegurarte de que tus servicios continúen sin interrupciones.
Usa variables de entorno específicas de la implementación
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Para cada una de tus implementaciones, Deployment Manager crea variables de entorno predefinidas que contienen información deducida de tu implementación.
Usa estas variables de entorno en tus plantillas de Python o Jinja2 para obtener información sobre tu proyecto o implementación.
Deployment Manager configura las siguientes variables del entorno automáticamente.
Se las reemplaza en cualquier lugar que las utilices en tus plantillas. Por ejemplo, usa la variable project_number para agregar el número de proyecto al nombre de una cuenta de servicio.
Variable de entorno
Valor
deployment
El nombre de la implementación.
name
El name declarado en la configuración que utiliza la plantilla. Esta variable puede ser útil si quieres que el nombre que declaras en la configuración sea el mismo del recurso en las plantillas subyacentes.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-03 (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."]]