juju / terraform-provider-juju

A Terraform provider for Juju
Apache License 2.0
21 stars 43 forks source link

Application upgrade when integration removal is required fails with `Client Error` #566

Open dariofaccin opened 2 months ago

dariofaccin commented 2 months ago

Description

The upgrade of some of our charms (sdcore-amf-k8s, sdcore-ms-k8s, sdcore-pcf-k8s) requires a relation to be removed before refreshing the charm. The provider correctly tries to remove it before trying the refresh, however it does not wait for the relation to be completely removed, causing the following error:

╷
│ Error: Client Error
│ 
│   with module.amf.juju_application.amf,
│   on .terraform/modules/amf/terraform/main.tf line 4, in resource "juju_application" "amf":
│    4: resource "juju_application" "amf" {
│ 
│ Unable to update application resource, got error: updating charm config: cannot upgrade application "amf" to
│ charm "ch:amd64/jammy/sdcore-amf-k8s-669": would break relation "amf:database mongodb:database"
╵
╷
│ Error: Client Error
│ 
│   with module.nms.juju_application.sdcore-nms-k8s,
│   on .terraform/modules/nms/terraform/main.tf line 4, in resource "juju_application" "sdcore-nms-k8s":
│    4: resource "juju_application" "sdcore-nms-k8s" {
│ 
│ Unable to update application resource, got error: updating charm config: cannot upgrade application "nms" to
│ charm "ch:amd64/jammy/sdcore-nms-k8s-548": would break relation "nms:sdcore-management
│ webui:sdcore-management"
╵
╷
│ Error: Client Error
│ 
│   with module.pcf.juju_application.pcf,
│   on .terraform/modules/pcf/terraform/main.tf line 4, in resource "juju_application" "pcf":
│    4: resource "juju_application" "pcf" {
│ 
│ Unable to update application resource, got error: updating charm config: cannot upgrade application "pcf" to
│ charm "ch:amd64/jammy/sdcore-pcf-k8s-485": would break relation "pcf:database mongodb:database"
╵

Urgency

Blocker for our release

Terraform Juju Provider version

0.12.0

Terraform version

v1.9.5

Juju version

3.5.1

Terraform Configuration(s)

No response

Reproduce / Test

1. git clone git@github.com:canonical/terraform-juju-sdcore-k8s.git
2. cd terraform-juju-sdcore-k8s/modules/sdcore-k8s
3. git checkout v1.4
4. terraform init && terraform apply
5. git checkout main
5. terraform init && terraform apply

Debug/Panic Output

No response

Notes & References

No response

Aflynn50 commented 2 months ago

Hey @dariofaccin, could you please add a terraform plan to this report with a minimal reproducer?

dariofaccin commented 2 months ago

@Aflynn50 the steps to reproduce the issue involve first deploying a plan (using a version X of the charms) and then refreshing the plan with a new version Y of the charms. This particular deployment involves different modules across multiple repositories. I could create a custom plan with the bare minimum if needed. Let me know, thanks.