Declare dependencies between components to control the order that installs provision/deprovision the parts of your app.

Why Dependencies?

Most applications have either explicit, or implicit dependencies between the different components that comprise them.

For example, given an app that comprises a Helm chart component and a Terraform component:

resource "nuon_helm_chart_component" "helm" {
  name   = "helm"
  app_id = nuon_app.main.id

  chart_name = "helm"
  connected_repo = {
    directory = "helm"
    repo      = "your-org/your-repo"
    branch    = "main"
  }

  value {
    name = "database_url"
    value = "{{.nuon.components.database.outputs.database_url}}"
  }
}

In this example, the helm chart requires that the database be provisioned before it is deployed. Otherwise, the database will not exist yet, and the database_url output will not be defined.

When deprovisioning the install, the helm chart must be deprovisioned before the database, to ensure no active dependencies exist, preventing the database from being shut down.

Defining Component Dependencies

To define a component dependency, add a dependencies field in the component config, that references the parent component it depends on.

To define a dependency:

resource "nuon_helm_chart_component" "helm" {
  name   = "helm"
  app_id = nuon_app.main.id

  dependencies = [
    nuon_terraform_module_component.database.id
  ]
  chart_name = "helm"
  connected_repo = {
    directory = "helm"
    repo      = "nuonco/mono"
    branch    = "main"
  }
}

Nuon automatically checks for cycles, and will error when trying to update a component config to contain a dependency cycle.

Install Provisioning

When an install is provisioned, Nuon will generate a graph of the app based on the defined dependencies. Nuon will automatically deploy the latest build of each component to the install. In the previous example, this means that the database component would be deployed before the Helm chart.

For example, when you create a new install, each component will automatically be deployed:

$ nuon installs create

To check the status of each component on the install:

$ nuon installs components

Install Deprovisioning

When an install is deprovisioned, Nuon will generate a graph of all the deployed components on the install, and walk them in reverse, to deprovision them properly. In the previous example, this means the helm component would be deprovisioned before the database.