Cloud Deployment Manager will reach end of support onDecember 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 collectionsSave and categorize content based on your preferences.
In some cases, you can have dependencies between your resources, such as when
you need certain parts of your environment to exist before you can deploy other
parts of the environment. For example, if you want to create a new project as
part of a deployment, you need to ensure that the project is created before you
add any resources to it.
You can specify these dependencies using thedependsOnoption in your configuration
files or templates. When you add thedependsOnoption for a resource, Deployment
Manager creates or updates the dependencies before creating or updating
the resource.
You can create dependencies between base types that are part of your deployment,
either in the configuration file, or in the templates that you use for the deployment.
You cannot set a dependency on template files or composite types.
For background information on base and composite types, see theTypes Overview.
If you want to use the API examples in this guide, set upAPI access.
Creating dependencies
To add a dependency to a resource, add ametadatasection that contains adependsOnsection. Then, in thedependsOnsection, specify one or more
dependencies.
In the following example, to makea-special-vmdependent on the creation of two
persistent disks, add themetadataanddependsOnsections fora-special-vm.
Then, add the dependencies for each persistent disk.
In the same deployment, you must define the persistent disks that are dependencies.
In this example, the disks arepersistent-disk-aandpersistent-disk-b:
[[["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\u003eDependencies between resources ensure that certain parts of an environment are created or updated before others, which is specified with the \u003ccode\u003edependsOn\u003c/code\u003e option in configuration files or templates.\u003c/p\u003e\n"],["\u003cp\u003eYou can establish dependencies between base types in configuration files or templates, but not on template files or composite types.\u003c/p\u003e\n"],["\u003cp\u003eTo create a dependency, you must include a \u003ccode\u003emetadata\u003c/code\u003e section with a \u003ccode\u003edependsOn\u003c/code\u003e subsection in the resource definition, listing the names of the resources it depends on, such as the example provided where \u003ccode\u003ea-special-vm\u003c/code\u003e depends on \u003ccode\u003epersistent-disk-a\u003c/code\u003e and \u003ccode\u003epersistent-disk-b\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eDeployment Manager will create or update the dependent resources before creating or updating the resource that lists them as a dependency.\u003c/p\u003e\n"],["\u003cp\u003eDependency loops, where resource A depends on resource B and vice-versa, are not allowed and will cause the deployment to fail.\u003c/p\u003e\n"]]],[],null,["# Creating Explicit Dependencies\n\nIn some cases, you can have dependencies between your resources, such as when\nyou need certain parts of your environment to exist before you can deploy other\nparts of the environment. For example, if you want to create a new project as\npart of a deployment, you need to ensure that the project is created before you\nadd any resources to it.\n\nYou can specify these dependencies using the `dependsOn` option in your configuration\nfiles or templates. When you add the `dependsOn` option for a resource, Deployment\nManager creates or updates the dependencies before creating or updating\nthe resource.\n\nYou can create dependencies between base types that are part of your deployment,\neither in the configuration file, or in the templates that you use for the deployment.\nYou cannot set a dependency on template files or composite types.\n\nFor background information on base and composite types, see the\n[Types Overview](/deployment-manager/docs/fundamentals#types).\n\nBefore you begin\n----------------\n\n- If you want to use the command-line examples in this guide, install the [\\`gcloud\\` command-line tool](/sdk).\n- If you want to use the API examples in this guide, set up [API access](/deployment-manager/docs/reference/latest).\n\nCreating dependencies\n---------------------\n\nTo add a dependency to a resource, add a `metadata` section that contains a\n`dependsOn` section. Then, in the `dependsOn` section, specify one or more\ndependencies.\n\nIn the following example, to make `a-special-vm` dependent on the creation of two\npersistent disks, add the `metadata` and `dependsOn` sections for `a-special-vm`.\nThen, add the dependencies for each persistent disk.\n\nIn the same deployment, you must define the persistent disks that are dependencies.\nIn this example, the disks are `persistent-disk-a` and `persistent-disk-b`: \n\n resources:\n - name: a-special-vm\n type: compute.v1.instances\n properties:\n ...\n\n metadata:\n dependsOn:\n - persistent-disk-a\n - persistent-disk-b\n\n - name: persistent-disk-a\n type: compute.v1.disks\n properties:\n ...\n\n - name: persistent-disk-b\n type: compute.v1.disks\n properties:\n ...\n\nIn this deployment, Deployment Manager creates `persistent-disk-a` and\n`persistent-disk-b` before creating `a-special-vm`.\n| **Warning:** Avoid creating dependency loops. For example, if you specify that resource A depends on resource B, and resource B depends on resource A, a dependency loop is created, and the deployment fails. Additionally, if you use [references](/deployment-manager/docs/configuration/use-references) in your deployment, implicit dependencies are created, which might also cause dependency loops.\n\nWhat's next\n-----------\n\n- [Create a deployment](/deployment-manager/docs/deployments).\n- Learn about [references](/deployment-manager/docs/configuration/use-references).\n- Learn more about [templates](/deployment-manager/docs/configuration/templates/create-basic-template)."]]