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

Add Placement parameter #378

Merged
merged 1 commit into from
Mar 7, 2024
Merged

Add Placement parameter #378

merged 1 commit into from
Mar 7, 2024

Conversation

amandahla
Copy link
Contributor

@amandahla amandahla commented Jan 9, 2024

Description

The machine resource does not support creating machines in LXD/KVM like the following command does:

juju add-machine kvm:3

This PR adds a placement parameter to provide this option.

Fixes: #347

Type of change

  • Change existing resource
  • Change in tests (one or several tests have been changed)
  • Requires a documentation update

Environment

  • Juju controller version:

  • Terraform version:

QA steps

Manual QA steps should be done to test this PR.

terraform {
  required_providers {
    juju = {
      version = "~> 0.7.0"
      source  = "registry.terraform.io/juju/juju"
    }
  }
}

provider "juju" {}

resource "juju_model" "development" {
  name = "development"
}

resource "juju_machine" "this_machine" {
  model     = juju_model.development.name
  name      = "this_machine"
  placement = "lxd"
}

resource "juju_machine" "this_machine_1" {
  model     = juju_model.development.name
  name      = "this_machine_1"
  placement = "lxd:0"
}

Expected

$ juju status
Model        Controller  Cloud/Region         Version  SLA          Timestamp
development  lxd-local   localhost/localhost  2.9.45   unsupported  18:27:04-03:00

Machine  State    Address       Inst id              Series  AZ  Message
0        started  10.42.91.156  juju-317769-4        focal       Running
0/lxd/0  started                juju-317769-4-lxd-0  focal       Container started
0/lxd/1  started                juju-317769-4-lxd-1  focal       Container started

Additional notes

Approved schema in:
#381

@amandahla amandahla marked this pull request as draft January 9, 2024 18:40
@hmlanigan hmlanigan added this to the 0.11.0 milestone Jan 30, 2024
@hmlanigan
Copy link
Member

@amandahla run make docs and add the updated docs to your PR to resolve the failed workflow.

@amandahla amandahla marked this pull request as ready for review February 8, 2024 20:32
@amandahla amandahla changed the title WIP - Add Placement parameter Add Placement parameter Feb 8, 2024
Copy link
Member

@hmlanigan hmlanigan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to start. QA went well with one oddity, including import.

Please rebase this PR and resolve the conflicts. It also needs an acceptance test for this change in resource_machine_test.go

QA oddity. I haven't had a chance to dig. But how this happens isn't obvious:

With this plan part:

resource "juju_model" "testmodel" {
  name = "machinetest"
}

resource "juju_machine" "my-machine-three" {
  model = juju_model.testmodel.name
  placement = ":failme"
}

I got:

juju_machine.my-machine-three: Creating...
╷
│ Error: Client Error
│
│   with juju_machine.my-machine-three,
│   on heather.tf line 39, in resource "juju_machine" "my-machine-three":
│   39: resource "juju_machine" "my-machine-three" {
│
│ Unable to create machine, got error: invalid model name "model-uuid"
╵

docs/resources/machine.md Outdated Show resolved Hide resolved
internal/provider/resource_machine.go Outdated Show resolved Hide resolved
@hmlanigan
Copy link
Member

hmlanigan commented Feb 9, 2024

@amandahla please do not use merge commits. It's preferable to use git pull --rebase instead. Merge commits interfere with the commit history once the PR lands.

@amandahla
Copy link
Contributor Author

invalid model name

This error seems to come from here.

Reading better now, from what I understood, I need to pass the model-uuid if there is no scope in the directive. Changed and testing now.

@amandahla
Copy link
Contributor Author

Now the error makes more sense:

$ terraform apply
juju_model.development: Refreshing state... [id=51f29c40-4f7e-4c03-8d1a-d10f2b433f01]
juju_machine.this_machine_1: Refreshing state... [id=development:0/lxd/1:this_machine_1]
juju_machine.this_machine: Refreshing state... [id=development:0/lxd/0:this_machine]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # juju_machine.this_machine_2 will be created
  + resource "juju_machine" "this_machine_2" {
      + base       = (known after apply)
      + id         = (known after apply)
      + machine_id = (known after apply)
      + model      = "development"
      + name       = "this_machine_1"
      + placement  = ":fail"
      + series     = (known after apply)
    }

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

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

juju_machine.this_machine_2: Creating...
╷
│ Error: Client Error
│ 
│   with juju_machine.this_machine_2,
│   on main.tf line 28, in resource "juju_machine" "this_machine_2":
│   28: resource "juju_machine" "this_machine_2" {
│ 
│ Unable to create machine, got error: cannot add a new machine: availability zone ":fail" not valid

@amandahla
Copy link
Contributor Author

Fixed the merge/rebase mess.

@amandahla amandahla force-pushed the iss347 branch 3 times, most recently from 6a89040 to 0a9fbf8 Compare March 6, 2024 17:34
Copy link
Member

@hmlanigan hmlanigan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for your contribution.

@hmlanigan hmlanigan merged commit 4670efd into juju:main Mar 7, 2024
20 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add kvm or lxd machines through juju_machine resource
2 participants