[[["容易理解","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 (世界標準時間)。"],[[["\u003cp\u003eReferences allow access to properties not defined until resource creation, such as a virtual machine's IP address.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003etwo-vms.yaml\u003c/code\u003e configuration demonstrates referencing a network's \u003ccode\u003eselfLink\u003c/code\u003e property within virtual machine network interfaces.\u003c/p\u003e\n"],["\u003cp\u003eTo deploy the configuration, instances of \u003ccode\u003eMY_PROJECT\u003c/code\u003e need to be replaced with the project ID, and a specific command needs to be run.\u003c/p\u003e\n"],["\u003cp\u003eThe deployment can be viewed with a \u003ccode\u003egcloud\u003c/code\u003e command and should be deleted after use to avoid charges.\u003c/p\u003e\n"],["\u003cp\u003eUtilizing variables and templates are recommended for efficiently building complex configurations.\u003c/p\u003e\n"]]],[],null,["# Understanding the benefits of references\n\nYou can use *references* to define the properties of your configuration or\ntemplates instead of directly providing values.\n\nWith references, you can access properties that are not defined until the\nresource is created. For example, when you define a virtual machine (VM) in your\nconfiguration, you do not know its IP address. However, you can create a\nreference to the IP address.\n\nIn this step, you will examine an updated `two-vms.yaml` that contains a\nnetwork, as well as VM instances that reference the network.\n\nOpening the new configuration\n-----------------------------\n\nOpen a new `two-vms.yaml`, which defines a network called `a-new-network`: \n\n cd deploymentmanager-samples/examples/v2/step_by_step_guide/step4_use_references\n\n nano two-vms.yaml # use your preferred text editor\n\n### Viewing the references to the network\n\nIn the `properties` section of both your virtual machine instances, note that\nthe value of `network` have a reference to the new network's `selfLink`\nproperty, so that the network interface property looks like this: \n\n networkInterfaces:\n - network: $(ref.a-new-network.selfLink)\n\nDeploying the configuration\n---------------------------\n\nIn the sample, replace all instances of \u003cvar translate=\"no\"\u003eMY_PROJECT\u003c/var\u003e\nwith your project ID, then deploy your configuration with the following command: \n\n gcloud deployment-manager deployments create deployment-with-references --config two-vms.yaml\n\nTo view your deployment, use the following command: \n\n gcloud deployment-manager deployments describe deployment-with-references\n\nLooking ahead: templates and variables\n--------------------------------------\n\nTo maximize efficiency when you're building complex configurations, follow best\npractices such as using variables and templates.\n\nIn the next step, you will learn about templates and how they enable flexible,\ndynamic configurations.\n\nDeleting your deployment\n------------------------\n\nOnce again, we recommend that you delete the deployment to avoid charges. You\ndon't need this deployment for the next step. Run the following command to\ndelete the deployment: \n\n gcloud deployment-manager deployments delete deployment-with-references"]]