[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-08-19 UTC。"],[[["\u003cp\u003eTemplate properties are custom variables defined within template files, allowing for flexibility in configurations without altering the core template.\u003c/p\u003e\n"],["\u003cp\u003eValues for template properties can be set within the top-level configuration file, ensuring all required properties have specified values.\u003c/p\u003e\n"],["\u003cp\u003eTemplate properties can be defined using Jinja syntax \u003ccode\u003e{{ properties["PROPERTY_NAME"] }}\u003c/code\u003e or Python syntax \u003ccode\u003econtext.properties["PROPERTY_NAME"]\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Cloud CLI enables setting template property values directly via command-line arguments, bypassing the need for a separate top-level YAML file.\u003c/p\u003e\n"],["\u003cp\u003eWhen using the Google Cloud CLI to set template property values, all values are treated as YAML types, and all required properties must be provided, unless default values are defined in the schema.\u003c/p\u003e\n"]]],[],null,["# Defining Template Properties\n\nOne of the advantages of using [templates](/deployment-manager/docs/configuration/templates/create-basic-template)\nis the ability to create and define custom template properties. Template\nproperties are arbitrary variables that you define in template files. Any\nconfiguration file or template file that uses the template in question can\nprovide a value for the template property without changing the template\ndirectly. This lets you abstract the property so that you can change the property's\nvalue for each unique configuration without updating the underlying template.\n\nFor example, the following line specifies a template property in the\nmachine type's URL: \n\n```actionscript-3\nmachineType: zones/{{ properties\\[\"zone\"\\] }}/machineTypes/n1-standard-1\n```\n\nIn a configuration that uses this template, you can set the value of `zone`\nin the `properties` section of the template: \n\n```carbon\nimports:\n- path: vm_template.jinja\n\nresources:\n- name: my-vm\n type: vm_template.jinja\n properties:\n zone: us-central1-a\n```\n\nDeployment Manager will know to pass in the value of `zone` to the underlying\ntemplate.\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\nCreating a template property\n----------------------------\n\nTo create a template property: \n\n### Jinja\n\nIn Jinja, define a property using the following syntax: \n\n```django/jinja\n{{ properties[\"PROJECT_NAME\"] }}\n```\n\nFor example: \n\n - name: vm-{{ env[\"deployment\"] }}\n type: compute.v1.instance\n properties:\n zone: us-central1-a\n machineType: zones/{{ properties[\"zone\"] }}/machineTypes/n1-standard-1\n disks:\n - deviceName: boot\n type: PERSISTENT\n boot: true\n autoDelete: true\n initializeParams:\n sourceImage: projects/debian-cloud/global/images/family/debian-11\n networkInterfaces:\n - network: global/networks/default\n\n### Python\n\nIn Python, define a property using the following syntax: \n\n context.properties[\"PROPERTY_NAME\"]\n\nFor example: \n\n resources.append({\n 'name': 'vm-' + context.env['deployment'],\n 'type': 'compute.v1.instance',\n 'properties': {\n 'zone': 'us-central1-a',\n 'machineType': ''.join(['zones/', context.properties['zone'],\n '/machineTypes/n1-standard-1']),\n 'disks': [{\n 'deviceName': 'boot',\n 'type': 'PERSISTENT',\n 'boot': True,\n 'autoDelete': True,\n 'initializeParams': {\n 'sourceImage':\n 'projects/debian-cloud/global/images/family/debian-11'\n }\n }],\n 'networkInterfaces': [{\n 'network': 'global/networks/default'\n }]\n }\n\n })\n\nFor the full Python example, see the Deployment Manager [GitHub repository](https://github.com/GoogleCloudPlatform/deploymentmanager-samples/blob/master/examples/v2/build_configuration/add_templates/python/vm-template.py).\n\nSetting values for template properties on the top-level config\n--------------------------------------------------------------\n\nOn the top-level configuration, you can set values for template properties using\nthe syntax: \n\n```carbon\nimports:\n- path: vm_template.jinja\n\nresources:\n- name: my-vm\n type: vm_template.jinja\n properties:\n zone: us-central1-a\n```\n\nYou must set values for all template properties in the template. For example,\nif a template has template properties `zone`, `image`, `network`, you must\ndefine values for all of those properties in the top-level configuration.\n\nIf certain template properties have default values, consider using\n[schemas](/deployment-manager/docs/configuration/templates/using-schemas)\nto set these default values. A template property with a default value can\nbe omitted from the top-level configuration if the default value is appropriate\nfor the deployment.\n\nSetting values for template properties on the command-line\n----------------------------------------------------------\n\nInstead of supplying values for template properties in the parent file importing\nthe template, Deployment Manager offers the ability to set these values directly\nin the Google Cloud CLI. You can skip creating the top-level YAML\nfile; Deployment Manager will automatically generate a top-level configuration\nfor your deployment based on the information in your request.\n\nFor example, assume you have the following template which has a template\nproperty called `zone`: \n\n - name: vm-{{ env[\"deployment\"] }}\n type: compute.v1.instance\n properties:\n zone: us-central1-a\n machineType: zones/{{ properties[\"zone\"] }}/machineTypes/n1-standard-1\n disks:\n - deviceName: boot\n type: PERSISTENT\n boot: true\n autoDelete: true\n initializeParams:\n sourceImage: projects/debian-cloud/global/images/family/debian-11\n networkInterfaces:\n - network: global/networks/default\n\nWith the Google Cloud CLI, you can pass in this template file directly\nand provide the values for your template properties on the command-line. For\nexample, the following request passes in the template and specifies the\n`zone` property directly on the command-line: \n\n gcloud deployment-manager deployments create a-single-vm --template vm_template.jinja \\\n --properties zone:us-central1-a\n\nKeep in mind that:\n\n- All values are parsed as YAML values. For example, `version: 3` is passed in\n as an integer. If you want to specify it as a string, put escaped single\n quotes around the value, `version: \\'3\\'`.\n\n- Boolean values are case insensitive, so `TRUE`, `true`, and `True` are treated\n the same.\n\n- You must pass in all required properties defined by the template. You cannot\n provide just a subset of the properties. If certain properties have default\n values, you can omit the property from the command-line.\n\nTo specify multiple properties, provide comma-separated key:value pairs. It does\nnot matter in what order you specify the pairs. For example:\n\n\n```\ngcloud deployment-manager deployments create my-igm \\\n --template vm_template.jinja \\\n --properties zone:us-central1-a,machineType:n1-standard-1,image:debian-9\n```\n\n\u003cbr /\u003e\n\nAfter running this command, Deployment Manager creates a deployment using the\ntemplate you provided. You can confirm that the deployment has been created\nusing the Google Cloud console or the gcloud CLI. For information on viewing a\ndeployment, read\n[Viewing a manifest](/deployment-manager/docs/deployments/viewing-manifest#view_a_manifest).\n\nWhat's next\n-----------\n\n- Populate information about your projects and deployments using [environment variables](/deployment-manager/docs/configuration/templates/use-environment-variables).\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."]]