In this step, you will explore a template that imports other templates.
After incorporating these templates, your configuration only needs to call a single template to create a deployment with all of these resources.
Opening the template for a network
Open the template named compute-engine-template.py
:
cd deploymentmanager-samples/examples/v2/step_by_step_guide/step6_use_multiple_templates/python
nano compute-engine-template.py # use your preferred text editor
This template imports other templates, for all the resources in the deployment:
vm-template.py
, vm-template-2.py
for virtual machines (VMs),
network-template.py
for a network, and firewall-template.py
for a firewall
rule.
Viewing the configuration
Open the configuration file for the deployment:
cd deploymentmanager-samples/examples/v2/step_by_step_guide/step6_use_multiple_templates/python
nano config-with-many-templates.yaml # use your preferred text editor
Notice that the configuration did not directly call the other templates.
However, the other templates are imported because compute-engine-template.py
depends on the other templates.
Saving the configuration and deploying it
Run this command to deploy the configuration:
gcloud deployment-manager deployments create deployment-with-many-templates \
--config config-with-many-templates.yaml
To view the deployment, run:
gcloud deployment-manager deployments describe deployment-with-many-templates
Looking ahead: template properties and environment variables
Next, you will replace some hard-coded parts of templates with reusable patterns such as custom template and environment variables.
Deleting your deployment
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-many-templates