How to manage the client

See also: Client

See also: terraform (CLI client)

Install the client

To install the terraform client for Juju on a Linux that supports snaps, run:

sudo snap install terraform

The client can also be installed on Windows or macOS, or on Linux in other ways.

See more: Hashicorp | Install Terraform

Make the client use the juju provider

In your file, require the juju provider:

terraform {
  required_providers {
    juju = {
      version = "~> 0.10.0"
      source  = "juju/juju"

Configure the client’s juju provider

There are 3 ways to do configure the client’s juju provider with your controller’s details.

For all methods: To view your controller's details, run:

juju show-controller --show-password

Using static credentials

In your Terraform plan, in your provider specification, use the various keywords to provide your controller information statically:

provider "juju" {
   controller_addresses = ","
   username = "jujuuser"
   password = "password1"
   ca_certificate = file("~/ca-cert.pem")

See Terraform | juju provider

Using environment variables

In your Terraform plan, leave the provider specification empty:

provider "juju" {}

In your terminal, export the controller environment variables with your controller’s values. For example:

export JUJU_USERNAME="jujuuser"
export JUJU_PASSWORD="password1"
export JUJU_CA_CERT= file("~/ca-cert.pem")

Using the juju CLI

In your Terraform plan, leave the provider specification empty:

provider "juju" {}

Then, your terminal, switch to the desired controller: juju switch <controller>. Your Terraform plan will be interpreted relative to that controller.

See also: python-libjuju

Install the client

pip3 install juju

Quick Start with Python-libjuju

Here’s a simple example that shows basic usage of the library. The example connects to the currently active Juju model, deploys a single unit of the ubuntu charm, then exits:

Note : Pylibjuju requires an already bootstrapped Juju controller to connect to.


  import logging
  import sys

  from juju import jasyncio
  from juju.model import Model

  async def deploy():
      # Create a Model instance. We need to connect our Model to a Juju api
      # server before we can use it.
      model = Model()

      # Connect to the currently active Juju model
      await model.connect()

          # Deploy a single unit of the ubuntu charm, using the latest revision
          # from the stable channel of the Charm Store.
          ubuntu_app = await model.deploy(

          if '--wait' in sys.argv:
              # optionally block until the application is ready
              await model.wait_for_idle(status = 'active')

          # Disconnect from the api server and cleanup.
          await model.disconnect()

  def main():

      # If you want to see everything sent over the wire, set this to DEBUG.
      ws_logger = logging.getLogger('websockets.protocol')

      # Run the deploy coroutine in an asyncio event loop, using a helper
      # that abstracts loop creation and teardown.

  if __name__ == '__main__':

More examples can be found in the docs, as well as in the examples directory in the repository which can be run using tox. For example, to run examples/, use:

  tox -e example -- examples/

Or you can directly run it via python as well:

 $ python3 examples/

Using Python-libjuju with Python REPL

To experiment with the library in a REPL, launch python in asyncio mode

  $ python3 -m asyncio

and then, to connect to the current model and fetch status:

  >>> from juju.model import Model
  >>> model = Model()
  >>> await model.connect_current()
  >>> status = await model.get_status()

Contributors: @cderici, @hmlanigan, @tmihoc

Last updated 6 days ago. Help improve this document in the forum.