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

Constraint changes causes replacements resulting in units being destroyed #632

Open
hloeung opened this issue Nov 18, 2024 · 0 comments
Open
Labels
kind/bug indicates a bug in the project state/untriaged untriaged bug report

Comments

@hloeung
Copy link

hloeung commented Nov 18, 2024

Description

Constraint changes or differences (see #344) causes units to be replaced and destroyed. This is scary for an environment hosting databases.

I can see use cases where we want to increase or scale up DB units. We do so by changing the constraints, adding new units, then cycling out the old.

Sadly, the current Juju Terraform provider sees constraint changes and causes replacements which means destroying units.

Urgency

Casually reporting

Terraform Juju Provider version

0.15.0

Terraform version

v1.7.2-dev

Juju version

3.5.3

Terraform Configuration(s)

locals {
  # Work around Juju `unexpected new value: .constraints: was cty.StringVal("... root-disk=20G"), but now cty.StringVal(" ... root-disk=20480M").`
  # https://github.com/juju/terraform-provider-juju/issues/344
  postgresql_disk_gigabytes       = var.disk_gigabytes * 1024
  postgresql_charm_constraints    = "arch=amd64 cores=${var.cores} mem=${var.mem_megabytes}M root-disk=${local.postgresql_disk_gigabytes}M"
  postgresql_root_disk_constraint = var.postgresql_use_local_storage ? " root-disk-source=local" : ""
}

resource "juju_application" "postgresql" {
  name  = "postgresql"
  model = var.juju_model_name
  trust = true

  charm {
    name     = "postgresql"
    channel  = var.postgresql_charm_channel
    revision = var.postgresql_charm_revision
    base     = var.postgresql_charm_base
  }

  expose {}

  units       = var.postgresql_charm_units
  constraints = "${local.postgresql_charm_constraints}${local.postgresql_root_disk_constraint}"
}

Reproduce / Test

terraform init & terraform apply

Update `postgresql_disk_gigabytes` to some other value

terraform apply

Debug/Panic Output

# module.postgresql-database.juju_application.postgresql must be replaced
-/+ resource "juju_application" "postgresql" {
      ~ constraints = "arch=amd64 cores=2 mem=4096M root-disk=20480M" -> "arch=amd64 cores=2 mem=4096M root-disk=30720M" # forces replacement
      ~ id          = "stg-is-dbaas-testing:postgresql" -> (known after apply)
        name        = "postgresql"
      ~ placement   = "5,6,7" -> (known after apply)
      + principal   = (known after apply)
      ~ storage     = [
          - {
              - count = 1 -> null
              - label = "pgdata-3" -> null
              - pool  = "rootfs" -> null
              - size  = "20G" -> null
            },
          - {
              - count = 1 -> null
              - label = "pgdata-4" -> null
              - pool  = "rootfs" -> null
              - size  = "20G" -> null
            },
          - {
              - count = 1 -> null
              - label = "pgdata-5" -> null
              - pool  = "rootfs" -> null
              - size  = "20G" -> null
            },
        ] -> (known after apply)
        # (3 unchanged attributes hidden)

      ~ charm {
            name     = "postgresql"
          ~ series   = "jammy" -> (known after apply)
            # (3 unchanged attributes hidden)
        }

        # (1 unchanged block hidden)
    }

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


### Notes & References

_No response_
@hloeung hloeung added kind/bug indicates a bug in the project state/untriaged untriaged bug report labels Nov 18, 2024
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 state/untriaged untriaged bug report
Projects
None yet
Development

No branches or pull requests

1 participant