Cloud Deployment Manager akan mencapai akhir dukungan pada 31 Desember 2025. Jika saat ini Anda menggunakan Deployment Manager, migrasikan ke Infrastructure Manager atau teknologi deployment alternatif paling lambat 31 Desember 2025 untuk memastikan layanan Anda berlanjut tanpa gangguan.
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Untuk setiap deployment, Deployment Manager akan membuat variabel lingkungan yang telah ditetapkan sebelumnya yang berisi informasi yang disimpulkan dari deployment Anda.
Gunakan variabel lingkungan ini dalam template Python atau Jinja2 untuk mendapatkan informasi tentang project atau deployment Anda.
Sebelum memulai
Jika Anda ingin menggunakan contoh command line dalam panduan ini, instal alat command line`gcloud`.
Jika Anda ingin menggunakan contoh API dalam panduan ini, siapkan akses API.
Variabel lingkungan berikut ditetapkan secara otomatis oleh Deployment Manager.
Variabel ini akan diganti di mana pun Anda menggunakannya dalam template. Misalnya,
gunakan variabel project_number untuk menambahkan nomor project ke nama akun layanan.
Variabel lingkungan
Nilai
deployment
Nama deployment.
name
name yang dideklarasikan dalam konfigurasi yang menggunakan
template. Hal ini dapat berguna jika Anda ingin nama yang Anda deklarasikan dalam
konfigurasi menjadi nama resource dalam template
yang mendasarinya.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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."]]