템플릿을 사용할 때의 장점 중 하나는 커스텀 템플릿 속성을 만들고 정의할 수 있다는 것입니다. 템플릿 속성은 템플릿 파일에 정의하는 임의 변수입니다. 문제의 템플릿을 사용하는 모든 구성 파일 또는 템플릿 파일은 템플릿을 직접 변경하지 않고 템플릿 속성 값을 제공할 수 있습니다. 이렇게 하면 속성을 추상화하여 기본 템플릿을 업데이트하지 않고도 각각의 고유 구성에 대해 속성 값을 변경할 수 있습니다.
템플릿의 모든 템플릿 속성에 값을 설정해야 합니다. 예를 들어 템플릿에 템플릿 속성 zone, image, network가 있으면 최상위 구성에서 이러한 속성 값을 모두 정의해야 합니다.
특정 템플릿 속성에 기본값이 포함된 경우, 스키마를 사용하여 이러한 기본값을 설정할 수 있습니다. 기본값이 있는 템플릿 속성은 해당 기본값이 배포에 적합한 경우, 최상위 구성에서 생략할 수 있습니다.
명령줄에서 템플릿 속성 값 설정
템플릿을 가져오는 상위 파일에 템플릿 속성 값을 지정하는 대신 Deployment Manager는 Google Cloud CLI에서 직접 이러한 값을 설정할 수 있습니다. 최상위 YAML 파일 만들기를 건너뛸 수 있습니다. Deployment Manager는 요청에 있는 정보를 기준으로 배포의 최상위 구성을 자동으로 생성합니다.
[[["이해하기 쉬움","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-09-03(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."]]