Der Support für Cloud Deployment Manager endet am 31. Dezember 2025. Wenn Sie derzeit Deployment Manager verwenden, müssen Sie bis zum 31. Dezember 2025 zu Infrastructure Manager oder einer alternativen Bereitstellungstechnologie migrieren, damit Ihre Dienste ohne Unterbrechung weiterlaufen.
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
In diesem Schritt sehen Sie sich eine Vorlage an, mit der andere Vorlagen importiert werden.
Nach dem Einbinden dieser Vorlagen muss Ihre Konfiguration nur eine einzelne Vorlage aufrufen, um eine Bereitstellung mit all diesen Ressourcen zu erstellen.
Vorlage für ein Netzwerk öffnen
Öffnen Sie die Vorlage namens compute-engine-template.py:
cddeploymentmanager-samples/examples/v2/step_by_step_guide/step6_use_multiple_templates/python
nanocompute-engine-template.py# use your preferred text editor
Diese Vorlage importiert andere Vorlagen für alle Ressourcen in der Bereitstellung: vm-template.py, vm-template-2.py für virtuelle Maschinen (VMs), network-template.py für ein Netzwerk und firewall-template.py für eine Firewallregel.
# 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."""Creates the Compute Engine."""defGenerateConfig(context):"""Creates the Compute Engine with network and firewall."""resources=[{'name':'vm-1','type':'vm-template.py'},{'name':'vm-2','type':'vm-template-2.py'},{'name':'network-1','type':'network-template.py'},{'name':'firewall-1','type':'firewall-template.py'}]return{'resources':resources}
Konfiguration ansehen
Öffnen Sie die Konfigurationsdatei für die Bereitstellung:
cddeploymentmanager-samples/examples/v2/step_by_step_guide/step6_use_multiple_templates/python
nanoconfig-with-many-templates.yaml# use your preferred text editor
Beachten Sie, dass die Konfiguration die anderen Vorlagen nicht direkt aufgerufen hat.
Die anderen Vorlagen werden jedoch importiert, da compute-engine-template.py von den anderen Vorlagen abhängt.
# 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.imports:-path:vm-template.py-path:vm-template-2.py-path:network-template.py-path:firewall-template.py-path:compute-engine-template.pyresources:-name:compute-engine-setuptype:compute-engine-template.py
Konfiguration speichern und bereitstellen
Führen Sie folgenden Befehl aus, um die Konfiguration bereitzustellen:
Nächstes Thema: Vorlagenattribute und Umgebungsvariablen
Als Nächstes ersetzen Sie einige hartcodierte Teile von Vorlagen durch wiederverwendbare Muster wie benutzerdefinierte Vorlagenattribute und Umgebungsvariablen.
Bereitstellung löschen
Sie sollten die Bereitstellung löschen, um Kosten zu vermeiden. Diese Bereitstellung benötigen Sie für den nächsten Schritt nicht. Führen Sie den folgenden Befehl aus, um die Bereitstellung zu löschen:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-03 (UTC)."],[[["\u003cp\u003eThis step involves exploring a template, \u003ccode\u003ecompute-engine-template.py\u003c/code\u003e, which imports other templates to manage various resources within a deployment.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ecompute-engine-template.py\u003c/code\u003e imports templates such as \u003ccode\u003evm-template.py\u003c/code\u003e, \u003ccode\u003evm-template-2.py\u003c/code\u003e, \u003ccode\u003enetwork-template.py\u003c/code\u003e, and \u003ccode\u003efirewall-template.py\u003c/code\u003e to create virtual machines, a network, and a firewall rule.\u003c/p\u003e\n"],["\u003cp\u003eThe configuration file, \u003ccode\u003econfig-with-many-templates.yaml\u003c/code\u003e, only needs to call \u003ccode\u003ecompute-engine-template.py\u003c/code\u003e, as this template handles the importing of the other templates.\u003c/p\u003e\n"],["\u003cp\u003eDeploying the configuration is done using the command \u003ccode\u003egcloud deployment-manager deployments create deployment-with-many-templates --config config-with-many-templates.yaml\u003c/code\u003e, and the deployment can be deleted later with the delete command.\u003c/p\u003e\n"]]],[],null,["# Using multiple templates\n\nIn this step, you will explore a template that imports other templates.\n\nAfter incorporating these templates, your configuration only needs to call a\nsingle template to create a deployment with all of these resources.\n\nOpening the template for a network\n----------------------------------\n\nOpen the template named `compute-engine-template.py`: \n\n cd deploymentmanager-samples/examples/v2/step_by_step_guide/step6_use_multiple_templates/python\n\n nano compute-engine-template.py # use your preferred text editor\n\nThis template imports other templates, for all the resources in the deployment:\n`vm-template.py`, `vm-template-2.py` for virtual machines (VMs),\n`network-template.py` for a network, and `firewall-template.py` for a firewall\nrule. \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 \"\"\"Creates the Compute Engine.\"\"\"\n\n\n def GenerateConfig(context):\n \"\"\"Creates the Compute Engine with network and firewall.\"\"\"\n\n resources = [{\n 'name': 'vm-1',\n 'type': 'vm-template.py'\n }, {\n 'name': 'vm-2',\n 'type': 'vm-template-2.py'\n }, {\n 'name': 'network-1',\n 'type': 'network-template.py'\n }, {\n 'name': 'firewall-1',\n 'type': 'firewall-template.py'\n }]\n return {'resources': resources}\n\nViewing the configuration\n-------------------------\n\nOpen the configuration file for the deployment: \n\n cd deploymentmanager-samples/examples/v2/step_by_step_guide/step6_use_multiple_templates/python\n\n nano config-with-many-templates.yaml # use your preferred text editor\n\nNotice that the configuration did not directly call the other templates.\nHowever, the other templates are imported because `compute-engine-template.py`\ndepends on the other templates. \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 imports:\n - path: vm-template.py\n - path: vm-template-2.py\n - path: network-template.py\n - path: firewall-template.py\n - path: compute-engine-template.py\n\n resources:\n - name: compute-engine-setup\n type: compute-engine-template.py\n\nSaving the configuration and deploying it\n-----------------------------------------\n\nRun this command to deploy the configuration: \n\n gcloud deployment-manager deployments create deployment-with-many-templates \\\n --config config-with-many-templates.yaml\n\nTo view the deployment, run: \n\n gcloud deployment-manager deployments describe deployment-with-many-templates\n\nLooking ahead: template properties and environment variables\n------------------------------------------------------------\n\nNext, you will replace some hard-coded parts of templates with reusable\npatterns such as custom template and environment variables.\n\nDeleting your deployment\n------------------------\n\nWe 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-many-templates"]]