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 the dependsOn
option in your configuration
files or templates. When you add the dependsOn
option 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 the Types Overview.
Before you begin
- If you want to use the command-line examples in this guide, install the `gcloud` command-line tool.
- If you want to use the API examples in this guide, set up API access.
Creating dependencies
To add a dependency to a resource, add a metadata
section that contains a
dependsOn
section. Then, in the dependsOn
section, specify one or more
dependencies.
In the following example, to make a-special-vm
dependent on the creation of two
persistent disks, add the metadata
and dependsOn
sections for a-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 are persistent-disk-a
and persistent-disk-b
:
resources:
- name: a-special-vm
type: compute.v1.instances
properties:
...
metadata:
dependsOn:
- persistent-disk-a
- persistent-disk-b
- name: persistent-disk-a
type: compute.v1.disks
properties:
...
- name: persistent-disk-b
type: compute.v1.disks
properties:
...
In this deployment, Deployment Manager creates persistent-disk-a
and
persistent-disk-b
before creating a-special-vm
.
What's next
- Create a deployment.
- Learn about references.
- Learn more about templates.