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

feat(vm): add support for pool update #505

Merged
merged 3 commits into from
Aug 19, 2023
Merged

Conversation

tseeker
Copy link
Contributor

@tseeker tseeker commented Aug 18, 2023

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.

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.

  • I have added / updated documentation in /docs for any user-facing features or additions.
  • I have added / updated templates in /examples for any new or updated resources / data sources.
  • I have ran make examples to verify that the change works as expected.

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

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.
tseeker added a commit to tseeker/terraform-provider-proxmox that referenced this pull request Aug 18, 2023
  * 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.
@tseeker tseeker mentioned this pull request Aug 18, 2023
3 tasks
bpg pushed a commit that referenced this pull request Aug 19, 2023
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.
Copy link
Owner

@bpg bpg left a 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"
Copy link
Owner

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)
Copy link
Owner

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

Copy link
Contributor Author

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.

// 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"`
Copy link
Owner

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.

@bpg bpg merged commit e6c15ec into bpg:main Aug 19, 2023
12 checks passed
@ghost ghost mentioned this pull request Aug 19, 2023
@bpg bpg changed the title feat(vm): pool update support feat(vm): add support for pool update Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants