O Cloud Deployment Manager vai chegar ao fim do suporte em 31 de dezembro de 2025. Se você usa o Deployment Manager, migre para o Infrastructure Manager ou uma tecnologia de implantação alternativa até 31 de dezembro de 2025 para garantir que seus serviços continuem sem interrupções.
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Ao definir as propriedades de configuração ou modelos, é possível usar referências às propriedades de outros recursos em vez de fornecer valores diretamente. Por exemplo, se você quiser criar um gerenciador de grupo de instâncias que use um modelo da mesma implantação, em vez de digitar explicitamente o link completo do modelo de instância, use uma referência com a sintaxe $(ref.instance-template.selfLink).
Com referências, é possível:
Acessar propriedades que não são definidas até a criação do recurso. Por exemplo, ao definir uma máquina virtual na configuração, você ainda não conhece o respectivo endereço IP. Mesmo assim, ainda é possível usar uma referência ao endereço IP. Ao implantar a configuração, a VM é criada primeiro e o Deployment Manager recebe o endereço IP externo quando ele se torna disponível.
Facilite a leitura e a resolução de problema das suas configurações ou modelos.
Por exemplo, se você precisar configurar várias regras de encaminhamento, também precisará especificar uma rede a ser usada. Em vez de fornecer um link para a rede a cada regra de encaminhamento, crie uma referência à propriedade selfLink da rede usando a seguinte sintaxe:
$(ref.network-name.selfLink)
Se você precisar solucionar problemas de configuração, a referência facilita a identificação da rede que está sendo usada na regra de encaminhamento.
Ao criar uma referência para um recurso, você também criará uma dependência entre recursos. Por exemplo, pense no seguinte snippet, em que sandbox-vm usa uma referência a network-a:
Quando você implanta essa configuração, o Deployment Manager cria network-a antes de sandbox-vm, para que a referência possa ser resolvida. Se alguma referência não for resolvida com sucesso, sua implementação falhará.
Você pode usar referências tanto nos arquivos de configuração quanto nos modelos.
Como fazer referências em arquivos de configuração
Declare as referências na configuração usando o seguinte formato:
$(ref.RESOURCE_NAME.PROPERTY)
O exemplo a seguir primeiro cria uma rede e depois cria duas instâncias que usam referências à rede recém-criada. Neste exemplo, a referência é:
$(ref.a-new-network.selfLink)
# Copyright 2016 Google Inc. All rights reserved.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.resources:-name:the-first-vmtype:compute.v1.instanceproperties:zone:us-central1-fmachineType:https://www.googleapis.com/compute/v1/projects/MY_PROJECT/zones/us-central1-f/machineTypes/f1-microdisks:-deviceName:boottype:PERSISTENTboot:trueautoDelete:trueinitializeParams:sourceImage:https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-11networkInterfaces:# The resource's "network value" has been replaced with a# reference to the new network's "selfLink" property. The network # resource has been added to the end of this file.-network:$(ref.a-new-network.selfLink)accessConfigs:-name:External NATtype:ONE_TO_ONE_NAT-name:the-second-vmtype:compute.v1.instanceproperties:zone:us-central1-fmachineType:https://www.googleapis.com/compute/v1/projects/MY_PROJECT/zones/us-central1-f/machineTypes/g1-smalldisks:-deviceName:boottype:PERSISTENTboot:trueautoDelete:trueinitializeParams:sourceImage:https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-11networkInterfaces:# As in the resource above, the "network" value has been replaced with # the new network's "selfLink" property. -network:$(ref.a-new-network.selfLink)accessConfigs:-name:External NATtype:ONE_TO_ONE_NAT# The following network is a new resource added to the "two-vms.yaml" file.-name:a-new-networktype:compute.v1.networkproperties:routingConfig:routingMode:REGIONALautoCreateSubnetworks:true
Quando você implanta essa configuração, a rede é criada antes das duas instâncias, e a referência é resolvida para o selfLink do recurso de rede.
Como fazer referências em arquivos de modelo
Nos arquivos de modelo, é necessário que a referência inteira esteja entre parênteses, precedidos por um $:
$(ref.RESOURCE_NAME.PROPERTY)
É possível combinar referências com outros recursos, como propriedades de modelo e variáveis de ambiente. Para garantir que o Deployment Manager analise a referência corretamente, é importante manter a string de referência inteira entre parênteses.
Aqui estão alguns exemplos de declaração de referências nos modelos:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-19 UTC."],[[["\u003cp\u003eReferences allow you to use properties of other resources in your configurations or templates instead of hardcoding values, improving readability and maintainability.\u003c/p\u003e\n"],["\u003cp\u003eUsing references lets you access properties that are determined during resource creation, such as a virtual machine's IP address, which is not known beforehand.\u003c/p\u003e\n"],["\u003cp\u003eReferences create dependencies between resources, meaning Deployment Manager will automatically create resources in the correct order to resolve the references.\u003c/p\u003e\n"],["\u003cp\u003eReferences are declared using the format \u003ccode\u003e$(ref.RESOURCE_NAME.PROPERTY)\u003c/code\u003e in configurations and templates, and can be combined with template properties and environment variables.\u003c/p\u003e\n"],["\u003cp\u003eYou cannot use references within the name field of a resource, and the processed value of a reference cannot be used in your Python or Jinja code, only after the deployment creation or update.\u003c/p\u003e\n"]]],[],null,["# Using references\n\nWhen you define the properties for your configuration or templates, you can\nuse **references** to the properties of other resources instead of directly\nproviding values. For example, if you want to create an instance group manager\nthat uses an instance template from the same deployment, instead of explicitly\ntyping the full link for the instance template, you can use a reference with the\nsyntax `$(ref.instance-template.selfLink)`.\n\nWith references, you can:\n\n- Access properties that are not defined until the resource is created. For\n example, when you define a virtual machine in your configuration, you do not\n yet know its IP address. However, you can still use a reference to the IP\n address. When you deploy your configuration, the VM is created first, and\n Deployment Manager gets the external IP address when it is available.\n\n- Make your configurations or templates easier to read and troubleshoot.\n For example, if you need to configure multiple forwarding rules, you must\n also specify a network to use. Instead of providing a link to the network\n for each forwarding rule, you can create a reference to the network's\n `selfLink` property using the following syntax:\n\n $(ref.network-name.selfLink)\n\n If you need to troubleshoot your configuration, the reference makes it easier\n to tell which network is being used in the forwarding rule.\n\nWhen you create a reference to a resource, you also create a dependency between\nresources. For example, consider the following snippet, where `sandbox-vm` uses\na reference to `network-a`: \n\n resources:\n - name: sandbox-vm\n type: compute.v1.instance\n properties:\n network: $(ref.network-a.selfLink)\n ...\n ...\n - name: network-a\n type: compute.v1.network\n properties:\n ...\n\nWhen you deploy this configuration, Deployment Manager creates `network-a`\nbefore `sandbox-vm`, so that the reference can be resolved. If any references\ndo not resolve successfully, your deployment fails.\n\nYou can use references in both configurations and templates.\n| **Note:** To avoid errors, don't use a reference within the name field of a resource.\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- Be familiar with [creating a configuration](/deployment-manager/docs/configuration/create-basic-configuration).\n- Be familiar with [creating a basic template](/deployment-manager/docs/configuration/templates/create-basic-template).\n\nMaking references in configuration files\n----------------------------------------\n\nDeclare references in your configuration using the following format: \n\n $(ref.RESOURCE_NAME.PROPERTY)\n\nThe following example creates a network, and then creates two\ninstances that use references to the newly created network. In this example,\nthe reference is: \n\n $(ref.a-new-network.selfLink)\n\n # Copyright 2016 Google Inc. All rights reserved.\n #\n # Licensed under the Apache License, Version 2.0 (the \"License\");\n # you may not use this file except in compliance with the License.\n # You may obtain a copy of the License at\n #\n # http://www.apache.org/licenses/LICENSE-2.0\n #\n # Unless required by applicable law or agreed to in writing, software\n # distributed under the License is distributed on an \"AS IS\" BASIS,\n # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n # See the License for the specific language governing permissions and\n # limitations under the License.\n\n resources:\n - name: the-first-vm\n type: compute.v1.instance\n properties:\n zone: us-central1-f\n machineType: https://www.googleapis.com/compute/v1/projects/MY_PROJECT/zones/us-central1-f/machineTypes/f1-micro\n disks:\n - deviceName: boot\n type: PERSISTENT\n boot: true\n autoDelete: true\n initializeParams:\n sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-11\n networkInterfaces:\n # The resource's \"network value\" has been replaced with a\n # reference to the new network's \"selfLink\" property. The network \n # resource has been added to the end of this file.\n - network: $(ref.a-new-network.selfLink)\n accessConfigs:\n - name: External NAT\n type: ONE_TO_ONE_NAT\n - name: the-second-vm\n type: compute.v1.instance\n properties:\n zone: us-central1-f\n machineType: https://www.googleapis.com/compute/v1/projects/MY_PROJECT/zones/us-central1-f/machineTypes/g1-small\n disks:\n - deviceName: boot\n type: PERSISTENT\n boot: true\n autoDelete: true\n initializeParams:\n sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-11\n networkInterfaces:\n # As in the resource above, the \"network\" value has been replaced with \n # the new network's \"selfLink\" property. \n - network: $(ref.a-new-network.selfLink)\n accessConfigs:\n - name: External NAT\n type: ONE_TO_ONE_NAT\n # The following network is a new resource added to the \"two-vms.yaml\" file.\n - name: a-new-network\n type: compute.v1.network\n properties:\n routingConfig:\n routingMode: REGIONAL\n autoCreateSubnetworks: true\n\nWhen you deploy this configuration, the network is created before the two\ninstances, and the reference resolves to the `selfLink` of the network resource.\n\nMaking references in templates\n------------------------------\n\nIn template files, the entire reference must be preceded by a `$` and then\ncontained within a set of parentheses: \n\n $(ref.RESOURCE_NAME.PROPERTY)\n\nYou can combine references with other features like template properties\nand environment variables. To make sure that Deployment Manager parses the\nreference correctly, it is important to remember to keep your entire reference\nstring within the parentheses.\n| **Note:** Your reference declaration is evaluated after your template is processed and the [expanded configuration is created](/deployment-manager/docs/deployments/viewing-manifest#expanded_configuration), so you can't use the processed value of a reference in your Python or Jinja code. If you need to get the value of a reference after you create or update a deployment, consider [exposing the value as an output](/deployment-manager/docs/configuration/expose-information-outputs) and accessing the value after the create or update operation.\n\nHere are some examples of declaring references in your templates: \n\n### Jinja\n\n- Reference that includes an environment variable\n\n network: $(ref.{{ env[\"deployment\"] }}-network.selfLink)\n\n- Reference to a value in an array\n\n subnetwork: $(ref.{{ env[\"deployment\"] }}-vm.networkInterfaces[2].subnetwork)\n\n- Reference that includes a [template property](/deployment-manager/docs/configuration/templates/define-template-properties)\n\n network: $(ref.{{ properties[\"network\"] }}.selfLink)\n\n- Reference using a Jinja parameter\n\n network: $(ref.{{ NETWORK_NAME }}.selfLink)\n\n- Reference in [outputs](/deployment-manager/docs/configuration/expose-information-outputs)\n\n outputs:\n - name: UrlToService\n value: http://$(ref.{{ env[\"deployment\"] }}-network.networkInterfaces[0].accessConfigs[0].natIp):8080/\n\n### Python\n\n- Reference that includes an environment variable\n\n 'network': '$(ref.' + context.env['deployment'] + '-network.selfLink)'\n\n- Reference to a value in an array\n\n 'subnetwork': '$(ref.' + context.env['deployment'] + '-vm.networkInterfaces[2].subnetwork)'\n\n- Reference that includes a [template property](/deployment-manager/docs/configuration/templates/define-template-properties)\n\n 'network': '$(ref.' + context.properties['network'] + '.selfLink)'\n\n- Reference using a Python parameter\n\n 'value': '$(ref.' + base_name + '.networkInterfaces[0].networkIP)'\n\n- Reference in [outputs](/deployment-manager/docs/configuration/expose-information-outputs)\n\n outputs = [{'name': 'UrlToService',\n 'value': '$(ref.' + context.env['deployment'] + '-network.networkInterfaces[0].accessConfigs[0].natIP):8080'}]\n\nWhat's next\n-----------\n\n- [Preview your configuration](/deployment-manager/docs/configuration/preview-configuration-file) before you commit to deploying it.\n- [Create a deployment](/deployment-manager/docs/deployments).\n- Learn more about [templates](/deployment-manager/docs/configuration/templates/create-basic-template)."]]