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

Changing charm base should be replace? #635

Open
hloeung opened this issue Nov 25, 2024 · 4 comments
Open

Changing charm base should be replace? #635

hloeung opened this issue Nov 25, 2024 · 4 comments
Assignees
Labels
area/application kind/bug indicates a bug in the project

Comments

@hloeung
Copy link

hloeung commented Nov 25, 2024

Description

When the charm base is changed, it triggers a change which then applies successfully, but isn't actually changed and causes a loop in our Flux CI/CD system constantly trying to apply this change.

| 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:
|
|   # module.canonical_k8s.juju_application.k8s_control will be updated in-place
|   ~ resource "juju_application" "k8s_control" {
|         id          = "stg-mcarvalhor-1:k8s-control"
|         name        = "k8s-control"
|       + principal   = (known after apply)
|       + storage     = (known after apply)
|         # (6 unchanged attributes hidden)
|
|       ~ charm {
|           ~ base     = "[email protected]" -> "[email protected]"
|             name     = "k8s"
|             # (3 unchanged attributes hidden)
|         }
|
|         # (1 unchanged block hidden)
|     }
|
|   # module.canonical_k8s.juju_application.k8s_worker will be updated in-place
|   ~ resource "juju_application" "k8s_worker" {
|         id          = "stg-mcarvalhor-1:k8s-worker"
|         name        = "k8s-worker"
|       + principal   = (known after apply)
|       + storage     = (known after apply)
|         # (6 unchanged attributes hidden)
|
|       ~ charm {
|           ~ base     = "[email protected]" -> "[email protected]"
|             name     = "k8s-worker"
|             # (3 unchanged attributes hidden)
|         }
|     }
|
| Plan: 0 to add, 2 to change, 0 to destroy.

Changing a charm's base should perhaps trigger a replacement instead?

Urgency

Casually reporting

Terraform Juju Provider version

0.15.0

Terraform version

v1.9.8-dev

Juju version

3.5.4

Terraform Configuration(s)

resource "juju_application" "ntp" {
  name  = "ntp"
  model = local.juju_model_name

  charm {
    name     = "chrony"
    channel  = "latest/edge"
    revision = 35
    base     = "[email protected]"
  }

  expose {}
}

Reproduce / Test

terraform init
terraform apply
(update charm bases from `[email protected]` to `[email protected]`)
terraform apply

Debug/Panic Output

No response

Notes & References

No response

@hloeung hloeung added kind/bug indicates a bug in the project state/untriaged untriaged bug report labels Nov 25, 2024
@hmlanigan
Copy link
Member

Triggering a replacement for a base (or series) change is also problematic as is. With a machine charm the application needs to be redeployed to do this. However it's okay with a Kubernetes charm as an upgrade uses a new OCI Image, which can effectively "upgrade" the base with no problems.

We can handle both scenarios with the RequiresReplaceIf rather than RequiresReplace.

Even with this change, there are potential problems with a clean run depending on how a plan is written and a bug in the provider.

The bug is #521. In that case, run terraform apply a second time and it should be okay.

Issues based on how the terraform plan is written:

  • If there is a machine resource used for the application and the machine isn't also replaced, the new deploy will fail.
  • Any integrations will not be recreated unless the integration resource example is followed

Maybe others.

@hmlanigan hmlanigan added area/application and removed state/untriaged untriaged bug report labels Dec 19, 2024
SimoneDutto added a commit to SimoneDutto/terraform-provider-juju that referenced this issue Jan 7, 2025
…harms

This PR adds support to update the base in application charms by requiring a replace in case of a
machine charm, and perform the upgrade in case of a k8s charm.

re juju#635
SimoneDutto added a commit to SimoneDutto/terraform-provider-juju that referenced this issue Jan 7, 2025
…harms

This PR adds support to update the base in application charms by requiring a replace in case of a
machine charm, and perform the upgrade in case of a k8s charm.

re juju#635
SimoneDutto added a commit to SimoneDutto/terraform-provider-juju that referenced this issue Jan 7, 2025
…harms

This PR adds support to update the base in application charms by requiring a replace in case of a
machine charm, and perform the upgrade in case of a k8s charm.

re juju#635
SimoneDutto added a commit to SimoneDutto/terraform-provider-juju that referenced this issue Jan 22, 2025
…harms

This PR adds support to update the base in application charms by requiring a replace in case of a
machine charm, and perform the upgrade in case of a k8s charm.

re juju#635
SimoneDutto added a commit to SimoneDutto/terraform-provider-juju that referenced this issue Jan 22, 2025
…harms

This PR adds support to update the base in application charms by requiring a replace in case of a
machine charm, and perform the upgrade in case of a k8s charm.

re juju#635
SimoneDutto added a commit to SimoneDutto/terraform-provider-juju that referenced this issue Jan 23, 2025
…harms

This PR adds support to update the base in application charms by requiring a replace in case of a
machine charm, and perform the upgrade in case of a k8s charm.

We add the model_type computed field on the application schema, and we
use it to make a decision in the planmodifier RequiresReplaceIf.

re juju#635
SimoneDutto added a commit to SimoneDutto/terraform-provider-juju that referenced this issue Jan 23, 2025
…harms

This PR adds support to update the base in application charms by requiring a replace in case of a
machine charm, and perform the upgrade in case of a k8s charm.

We add the model_type computed field on the application schema, and we
use it to make a decision in the planmodifier RequiresReplaceIf.

re juju#635
SimoneDutto added a commit to SimoneDutto/terraform-provider-juju that referenced this issue Jan 23, 2025
…harms

This PR adds support to update the base in application charms by requiring a replace in case of a
machine charm, and perform the upgrade in case of a k8s charm.

We add the model_type computed field on the application schema, and we
use it to make a decision in the planmodifier RequiresReplaceIf.

re juju#635
SimoneDutto added a commit to SimoneDutto/terraform-provider-juju that referenced this issue Jan 29, 2025
…harms

This PR adds support to update the base in application charms by requiring a replace in case of a
machine charm, and perform the upgrade in case of a k8s charm.

We add the model_type computed field on the application schema, and we
use it to make a decision in the planmodifier RequiresReplaceIf.

re juju#635
SimoneDutto added a commit to SimoneDutto/terraform-provider-juju that referenced this issue Jan 29, 2025
…harms

This PR adds support to update the base in application charms by requiring a replace in case of a
machine charm, and perform the upgrade in case of a k8s charm.

We add the model_type computed field on the application schema, and we
use it to make a decision in the planmodifier RequiresReplaceIf.

re juju#635
jujubot added a commit that referenced this issue Jan 29, 2025
#652

## Description

This PR adds support to update the base in application charms by requiring a replace in case of a machine charm, and perform the upgrade in case of a k8s charm.

Fixes: re #635

## Type of change

- Add support to update `base` for application charms

## QA Steps

### LXD

```terraform
terraform {
 required_providers {
 juju = {
 version = "~> 0.15.0"
 source = "juju/juju"
 }
 }
}

provider "juju" {
 controller_addresses = "10.229.36.127:17070"

 username = "admin"
 password = <redacted>

 ca_certificate = file("ca.crt")
}

resource "juju_model" "this" {
 name = "test-model"
}

resource "juju_application" "this" {
 model = juju_model.this.name
 name = "test-app"
 charm {
 name = "ubuntu"
 base = "[email protected]"
 }
}
```

`terraform apply`
`juju status` and you should see base=22.04

Now update the base
```terraform
resource "juju_application" "this" {
 model = juju_model.this.name
 name = "test-app"
 charm {
 name = "ubuntu"
 base = "[email protected]"
 }
}
```
`terraform plan` and you should see `~ base = "[email protected]" -> "[email protected]" # forces replacement`
`terraform apply`
Now we have two scenarios:
- happy (maybe just in the tests): the changes go though and you now have your new charm with the updated charm.
- sad: terraform tries to recreate the application before it was destroyed and errors out. If you rerun it, you now have your updated charm.
`juju status` and you should see base=20.04


### Microk8s
```terraform
terraform {
 required_providers {
 juju = {
 version = "~> 0.15.0"
 source = "juju/juju"
 }
 }
}

provider "juju" {
 controller_addresses = "10.152.183.78:17070"

 username = "admin"
 password = "<redacted>"

 ca_certificate = file("ca.crt")
}

resource "juju_model" "this" {
 name = "test-model"
}

resource "juju_application" "this" {
 model = juju_model.this.name
 name = "test-app"
 charm {
 name = "coredns"
 base = "[email protected]"
 channel = "1.25/stable"
 }
}
```
`terraform apply`
`juju show-application test-app` -> check base ubuntu 22.04
Update plan
```terraform
resource "juju_application" "this" {
 model = juju_model.this.name
 name = "test-app"
 charm {
 name = "coredns"
 base = "[email protected]"
 channel = "1.25/stable"
 }
}
```
`terraform plan` -> check that the plan doesn't require replace.
`terraform apply`
`juju show-application test-app` -> check base ubuntu 20.04
@alesstimec
Copy link
Member

@hloeung a change by @SimoneDutto has landed - please test it and let us know if it meets your needs.

@hloeung
Copy link
Author

hloeung commented Jan 31, 2025

It's not released in 0.16.0. Any ideas how to test this before it being released?

@SimoneDutto
Copy link
Contributor

It's not released in 0.16.0. Any ideas how to test this before it being released?

Hello, you can follow this guide. Sections: Building The Provider and Using the Provider.
It helps you through installing dependencies, building and installing the terraform provider.
Or wait for the release candidate: here you can find the dates for it https://discourse.charmhub.io/t/release-planning-for-the-juju-terraform-provider-v0-17-0/16668#dates-to-be-aware-of-4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/application kind/bug indicates a bug in the project
Projects
None yet
Development

No branches or pull requests

4 participants