Skip to content

Import machine does not take into account placement and also differences in contstraint sizes #1149

Description

@skatsaounis

Description

When I am importing a machine with placement and constraints into juju_machine, the provider cannot detect the placement. As a result, it is proposing to recreate the machine because of that. In additions, if constraints have numbers for e.g., memory or disk, it fails to understand that the applied numbers are equal to those of my Terraform plan

Urgency

Casually reporting

Terraform Juju Provider version

1.3.1

Terraform version

1.14.8

Juju version

3.6.13

Terraform Configuration(s)

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

resource "juju_model" "name" {
  name = "kitsos"

  config = {
    "project" = "juju-model"
  }
}

resource "juju_machine" "name" {
  model_uuid  = juju_model.name.uuid
  base        = "ubuntu@24.04"
  name        = "demo-machine"
  constraints = "cores=1 mem=4G root-disk=20G root-disk-source=default virt-type=virtual-machine"
  placement   = "zone=ThinkPad-X1"
}

Reproduce / Test

juju add-machine "zone=ThinkPad-X1"  --constraints "cores=1 mem=4G root-disk=20G root-disk-source=default virt-type=virtual-machine"
terraform apply -target juju_model.name -auto-approve
terraform import juju_machine.name 34e818ac-29b5-4ce4-8c27-0cb2561c3472:0:demo-machine

Debug/Panic Output

terraform plan
juju_model.name: Refreshing state... [id=34e818ac-29b5-4ce4-8c27-0cb2561c3472]
juju_machine.name: Refreshing state... [id=34e818ac-29b5-4ce4-8c27-0cb2561c3472:0:demo-machine]

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_machine.name must be replaced
-/+ resource "juju_machine" "name" {
      ~ constraints = "cores=1 mem=4096M root-disk=20480M root-disk-source=default virt-type=virtual-machine" -> "cores=1 mem=4G root-disk=20G root-disk-source=default virt-type=virtual-machine"
      ~ hostname    = "juju-1c3472-0" -> (known after apply)
      ~ id          = "34e818ac-29b5-4ce4-8c27-0cb2561c3472:0:demo-machine" -> (known after apply)
      ~ machine_id  = "0" -> (known after apply)
      ~ model_uuid  = "34e818ac-29b5-4ce4-8c27-0cb2561c3472" -> (known after apply) # forces replacement
        name        = "demo-machine"
      + placement   = "zone=ThinkPad-X1" # forces replacement
        # (1 unchanged attribute hidden)
    }

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

Notes & References

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions