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

juju_application.mysql must be replaced: fails with application already exists #521

Open
hemanthnakkina opened this issue Jul 11, 2024 · 1 comment
Assignees
Labels
area/application hint/main going on main branch

Comments

@hemanthnakkina
Copy link
Contributor

hemanthnakkina commented Jul 11, 2024

Description

juju + microk8s environment

Applied a terraform plan with storage_directive. The terraform is applied fine.
Change the size of storage_directive and reapply the plan.

The application is removed as expected but not recreated back.
Terraform plan failed with error application already exists

Urgency

Casually reporting

Terraform Juju Provider version

0.13.0-rc1

Terraform version

1.9.1

Juju version

3.4.2

Terraform Configuration(s)

terraform {  
  required_providers {
    juju = {
      source  = "registry.terraform.io/juju/juju"
      version = "0.13.0"
    }
  }
}

provider "juju" {}

resource "juju_model" "sunbeam" {
  name = var.model

  cloud {
    name   = var.cloud
    region = "localhost"
  }

  config = var.config
}

resource "juju_application" "mysql" {
  name  = "mysql"
  trust = true
  model = juju_model.sunbeam.name

  charm {
    name    = "mysql-k8s"
    channel = "8.0/stable"
    base    = "[email protected]"
  }

  storage_directives = { database = "8G" }
}

variable "model" {
  description = "Name of Juju model to use for deployment"
  default     = "sunbeam"
}

variable "cloud" {
  description = "Name of K8S cloud to use for deployment"
  default     = "microk8s"
}

variable "config" {
  description = "Set configuration on model"
  default     = { "workload-storage" : "microk8s-hostpath" }
}

Reproduce / Test

terraform init
terraform apply -auto-approve

Change the "storage_directives = { database = "8G" }" to "storage_directives = { database = "5G" }" in terraform plan

terraform apply -auto-approve

Debug/Panic Output

juju_model.sunbeam: Refreshing state... [id=332bd1c6-639f-42cd-8037-385c1cf515f5]
juju_application.mysql: Refreshing state... [id=sunbeam:mysql]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # juju_application.mysql must be replaced
-/+ resource "juju_application" "mysql" {
      ~ constraints        = "arch=amd64" -> (known after apply)
      ~ id                 = "sunbeam:mysql" -> (known after apply)
        name               = "mysql"
      ~ placement          = null -> (known after apply)
      + principal          = (known after apply)
      ~ storage            = [
          - {
              - count = 1 -> null
              - label = "database" -> null
              - pool  = "kubernetes" -> null
              - size  = "8.2G" -> null
            },
        ] -> (known after apply)
      ~ storage_directives = { # forces replacement
          ~ "database" = "8G" -> "5G"
        }
        # (3 unchanged attributes hidden)

      ~ charm {
            name     = "mysql-k8s"
          ~ revision = 153 -> (known after apply)
          ~ series   = "jammy" -> (known after apply)
            # (2 unchanged attributes hidden)
        }
    }

Plan: 1 to add, 0 to change, 1 to destroy.
juju_application.mysql: Destroying... [id=sunbeam:mysql]
juju_application.mysql: Destruction complete after 0s
juju_application.mysql: Creating...
╷
│ Error: Client Error
│ 
│   with juju_application.mysql,
│   on main.tf line 23, in resource "juju_application" "mysql":
│   23: resource "juju_application" "mysql" {
│ 
│ Unable to create application, got error: cannot add application "mysql": application already exists

Notes & References

No response

@hmlanigan hmlanigan changed the title Not able to update storage_directive size juju_application.mysql must be replaced: fails with application already exists Jul 11, 2024
@hmlanigan hmlanigan self-assigned this Jul 11, 2024
@hmlanigan hmlanigan added this to the 0.13.0 milestone Jul 11, 2024
@hmlanigan hmlanigan added area/application hint/main going on main branch state/in-progress currently being worked on and removed hint/main going on main branch labels Jul 11, 2024
hmlanigan added a commit to hmlanigan/terraform-provider-juju that referenced this issue Jul 11, 2024
When destroying an application, wait for it to be destroyed before
returning. Issue juju#521 and maybe others. Otherwise terraform fails when
RequireReplace is set.
@hmlanigan hmlanigan added hint/main going on main branch and removed state/in-progress currently being worked on labels Jul 18, 2024
@hmlanigan hmlanigan removed this from the 0.13.0 milestone Jul 18, 2024
@hmlanigan
Copy link
Member

hmlanigan commented Jul 18, 2024

I started working on this has it's been a long standing issue. However it became a bigger change than we had time for to get into 0.13.0-rc2.

I believe if you try to run the plan again, the application will be created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/application hint/main going on main branch
Projects
None yet
Development

No branches or pull requests

2 participants