juju_application (Resource)

A resource that represents a single Juju application deployment from a charm. Deployment of bundles is not supported.

Example Usage

# An application with config, multiple units and constraints
resource "juju_application" "this" {
  name = "my-application"

  model_uuid = juju_model.development.uuid

  charm {
    name     = "ubuntu"
    channel  = "latest/stable"
    revision = 24
    base     = "[email protected]"
  }

  units = 3

  constraints = "mem=4G cores=2"

  config = {
    external-hostname = "..."
  }
}

# An application with storage directives
resource "juju_application" "this" {
  name = "my-application"

  model_uuid = juju_model.development.uuid

  charm {
    name    = "postgresql"
    channel = "14/stable"
    base    = "[email protected]"
  }

  storage_directives = {
    "pgdata" = "4G" # 4 gigabytes of storage for pgdata using the model's default storage pool
    # or
    "pgdata" = "2,4G" # 2 instances of 4 gigabytes of storage for pgdata using the model's default storage pool
    # or
    "pgdata" = "ebs,2,4G" # 2 instances of 4 gigabytes of storage for pgdata on the ebs storage pool
  }
}

# An application deployed to specific machines
# This example creates a set of machines and deploys an application to those machines.
resource "juju_machine" "all_machines" {
  count      = 5
  model_uuid = juju_model.model.uuid
  base       = "[email protected]"
  name       = "machine_${count.index}"

  # The following lifecycle directive instructs Terraform to create 
  # new machines before destroying existing ones.
  lifecycle {
    create_before_destroy = true
  }
}

resource "juju_application" "testapp" {
  name       = "juju-qa-test"
  model_uuid = juju_model.model.uuid


  machines = toset(juju_machine.all_machines[*].machine_id)

  charm {
    name    = "ubuntu"
    channel = "latest/stable"
    base    = "[email protected]"
  }
}

# K8s application with an OCI image resource from a private registry
resource "juju_application" "this" {
  name = "test-app"

  model_uuid = juju_model.this.uuid

  charm {
    name    = "coredns"
    channel = "latest/stable"
  }

  trust = true
  expose {}

  registry_credentials = {
    "ghcr.io/canonical" = {
      username = "username"
      password = "password"
    }
  }

  resources = {
    "coredns-image" : "ghcr.io/canonical/test:dfb5e3fa84d9476c492c8693d7b2417c0de8742f"
  }
}

Schema

Required

  • model_uuid (String) The UUID of the model where the application is to be deployed. Changing this value will cause the application to be destroyed and recreated by terraform.

Optional

  • charm (Block List) The charm installed from Charmhub. (see below for nested schema)

  • config (Map of String) Application specific configuration. Must evaluate to a string, integer or boolean.

  • constraints (String) Constraints imposed on this application. Changing this value will cause the application to be destroyed and recreated by terraform. Multiple constraints can be provided as a space-separated list.

  • endpoint_bindings (Attributes Set) Configure endpoint bindings (see below for nested schema)

  • expose (Block List) Makes an application publicly available over the network (see below for nested schema)

  • machines (Set of String) Specify the target machines for the application’s units. The number of machines in the set indicates the unit count for the application. Removing a machine from the set will remove the application’s unit residing on it. machines is mutually exclusive with units.

  • name (String) A custom name for the application deployment. If empty, uses the charm’s name.Changing this value will cause the application to be destroyed and recreated by terraform.

  • registry_credentials (Attributes Map) OCI image registry credentials for OCI images specified in the charm resources. The map key is the registry URL.

    If the charm resource requires authentication, supply a username and password that will be passed to the Juju API and added to the Kubernetes cluster.

    The registry credentials will only be used if the URL of the registry is a partial match for the OCI image URL specified in the charm resources. An OCI image URL is considered a match for a registry URL if the URL without the OCI image tag matches the registry URL. For example, a charm OCI resource specified as “registry.example.com:5000/path/image:tag ” will match a registry entry with key “registry.example.com:5000/path ” but not “registry.example.com:5000 ” nor “registry.example.com ”. (see below for nested schema)

  • resources (Map of String) Charm resources. Must evaluate to a string. A resource could be a resource revision number from CharmHub or a custom OCI image resource. Specify a resource other than the default for a charm. Note that not all charms have resources.

Notes:

  • A resource can be specified by a revision number or by URL to a OCI image repository. Resources of type ‘file’ can only be specified by revision number. Resources of type ‘oci-image’ can be specified by revision number or URL.

  • A resource can be added or changed at any time. If the charm has resources and None is specified in the plan, Juju will use the resource defined in the charm’s specified channel.

  • If a charm is refreshed, by changing the charm revision or channel and if the resource is specified by a revision in the plan, Juju will use the resource defined in the plan.

  • Resources specified by URL to an OCI image repository will never be refreshed (upgraded) by juju during a charm refresh unless explicitly changed in the plan.

  • storage_directives (Map of String) Storage directives (constraints) for the juju application. The map key is the label of the storage defined by the charm, the map value is the storage directive in the form [,][,][] where at least one constraint must be specified. See https://documentation.ubuntu.com/juju/3.6/reference/storage/ for more details. If a pool is not specified, the model’s default pool will be used. Changing an existing key/value pair will cause the application to be replaced. Adding a new key/value pair will add storage to the application on upgrade.

  • trust (Boolean) Set the trust for the application.

  • units (Number) The number of application units to deploy for the charm.

Read-Only

  • id (String) The ID of this resource.

  • model_type (String) The type of the model where the application is deployed. It is a computed field and is needed to determine if the application should be replaced or updated in case of base updates.

  • storage (Attributes Set) Storage used by the application. (see below for nested schema)

Nested Schema for charm

Required:

  • name (String) The name of the charm to be deployed. Changing this value will cause the application to be destroyed and recreated by terraform.

Optional:

  • base (String) The operating system on which to deploy. E.g. ubuntu@22.04. Changing this value for machine charms will trigger a replace by terraform.

  • channel (String) The channel to use when deploying a charm. Specified as <track>/<risk>/<branch>.

  • revision (Number) The revision of the charm to deploy. During the update phase, the charm revision should be update before config update, to avoid issues with config parameters parsing.

Nested Schema for endpoint_bindings

Required:

  • space (String) Name of the space to bind the endpoint to.

Optional:

  • endpoint (String) Name of the endpoint to bind to a space. Keep null (or undefined) to define default binding.

Nested Schema for expose

Optional:

  • cidrs (String) A comma-delimited list of CIDRs that should be able to access the application ports once exposed.

  • endpoints (String) Expose only the ports that charms have opened for this comma-delimited list of endpoints

  • spaces (String) A comma-delimited list of spaces that should be able to access the application ports once exposed.

Nested Schema for registry_credentials

Required:

  • password (String, Sensitive) The password for authenticating to the registry.

  • username (String) The username for authenticating to the registry.

Nested Schema for storage

Read-Only:

  • count (Number) The number of volumes.

  • label (String) The specific storage option defined in the charm.

  • pool (String) Name of the storage pool.

  • size (String) The size of each volume.

Import

Import is supported using the following syntax:

# Applications can be imported using the format: `model_uuid:application_name`, for example:
$ terraform import juju_application.wordpress abe22490-a845-4a4d-ba52-7ec80a60aff5:wordpress