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

Update charm resources if necessary when updating a charm #326

Merged
merged 2 commits into from
Oct 19, 2023

Conversation

cderici
Copy link

@cderici cderici commented Oct 18, 2023

Description

Updates the charm resources (if needed) when refreshing a charm.

Fixes #278

Type of change

  • Logic changes in resources (the API interaction with Juju has been changed)

Environment

  • Juju controller version: 2.9.46

  • Terraform version: 1.5

QA steps

I used coredns on microk8s to test this, any charm with different resource revisions would work for the QA.
We start with the channel=1.27/stable revision=48 as follows:

provider "juju" {}

resource "juju_model" "tst278" {
  name = "tst278"

  cloud {
    name = "microk8s"
    region = "localhost"
  }
}

resource "juju_application" "tst" {
  name = "corednstest"

  model = juju_model.tst278.name

  charm {
    name = "coredns"
    channel = "1.27/stable"
    revision = 48
    series = "jammy"
  }
}

Apply this plan:

 $ terraform init && terraform plan && terraform apply --auto-approve

Check that the application has the resource revision 13:

juju resources coredns
Resource       Supplied by  Revision
coredns-image  charmstore   13

Now modify the charm details in the plan and change it to channel=1.28/stable revision=121, and re-apply.

You should see an update in-place for the application in the plan:

$ terraform plan
juju_model.tst278: Refreshing state... [id=4c930e9e-9ef7-496b-8d10-5127662a8ea3]
juju_application.tst: Refreshing state... [id=tst278:corednstest]

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.tst will be updated in-place
  ~ resource "juju_application" "tst" {
        id          = "tst278:corednstest"
        name        = "corednstest"
        # (5 unchanged attributes hidden)

      ~ charm {
          ~ channel  = "1.27/stable" -> "1.28/stable"
            name     = "coredns"
          ~ revision = 48 -> 121
            # (1 unchanged attribute hidden)
        }
    }

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

Now apply this with terraform apply --auto-approve and check the resource revision, it should be 60 🎉 :

juju resources coredns
Resource       Supplied by  Revision
coredns-image  charmstore   60

Additional notes

JUJU-4527

Copy link
Member

@hmlanigan hmlanigan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with a couple small things

internal/juju/applications.go Outdated Show resolved Hide resolved
internal/juju/applications.go Outdated Show resolved Hide resolved
@cderici cderici merged commit 3548c49 into juju:main Oct 19, 2023
16 checks passed
@hmlanigan hmlanigan added the kind/bug indicates a bug in the project label Oct 26, 2023
@hmlanigan hmlanigan added this to the 0.10.0 milestone Oct 26, 2023
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

Successfully merging this pull request may close these issues.

Updating a charm through Terraform doesn't update resources
2 participants