Cloud Deployment Manager will reach end of support on December 31, 2025. If you currently use Deployment Manager, please migrate to Infrastructure Manager or an alternative deployment technology by December 31, 2025 to ensure your services continue without interruption.
Stay organized with collections
Save and categorize content based on your preferences.
After you have a deployment, you can update it as your app evolves. You can use
Deployment Manager to update a deployment by:
Adding or removing resources to the deployment
Updating some properties of existing resources in your deployment
Deployment Manager uses the underlying APIs of Google Cloud services
to manage resources in your deployment. Deployment Manager can update
existing resources if there is an update or patch method in the
corresponding API.
Deploy the original configuration
In this step, deploy the configuration that you will update later. Navigate to
the folder in the GitHub repository, and deploy the configuration:
The configuration deploys two virtual machines (VMs) that run a startup script.
The VM template is:
# 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 virtual machine with environment variables and startup script."""COMPUTE_URL_BASE='https://www.googleapis.com/compute/v1/'defGenerateConfig(context):"""Creates the virtual machine."""resources=[{'name':context.env['name'],'type':'compute.v1.instance','properties':{'zone':context.properties['zone'],'machineType':''.join([COMPUTE_URL_BASE,'projects/',context.env['project'],'/zones/',context.properties['zone'],'/machineTypes/',context.properties['machineType']]),'disks':[{'deviceName':'boot','type':'PERSISTENT','boot':True,'autoDelete':True,'initializeParams':{'sourceImage':''.join([COMPUTE_URL_BASE,'projects/','debian-cloud/global/','images/family/debian-11'])}}],'networkInterfaces':[{'network':'$(ref.'+context.properties['network']+'.selfLink)','accessConfigs':[{'name':'External NAT','type':'ONE_TO_ONE_NAT'}]}],'metadata':{'items':[{'key':'startup-script','value':''.join(['#!/bin/bash\n','python -m SimpleHTTPServer 80'])}]}}}]return{'resources':resources}
In the updated template, in the metadata section, the VM's startup script
has been changed:
# 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 virtual machine with environment variables and startup script."""COMPUTE_URL_BASE='https://www.googleapis.com/compute/v1/'defGenerateConfig(context):"""Creates the virtual machine."""resources=[{'name':context.env['name'],'type':'compute.v1.instance','properties':{'zone':context.properties['zone'],'machineType':''.join([COMPUTE_URL_BASE,'projects/',context.env['project'],'/zones/',context.properties['zone'],'/machineTypes/',context.properties['machineType']]),'disks':[{'deviceName':'boot','type':'PERSISTENT','boot':True,'autoDelete':True,'initializeParams':{'sourceImage':''.join([COMPUTE_URL_BASE,'projects/','debian-cloud/global/','images/family/debian-11'])}}],'networkInterfaces':[{'network':'$(ref.'+context.properties['network']+'.selfLink)','accessConfigs':[{'name':'External NAT','type':'ONE_TO_ONE_NAT'}]}],'metadata':{'items':[{'key':'startup-script','value':''.join(['#!/bin/bash\n','INSTANCE=$(curl http://metadata.google.','internal/computeMetadata/v1/instance/','hostname -H "Metadata-Flavor: Google")\n','echo "<html><header><title>Hello from ','Deployment Manager!</title></header>','<body><h2>Hello from $INSTANCE</h2><p>','Deployment Manager bids you good day!</p>','</body></html>" > index.html\n','python -m SimpleHTTPServer 80\n'])}]}}}]return{'resources':resources}
You will use this updated template to change the deployment you created.
Preview the update
To preview the updated deployment, run the update command with a --preview
flag:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eDeployment Manager allows you to update a deployment by adding or removing resources, or by updating properties of existing resources, using the underlying Google Cloud APIs.\u003c/p\u003e\n"],["\u003cp\u003eTo update a deployment, you first deploy an initial configuration which will later be modified, such as deploying two virtual machines (VMs) running a startup script.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves opening and modifying an updated template where a specific aspect of the initial setup is changed, as demonstrated by changing the startup script for a virtual machine.\u003c/p\u003e\n"],["\u003cp\u003eBefore finalizing the update, you can preview the changes to the deployment to ensure they align with your expectations, followed by committing the update.\u003c/p\u003e\n"],["\u003cp\u003eAfter committing the update, it's necessary to restart the affected instances and then confirm the update has been applied by examining the instance, such as by checking for the new welcome message in this example.\u003c/p\u003e\n"]]],[],null,["# Updating a deployment\n\nAfter you have a deployment, you can update it as your app evolves. You can use\nDeployment Manager to update a deployment by:\n\n- Adding or removing resources to the deployment\n- Updating some properties of existing resources in your deployment\n\nDeployment Manager uses the underlying APIs of Google Cloud services\nto manage resources in your deployment. Deployment Manager can update\nexisting resources if there is an `update` or `patch` method in the\ncorresponding API.\n\nDeploy the original configuration\n---------------------------------\n\nIn this step, deploy the configuration that you will update later. Navigate to\nthe folder in the GitHub repository, and deploy the configuration: \n\n cd deploymentmanager-samples/examples/v2/step_by_step_guide/step8_metadata_and_startup_scripts/python\n\n gcloud deployment-manager deployments create deployment-to-update --config config-with-many-templates.yaml\n\nThe configuration deploys two virtual machines (VMs) that run a startup script.\nThe VM template is: \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 virtual machine with environment variables and startup script.\"\"\"\n\n\n COMPUTE_URL_BASE = 'https://www.googleapis.com/compute/v1/'\n\n\n def GenerateConfig(context):\n \"\"\"Creates the virtual machine.\"\"\"\n\n resources = [{\n 'name': context.env['name'],\n 'type': 'compute.v1.instance',\n 'properties': {\n 'zone': context.properties['zone'],\n 'machineType': ''.join([COMPUTE_URL_BASE, 'projects/',\n context.env['project'], '/zones/',\n context.properties['zone'], '/machineTypes/',\n context.properties['machineType']]),\n 'disks': [{\n 'deviceName': 'boot',\n 'type': 'PERSISTENT',\n 'boot': True,\n 'autoDelete': True,\n 'initializeParams': {\n 'sourceImage': ''.join([COMPUTE_URL_BASE, 'projects/',\n 'debian-cloud/global/',\n 'images/family/debian-11'])\n }\n }],\n 'networkInterfaces': [{\n 'network': '$(ref.' + context.properties['network']\n + '.selfLink)',\n 'accessConfigs': [{\n 'name': 'External NAT',\n 'type': 'ONE_TO_ONE_NAT'\n }]\n }],\n 'metadata': {\n 'items': [{\n 'key': 'startup-script',\n 'value': ''.join(['#!/bin/bash\\n',\n 'python -m SimpleHTTPServer 80'])\n }]\n }\n }\n }]\n return {'resources': resources}\n\nOpen the updated template\n-------------------------\n\nNow, open the updated template: \n\n cd deploymentmanager-samples/examples/v2/step_by_step_guide/step9_update_a_deployment/python\n\n nano vm-template.py\n\nIn the updated template, in the `metadata` section, the VM's startup script\nhas been changed: \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 virtual machine with environment variables and startup script.\"\"\"\n\n\n COMPUTE_URL_BASE = 'https://www.googleapis.com/compute/v1/'\n\n\n def GenerateConfig(context):\n \"\"\"Creates the virtual machine.\"\"\"\n\n resources = [{\n 'name': context.env['name'],\n 'type': 'compute.v1.instance',\n 'properties': {\n 'zone': context.properties['zone'],\n 'machineType': ''.join([COMPUTE_URL_BASE, 'projects/',\n context.env['project'], '/zones/',\n context.properties['zone'], '/machineTypes/',\n context.properties['machineType']]),\n 'disks': [{\n 'deviceName': 'boot',\n 'type': 'PERSISTENT',\n 'boot': True,\n 'autoDelete': True,\n 'initializeParams': {\n 'sourceImage': ''.join([COMPUTE_URL_BASE, 'projects/',\n 'debian-cloud/global/',\n 'images/family/debian-11'])\n }\n }],\n 'networkInterfaces': [{\n 'network': '$(ref.' + context.properties['network']\n + '.selfLink)',\n 'accessConfigs': [{\n 'name': 'External NAT',\n 'type': 'ONE_TO_ONE_NAT'\n }]\n }],\n 'metadata': {\n 'items': [{\n 'key': 'startup-script',\n 'value': ''.join(['#!/bin/bash\\n',\n 'INSTANCE=$(curl http://metadata.google.',\n 'internal/computeMetadata/v1/instance/',\n 'hostname -H \"Metadata-Flavor: Google\")\\n',\n 'echo \"\u003chtml\u003e\u003cheader\u003e\u003ctitle\u003eHello from ',\n 'Deployment Manager!\u003c/title\u003e\u003c/header\u003e',\n '\u003cbody\u003e\u003ch2\u003eHello from $INSTANCE\u003c/h2\u003e\u003cp\u003e',\n 'Deployment Manager bids you good day!\u003c/p\u003e',\n '\u003c/body\u003e\u003c/html\u003e\" \u003e index.html\\n',\n 'python -m SimpleHTTPServer 80\\n'])\n }]\n }\n }\n }]\n return {'resources': resources}\n\nYou will use this updated template to change the deployment you created.\n\nPreview the update\n------------------\n\nTo preview the updated deployment, run the `update` command with a `--preview`\nflag: \n\n gcloud deployment-manager deployments update deployment-to-update --config config-with-many-templates.yaml --preview\n\nCommit the update\n-----------------\n\nTo commit the update, run: \n\n gcloud deployment-manager deployments update deployment-to-update\n\nVerify the update\n-----------------\n\nTo check if the update worked, you must first restart the instances to use\nthe new startup script. Restart `the-first-vm`: \n\n gcloud compute instances reset the-first-vm\n\nThe instance might take some time to start back up. Wait a couple minutes before\nconfirming the change.\n\n### Confirm the new startup script\n\n1. Get the external IP of `the-first-vm`:\n\n gcloud compute instances describe the-first-vm | grep \"natIP\"\n\n2. Copy the value.\n\n3. Open a browser and paste the IP address into the address bar to visit your\n instance.\n\n The page should now show a welcome message that says\n \"Deployment Manager bids you good day!\"\n\nYou can also repeat these steps with `the-second-vm` and see a slightly\ndifferent message.\n\nDelete your deployment\n----------------------\n\nAs with previous steps, we recommend that you delete the deployment to avoid\ncharges. Run the following command to delete the deployment: \n\n gcloud deployment-manager deployments delete deployment-to-update\n\nWhat's next\n-----------\n\nHere are some areas to explore as you use Deployment Manager more:\n\n- [Explore more complex tutorials](/deployment-manager/docs/tutorials)\n- [Learn about available resource types](/deployment-manager/docs/configuration/supported-resource-types)\n- [Learn more about environment variables](/deployment-manager/docs/configuration/templates/use-environment-variables)\n- [Learn about importing Python libraries](/deployment-manager/docs/configuration/templates/import-python-libraries)\n- [Read the guidelines for preparing updates](/deployment-manager/docs/deployments/updating-deployments)"]]