-
-
Notifications
You must be signed in to change notification settings - Fork 138
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
feat(vm): add support for pool update #505
Conversation
This commit removed the ForceNew flag from the VM resource's `pool_id` argument and implements pool update: * if the VM was part of a pool, it is removed from it, * if the new `pool_id` value is non-empty, the VM is added to that new pool.
* This commit fixes a linter error that somehow doesn't manifest unless some other, unrelated changes trigger it (see bpg#501 and bpg#505). * In addition it fixes a similar issue that had so far gone undetected by the linter. * Refactored the code in question into a function, since it was mostly duplicated. * Simplified a pair of conditionals that had the same code in both branches.
fix: linter error in ambush * This commit fixes a linter error that somehow doesn't manifest unless some other, unrelated changes trigger it (see #501 and #505). * In addition it fixes a similar issue that had so far gone undetected by the linter. * Refactored the code in question into a function, since it was mostly duplicated. * Simplified a pair of conditionals that had the same code in both branches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for the contribution!
LGTM!
@@ -6,6 +6,8 @@ | |||
|
|||
package pools | |||
|
|||
import "github.com/bpg/terraform-provider-proxmox/internal/types" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh... I didn't realize this mistake that I've made before -- the proxmox
package (API client) is now dependent on the internal
package types 😞
You're also adding new API types and more dependencies between API and FWK types in #498.
This all won't work long term, as I think it will make sense to extract the API client into a separate repo (#423)
But I'll leave it as is for now, the "separation" refactoring can be done later.
@@ -4798,6 +4842,10 @@ func vmUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.D | |||
return diag.FromErr(e) | |||
} | |||
|
|||
if vmUpdatePool(ctx, d, api.Pool(), vmID) != nil { | |||
return diag.FromErr(e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this swallows the returned error value and uses error e
from the previous statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops, sorry. Thanks for the fix.
proxmox/pools/pool_types.go
Outdated
// If this is set to 1, VMs and datastores will be removed from the pool instead of added. | ||
Delete *types.CustomBool `json:"delete,omitempty" url:"delete,omitempty,int"` | ||
// The list of virtual machines to add or delete. | ||
VMs *[]string `json:"vms,omitempty" url:"vms,omitempty,comma"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd need a custom JSON serialization to a comma-separated list, though it works now as there is only a single VM ID in the use case.
This commit removed the
ForceNew
flag from the VM resource'spool_id
argument and implements pool update:pool_id
value is non-empty, the VM is added to that new pool.It triggers the same linter problem as my other pull request, the same solution would apply.
Contributor's Note
Please mark the following items with an [x] if they apply to your PR.
Leave the [ ] if they are not applicable, or if you have not completed the item.
/docs
for any user-facing features or additions./examples
for any new or updated resources / data sources.make examples
to verify that the change works as expected.Community Note