OpenNebula / terraform-provider-opennebula

Terraform provider for OpenNebula
https://www.terraform.io/docs/providers/opennebula/
Mozilla Public License 2.0
63 stars 52 forks source link

F-447 F-448: externalize quotas as resources #449

Closed treywelsh closed 1 year ago

treywelsh commented 1 year ago

Community Note

Description

Until now quotas are only a schema part (via some nested typeset and typelists) of the users ans group resources, this PR externalize quotas in their own resource. One resource for the users, another for the groups.

After some tests it's possible to define several quota resource for a single user or a signle group.

References

Close #447 Close #448

New or Affected Resource(s)

Checklist

treywelsh commented 1 year ago

For this first shot this PR didn't followed the schema shown in the issues #447 and #448 This works like this:

resource "opennebula_user" "example" {
  name          = "test"
  password      = "test2"
  auth_driver   = "core"

  lifecycle {
    ignore_changes = [
      "quotas"
    ]
  }
}

resource "opennebula_user_quotas" "test" {
    user_id = opennebula_user.example.id
    datastore {
      id     = 1
      images = 5
      size   = 10000
    }
    vm{
      cpu            = 3
      running_cpu    = 3
      memory         = 2048
      running_memory = 2048
    }
    network {
      id     = 10
      leases = 6
    }
    network {
      id     = 11
      leases = 4
    }
    image {
      id          = 8
      running_vms = 1
    }
    image {
      id          = 9
      running_vms = 1
    }
}

It was easier to migrate as a resource, it's easier to import via terraform import and overall it require a bit less of text. I'm able to split the quotas resource to only apply a quota to a given type of resource (image or network or datastore or VM) but it seems to me that we'll at least loose the capability to easily import the quotas (I'll need to find a way to make the provider read partially the quotas).

frousselet commented 1 year ago

Understood. I'll test, but are we not going to fall back into the same situation? It might solve the zone issue, but not the drift one.

and detects drift when creating resources without defining a quota

treywelsh commented 1 year ago

I'm not sure I got was the drift problem was, or maybe I forgot, so ok blame on me. Not sure the drift problem is still there so If we/you can test it again it would be nice.

By the way I need to check via #458 if I can't improve the quota import because I said it was a problem in my previous comment

treywelsh commented 1 year ago

I'm finally able to propose something close to the schema of the issue:

resource "opennebula_user" "example" {
  name          = "test"
  password      = "test2"
  auth_driver   = "core"

  lifecycle {
    ignore_changes = [
      "quotas"
    ]
  }
}

resource "opennebula_user_quotas" "example_datastore" {
  user_id = opennebula_user.example.id
  datastore {
    id     = 1
    images = 3
    size   = 10000
  }
}

resource "opennebula_user_quotas" "example_image" {
  user_id = opennebula_user.example.id
  image {
    id          = 8
    running_vms = 1
  }
}

resource "opennebula_user_quotas" "example_vm" {
  user_id = opennebula_user.example.id
    vm{
      cpu            = 3
      running_cpu    = 3
      memory         = 2048
      running_memory = 2048
    }
}

resource "opennebula_user_quotas" "example_net" {
  user_id = opennebula_user.example.id
  network {
    id     = 10
    leases = 6
  }
  network {
    id     = 11
    leases = 4
  }
}

Tradeoffs: There's a ConflictWith behavior between the sections of the quotas so we must split the quotas across several resources. And in order to import a resource we need to do something like:

terraform import opennebula_group_quotas.example 123:image

Where 123 is the group ID, and image is the type of the quota we are trying to import. All these last changes were added in the last commit of my branch so it's easy to test both variants and choose

github-actions[bot] commented 1 year ago

This pull request is stale because it has been open for 30 days with no activity and it is not in a milestone. Remove 'status: stale' label or comment, or this will be closed in 5 days.