You can use references to define the properties of your configuration or templates instead of directly providing values.
With references, you can access properties that are not defined until the resource is created. For example, when you define a virtual machine (VM) in your configuration, you do not know its IP address. However, you can create a reference to the IP address.
In this step, you will examine an updated two-vms.yaml
that contains a
network, as well as VM instances that reference the network.
Opening the new configuration
Open a new two-vms.yaml
, which defines a network called a-new-network
:
cd deploymentmanager-samples/examples/v2/step_by_step_guide/step4_use_references
nano two-vms.yaml # use your preferred text editor
Viewing the references to the network
In the properties
section of both your virtual machine instances, note that
the value of network
have a reference to the new network's selfLink
property, so that the network interface property looks like this:
networkInterfaces:
- network: $(ref.a-new-network.selfLink)
Deploying the configuration
In the sample, replace all instances of MY_PROJECT with your project ID, then deploy your configuration with the following command:
gcloud deployment-manager deployments create deployment-with-references --config two-vms.yaml
To view your deployment, use the following command:
gcloud deployment-manager deployments describe deployment-with-references
Looking ahead: templates and variables
To maximize efficiency when you're building complex configurations, follow best practices such as using variables and templates.
In the next step, you will learn about templates and how they enable flexible, dynamic configurations.
Deleting your deployment
Once again, we recommend that you delete the deployment to avoid charges. You don't need this deployment for the next step. Run the following command to delete the deployment:
gcloud deployment-manager deployments delete deployment-with-references