Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application custom image is not properly tracked #663

Open
Batalex opened this issue Feb 3, 2025 · 2 comments
Open

Application custom image is not properly tracked #663

Batalex opened this issue Feb 3, 2025 · 2 comments
Labels
kind/bug indicates a bug in the project

Comments

@Batalex
Copy link

Batalex commented Feb 3, 2025

Description

When defining a custom image for an application, subsequent calls to terraform plan will always propose to upgrade the image, even though the application is already running it.

Urgency

Casually reporting

Terraform Juju Provider version

0.15.1,0.16.0

Terraform version

1.10.5

Juju version

3.6.2

Terraform Configuration(s)

terraform {
  required_providers {
    juju = {
      source  = "juju/juju"
      version = "0.16.0"
    }
  }
}

resource "juju_model" "spark" {
  name = "spark"
}

resource "juju_application" "history_server" {
  name  = "history-server"
  model = juju_model.spark.name
  charm {
    name     = "spark-history-server-k8s"
    channel  = "3.4/edge"
    revision = 37
  }
  resources = {
    spark-history-server-image = "ghcr.io/canonical/charmed-spark@sha256:1d9949dc7266d814e6483f8d9ffafeff32f66bb9939e0ab29ccfd9d5003a583a"
  }
  units       = 1
  constraints = "arch=amd64"
}

Reproduce / Test

terraform init
terraform apply
terraform plan

Debug/Panic Output

tf apply

Terraform used the selected providers to generate the following execution plan. Resource actions
are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # juju_application.history_server will be created
  + resource "juju_application" "history_server" {
      + constraints = "arch=amd64"
      + id          = (known after apply)
      + model       = "spark"
      + name        = "history-server"
      + placement   = (known after apply)
      + principal   = (known after apply)
      + resources   = {
          + "spark-history-server-image" = "ghcr.io/canonical/charmed-spark@sha256:1d9949dc7266d814e6483f8d9ffafeff32f66bb9939e0ab29ccfd9d5003a583a"
        }
      + storage     = (known after apply)
      + trust       = false
      + units       = 1

      + charm {
          + base     = (known after apply)
          + channel  = "3.4/edge"
          + name     = "spark-history-server-k8s"
          + revision = 37
          + series   = (known after apply)
        }
    }

  # juju_model.spark will be created
  + resource "juju_model" "spark" {
      + credential = (known after apply)
      + id         = (known after apply)
      + name       = "spark"
      + type       = (known after apply)
      + uuid       = (known after apply)
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

juju_model.spark: Creating...
juju_model.spark: Creation complete after 0s [id=4fc17aec-5851-4135-8ec3-761cebe8ec01]
juju_application.history_server: Creating...
juju_application.history_server: Creation complete after 1s [id=spark:history-server]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.



tf plan
juju_model.spark: Refreshing state... [id=4fc17aec-5851-4135-8ec3-761cebe8ec01]
juju_application.history_server: Refreshing state... [id=spark:history-server]

Terraform used the selected providers to generate the following execution plan. Resource actions
are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # juju_application.history_server will be updated in-place
  ~ resource "juju_application" "history_server" {
        id          = "spark:history-server"
        name        = "history-server"
      + principal   = (known after apply)
      ~ resources   = {
          ~ "spark-history-server-image" = "0" -> "ghcr.io/canonical/charmed-spark@sha256:1d9949dc7266d814e6483f8d9ffafeff32f66bb9939e0ab29ccfd9d5003a583a"
        }
      + storage     = (known after apply)
        # (5 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take
exactly these actions if you run "terraform apply" now.

The image seems correctly written in the state file, so the issue might be when the diff is computed:

terraform state show -state=terraform.tfstate juju_application.history_server
# juju_application.history_server:
resource "juju_application" "history_server" {
    constraints = "arch=amd64"
    id          = "spark:history-server"
    model       = "spark"
    name        = "history-server"
    placement   = ""
    resources   = {
        "spark-history-server-image" = "ghcr.io/canonical/charmed-spark@sha256:1d9949dc7266d814e6483f8d9ffafeff32f66bb9939e0ab29ccfd9d5003a583a"
    }
    trust       = false
    units       = 1

    charm {
        base     = "[email protected]"
        channel  = "3.4/edge"
        name     = "spark-history-server-k8s"
        revision = 37
        series   = "jammy"
    }
}
@Batalex Batalex added kind/bug indicates a bug in the project state/untriaged untriaged bug report labels Feb 3, 2025
@Batalex Batalex changed the title Application custom image is not properly tracked Application custom image is not properly tracked in the state Feb 3, 2025
@Batalex Batalex changed the title Application custom image is not properly tracked in the state Application custom image is not properly tracked Feb 3, 2025
@dparv
Copy link

dparv commented Feb 3, 2025

+1

@SimoneDutto
Copy link
Contributor

Hi @Batalex, thanks for reporting the bug. I've managed to reproduce the issue locally.
Unfortunately it doesn't seem to me an easy fix, I'll discuss with my colleagues to find a solution for it.
I'll update here as soon as I have any news.

@SimoneDutto SimoneDutto removed the state/untriaged untriaged bug report label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug indicates a bug in the project
Projects
None yet
Development

No branches or pull requests

3 participants