Cloud Deployment Manager akan mencapai akhir dukungan pada 31 Desember 2025. Jika saat ini Anda menggunakan Deployment Manager, migrasikan ke Infrastructure Manager atau teknologi deployment alternatif paling lambat 31 Desember 2025 untuk memastikan layanan Anda berlanjut tanpa gangguan.
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Dalam beberapa kasus, Anda dapat memiliki dependensi antar-resource, seperti saat
Anda memerlukan bagian tertentu dari lingkungan agar dapat men-deploy bagian
lingkungan lainnya. Misalnya, jika ingin membuat project baru sebagai
bagian dari deployment, Anda harus memastikan bahwa project dibuat sebelum
menambahkan resource apa pun ke project tersebut.
Anda dapat menentukan dependensi ini menggunakan opsi dependsOn dalam file atau template konfigurasi. Saat Anda menambahkan opsi dependsOn untuk resource, Deployment Manager akan membuat atau memperbarui dependensi sebelum membuat atau memperbarui resource.
Anda dapat membuat dependensi antarjenis dasar yang merupakan bagian dari deployment,
baik dalam file konfigurasi, maupun dalam template yang Anda gunakan untuk deployment.
Anda tidak dapat menetapkan dependensi pada file template atau jenis komposit.
Untuk informasi latar belakang tentang jenis dasar dan komposit, lihat
Ringkasan Jenis.
Sebelum memulai
Jika Anda ingin menggunakan contoh command line dalam panduan ini, instal alat command line`gcloud`.
Jika Anda ingin menggunakan contoh API dalam panduan ini, siapkan akses API.
Membuat dependensi
Untuk menambahkan dependensi ke resource, tambahkan bagian metadata yang berisi
bagian dependsOn. Kemudian, di bagian dependsOn, tentukan satu atau beberapa dependensi.
Pada contoh berikut, agar a-special-vm bergantung pada pembuatan dua
disk persisten, tambahkan bagian metadata dan dependsOn untuk a-special-vm.
Kemudian, tambahkan dependensi untuk setiap disk persisten.
Dalam deployment yang sama, Anda harus menentukan persistent disk yang merupakan dependensi.
Dalam contoh ini, disk-nya adalah persistent-disk-a dan persistent-disk-b:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)."]]