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

application placement to any machine/container/kvm doesn't work if machine is not started #506

Open
arif-ali opened this issue Jun 27, 2024 · 3 comments
Labels
area/machine hint/main going on main branch kind/bug indicates a bug in the project

Comments

@arif-ali
Copy link

Description

When you create tf plan with physical + lxd + application, then this will not apply in the first instance.

We now have to wait for the lxd to be active for the application to be added.

This was working with juju 2.9

Urgency

Annoying bug in our test suite

Terraform Juju Provider version

0.12.0

Terraform version

1.9.0

Juju version

3.4.3

Terraform Configuration(s)

resource "juju_machine" "machine" {
  model       = "test"
}

resource "juju_machine" "cinder" {
  model       = "test"
  placement   = "${join(":",["lxd",juju_machine.machine.machine_id])}"
  constraints = "spaces=oam"
}

resource "juju_application" "cinder" {
  name = "cinder"

  model = "test"

  charm {
    name     = "cinder"
    channel  = "yoga/stable"
    base     = "[email protected]"
  }

  units = 1

  placement = juju_machine.cinder.machine_id

  endpoint_bindings = [{
    space    = "oam"
  },{
    endpoint = "public"
    space    = "oam"
  },{
    endpoint = "admin"
    space    = "oam"
  },{
    endpoint = "internal"
    space    = "oam"
  },{
    endpoint = "shared-db"
    space    = "oam"
  }]

}

Reproduce / Test

* Create a fresh model called `test`
* Then run terraform apply with the above plan, and we will get the following issue


juju_machine.machine: Creating...
juju_machine.machine: Creation complete after 5s [id=test:0:machine-0]
juju_machine.cinder: Creating...
juju_machine.cinder: Creation complete after 5s [id=test:0/lxd/0:machine-0/lxd/0]
juju_application.cinder: Creating...
╷
│ Error: Client Error
│ 
│   with juju_application.cinder,
│   on 05-cinder.tf line 11, in resource "juju_application" "cinder":
│   11: resource "juju_application" "cinder" {
│ 
│ Unable to create application, got error: machine "0/lxd/0" not started, please retry when started
╵


### Debug/Panic Output

_No response_

### Notes & References

_No response_
@arif-ali arif-ali added the kind/bug indicates a bug in the project label Jun 27, 2024
@arif-ali arif-ali changed the title application placement to LXD container doesn't work if machine is not started application placement to any machine/container/kvm doesn't work if machine is not started Jun 28, 2024
@arif-ali
Copy link
Author

arif-ali commented Jun 28, 2024

after doing some other work, this is not just an LXD issue, but any machine. My simple plan below had to be run in 2 stages

resource "juju_model" "microk8s" {
  name = var.mk8s-model-name

  cloud {
    name = var.cloud
  }

  config = {
    apt-mirror = "http://${var.apt_mirror}/archive.ubuntu.com/ubuntu"
    lxd-snap-channel = var.lxd-snap-channel

    container-image-metadata-url = "http://${var.apt_mirror}/lxd/"
    container-image-stream = "released"

    agent-metadata-url = "http://${var.apt_mirror}/juju/tools/"
    agent-stream = "released"
  }
}


resource "juju_machine" "mk8s" {
  for_each    = {
  for index, machine in var.mk8s-machines:
  machine.machine_id => machine
  }
#  model       = var.mk8s-model-name
  model       = juju_model.microk8s.name
  name        = each.value.machine_id
  constraints = each.value.constraints
  #base        = each.value.base
}

resource "juju_application" "microk8s" {
  name = "microk8s"

  #model = var.mk8s-model-name
  model = juju_model.microk8s.name

  charm {
    name     = "microk8s"
    channel  = "1.28/stable"
    base     = "[email protected]"
  }

  units = 4

  placement = "${join(",", sort([
    for res in juju_machine.mk8s :
        res.machine_id
  ]))}"

  config = {
  }
}

The error below

juju_model.microk8s: Creating...
juju_model.microk8s: Creation complete after 2s [id=9c93b2ac-8cbb-4eba-8d94-aeaec1f1d1d1]
juju_machine.mk8s["2002"]: Creating...
juju_machine.mk8s["2000"]: Creating...
juju_machine.mk8s["2003"]: Creating...
juju_machine.mk8s["2001"]: Creating...
juju_machine.mk8s["2001"]: Creation complete after 8s [id=microk8s:0:2001]
juju_machine.mk8s["2002"]: Creation complete after 8s [id=microk8s:1:2002]
juju_machine.mk8s["2000"]: Still creating... [10s elapsed]
juju_machine.mk8s["2003"]: Still creating... [10s elapsed]
juju_machine.mk8s["2000"]: Creation complete after 13s [id=microk8s:2:2000]
juju_machine.mk8s["2003"]: Creation complete after 20s [id=microk8s:3:2003]
juju_application.microk8s: Creating...
╷
│ Error: Client Error
│ 
│   with juju_application.microk8s,
│   on 20-microk8s.tf line 33, in resource "juju_application" "microk8s":
│   33: resource "juju_application" "microk8s" {
│ 
│ Unable to create application, got error: machine "0" not started, please retry when started
╵

@hmlanigan
Copy link
Member

This is juju behavior and not specific to the terraform provider. To deploy an application juju must know the operating system to use. If an actual machine is used in deployment, the operating system of the machine must be known. It is used to deploy the application, or to validate against the operating system specified for the application.

The fix is for the terraform provider to wait for the machine to finish provisioning before returning from creating the machine resource. Thus delaying the application deployment.

@hmlanigan
Copy link
Member

See #116 for additional info

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

No branches or pull requests

2 participants