Il supporto di Cloud Deployment Manager terminerà il 31 dicembre 2025. Se al momento utilizzi Deployment Manager, esegui la migrazione a Infrastructure Manager o a una tecnologia di deployment alternativa entro il 31 dicembre 2025 per assicurarti che i tuoi servizi continuino senza interruzioni.
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
In alcuni casi, possono esserci dipendenze tra le risorse, ad esempio quando è necessario che alcune parti dell'ambiente esistano prima di poter implementare altre parti dell'ambiente. Ad esempio, se vuoi creare un nuovo progetto nell'ambito di un deployment, devi assicurarti che il progetto sia stato creato prima di aggiungere risorse.
Puoi specificare queste dipendenze utilizzando l'opzione dependsOn nei file di configurazione o nei modelli. Quando aggiungi l'opzione dependsOn per una risorsa, Deployment Manager crea o aggiorna le dipendenze prima di creare o aggiornare la risorsa.
Puoi creare dipendenze tra i tipi di base che fanno parte del tuo deployment nel file di configurazione o nei modelli che utilizzi per il deployment.
Non puoi impostare una dipendenza su file di modelli o tipi compositi.
Per informazioni di base sui tipi di base e composti, consulta la Panoramica dei tipi.
Se vuoi utilizzare gli esempi di API in questa guida, configura l'accesso API.
Creazione di dipendenze
Per aggiungere una dipendenza a una risorsa, aggiungi una sezione metadata contenente una sezione dependsOn. Poi, nella sezione dependsOn, specifica una o più dipendenze.
Nell'esempio seguente, per fare in modo che a-special-vm dipenda dalla creazione di due dischi permanenti, aggiungi le sezioni metadata e dependsOn per a-special-vm.
Aggiungi poi le dipendenze per ogni disco persistente.
Nello stesso deployment, devi definire i dischi permanenti che sono dipendenze.
In questo esempio, i dischi sono persistent-disk-a e persistent-disk-b:
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-08 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)."]]