-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
r/vapp_container: Add vapp_container resource #566
Conversation
9405c9d
to
2d8450d
Compare
@bill-rich could this PR be cleaned up a bit? I see a bunch of my commits in there. Maybe rebase your current changes on master?
That should make things a lot clearer and may resolve merge conflicts as well. |
2d8450d
to
ade70fd
Compare
@vancluever Thanks! I missed that. Got it sorted now. |
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.
Hey @bill-rich! This looks mostly good. We should address these comments I think and then maybe I'll give a manual test a spin to see how it runs. Let me know!
// If the parent resource pool is a vApp, we need to create the VM using the | ||
// CreateChildVM vApp function instead of directly using SDRS recommendations. | ||
if sps.ResourcePool != nil { | ||
if vc, err := vappcontainer.FromID(client, sps.ResourcePool.Reference().Value); err == nil { |
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 logic assumes that the only error that we are ever going to receive from vappcontainer.FromID
will be ManagedObjectNotFound
, which has implications further down the stack. You will want to handle the error, possibly in a switch
:
vc, err := vappcontainer.FromID(client, sps.ResourcePool.Reference().Value)
switch {
case viapi.IsManagedObjectNotFoundError(err):
// pass
case nil:
// vApp container creation logic here
default:
return err
}
return err | ||
} | ||
|
||
func recommendAndApplySDRS( |
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.
Rather than deleting this function, I'd recommend taking the de-coupled logic that has been duplicated to other parts and just throwing that here. Then the rest of the places that reference recommendAndApplySDRS
that don't require a special path to address vApp containers don't need changes at all.
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.
The reason I did it this way was because I still need the recommendation in order to determine which datastore to use in the case where the VM is being created in a vApp. I didn't want to clutter up recommendAndApplySDRS with the vApp code. Does that make sense? Very possible I'm just overlooking something simple.
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.
I'm not saying to actually revert the de-coupling, but rather than removing the function altogether and then duplicating code a few places, just change recommendAndApplySDRS to:
func recommendAndApplySDRS(
client *govmomi.Client,
sps types.StoragePlacementSpec,
timeout time.Duration,
) (*object.VirtualMachine, error) {
placement, err := recommendSDRS(client, sps, time.Minute*time.Duration(timeout))
if err != nil {
return nil, err
}
return applySDRS(client, placement, time.Minute*time.Duration(timeout))
}
This way, you don't have to update the other places that this is being used (where you don't need the recommendation), such as #566 (comment), #566 (comment), or #566 (comment).
@@ -228,7 +250,11 @@ func CloneVM( | |||
Type: string(types.StoragePlacementSpecPlacementTypeClone), | |||
} | |||
|
|||
return recommendAndApplySDRS(client, sps, time.Minute*time.Duration(timeout)) |
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.
See comment on recommendAndApplySDRS
@@ -268,7 +294,11 @@ func ReconfigureVM( | |||
ConfigSpec: &spec, | |||
} | |||
|
|||
_, err = recommendAndApplySDRS(client, sps, provider.DefaultAPITimeout) |
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.
See comment on recommendAndApplySDRS
@@ -305,16 +335,16 @@ func RelocateVM( | |||
Type: string(types.StoragePlacementSpecPlacementTypeRelocate), | |||
} | |||
|
|||
_, err = recommendAndApplySDRS(client, sps, time.Minute*time.Duration(timeout)) |
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.
See comment on recommendAndApplySDRS
# vsphere\_vapp\_container | ||
|
||
The `vsphere_vApp_container` resource can be used to create and manage | ||
Virtual Appliances. |
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 is not accurate, correct? Eventually we might allow OVAs through it (which could allow for the deploy of multi-VM vApps), but currently it's just a container.
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.
It is not correct. Seems I got Virtual Appliance in my head when I was writing the docs. Thanks for catching that!
The `vsphere_vApp_container` resource can be used to create and manage | ||
Virtual Appliances. | ||
|
||
For more information on vSphere Virtual Appliances, see [this |
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.
Terminology also here. Might be worth it to scan the doc for all reference of "Virtual Appliance" and just replace with "vApp".
or standalone host, or a resource pool itself. When moving a vApp container | ||
from one parent resource pool to another, both must share a common root | ||
resource pool or the move will fail. | ||
* `parent_folder_id` - (Optional) The [manage object ID][docs-about-morefs] of |
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.
s/manage/managed/
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.
👍
} | ||
} | ||
|
||
func testGetVAppContainer(s *terraform.State, resourceName string) (*object.VirtualApp, error) { |
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.
Can this be thrown into helper_test.go
just in case it's needed by other tests other than vApp container tests?
This is where most of the other test helper code is stored.
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.
Done
|
||
[ref-vsphere-vapp]: https://docs.vmware.com/en/VMware-vSphere/6.5/com.vmware.vsphere.vm_admin.doc/GUID-2A95EBB8-1779-40FA-B4FB-4D0845750879.html | ||
|
||
## Example Usage |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
Good idea. That probably isn't as obvious if you haven't been looking at it for hours.
Also fix err shadowing and function complexity
e630566
to
3cdb5b3
Compare
When a VM is part of a vApp, folder should be empty. Add support moving into resource pools.
3cdb5b3
to
04c0fbf
Compare
@@ -636,6 +652,11 @@ func resourceVSphereVirtualMachineCustomizeDiff(d *schema.ResourceDiff, meta int | |||
if err := virtualdevice.DiskDiffOperation(d, client); err != nil { | |||
return err | |||
} | |||
// When a VM is a member of a vApp container, it is no longer part of the VM | |||
// tree, and therefor cannot have its VM folder set. |
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.
s/therefor/therefore/
No description provided.