juju / terraform-provider-juju

A Terraform provider for Juju
Apache License 2.0
19 stars 32 forks source link

Scale a "daemon" application not supported #456

Open mcarvalhor opened 2 months ago

mcarvalhor commented 2 months ago

Description

When we deploy a "daemon" juju application using terraform without explicit unit count, every terraform apply command fails with "Unable to update application resource, got error: scale a "daemon" application not supported".

We can see from the plan that juju terraform provider is trying to change the number of units, and it shouldn't.

The current workaround is: ignore the error.

Urgency

Annoying bug in our test suite

Terraform Juju Provider version

0.11.0

Terraform version

v1.7.2-dev

Terraform Configuration(s)

# This plan should be deployed on a Juju KUBERNETES model.
# Please notice that I am NOT specifying "units = X" for the applications.

resource "juju_application" "metallb-controller" {
  name  = "metallb-controller"
  model = "my-model-name"

  charm {
    name     = "metallb-controller"
    channel  = "latest/stable"
    revision = 46
  }

  config = {
    iprange  = "10.1.2.3/32" # This is my Kubernetes worker ingress IP list.
    protocol = "layer2"
  }
}

resource "juju_application" "metallb-speaker" {
  name  = "metallb-speaker"
  model = "my-model-name"

  charm {
    name     = "metallb-speaker"
    channel  = "latest/stable"
    revision = 41
  }
}

Reproduce / Test

$ # Juju Status is empty. This should be an empty kubernetes model.
$
$ terraform init && terraform apply -auto-approve

$ # Now Juju Status shows 1 unit for "metallb-controller" and X units for "metallb-speaker".
$ #  where X is dynamic and depends on the number of units on the underlying Kubernetes cloud - an information abstracted from this model.

$ # Now let's try to run `terraform apply` again. No changes should be expected.
$ terraform apply
$ # Hm. Actually we see changes (eg.: https://pastebin.canonical.com/p/WHgMTWBy2P/). This is wrong, and even when trying to apply it fails.

Debug/Panic Output

https://private-fileshare.canonical.com/~mcarvalhor/2024-04-16_terraform-provider-daemon-application-issue/.XWe1p1qVPiQQktN6nALn/tf-debug.log

Notes & References

I have a live environment on Canonical private cloud (Prodstack 6) where this issue is seen. Feel free to ping me on Mattermost if you'd like to troubleshoot this using that environment.

hmlanigan commented 2 months ago

@mcarvalhor What version if juju are the controller and model running?

mcarvalhor commented 2 months ago

Hi!

Controller: v3.1.8
Model: v3.1.8
mcarvalhor commented 2 months ago

Another workaround is adding:

  lifecycle{
    ignore_changes = [ units, ]
  }

This one is better as we don't even see the changes on the plan. But I guess the bug still needs a permanent fix.