terraform-provider-vsphere icon indicating copy to clipboard operation
terraform-provider-vsphere copied to clipboard

Cannot use datastore_cluster_id with content library item

Open melck opened this issue 1 year ago • 11 comments

Community Guidelines

  • [X] I have read and agree to the HashiCorp Community Guidelines .
  • [X] Vote on this issue by adding a 👍 reaction to the original issue initial description to help the maintainers prioritize.
  • [X] Do not leave "+1" or other comments that do not add relevant information or questions.
  • [X] If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Terraform

1.6.3

Terraform Provider

2.5.1

VMware vSphere

7.0

Description

I saw the outcome of issue #1087 and VMWare KB.

I think this is an obstacle to the adoption of content libraries. We can deploy with storage policy but it really adds complexity.

Isn't there something we can do? Like for example creating a virtual machine with datastore cluster defined and in the clone section an ovf_storage_map which would use the storage policy for the clone only ?

Affected Resources or Data Sources

resource/vsphere_virtual_machine

Terraform Configuration

terraform {
  required_version = ">= 1.0"

  required_providers {
    vsphere = {
      source  = "hashicorp/vsphere"
      version = ">= 2.5"
    }
  }
}


provider "vsphere" {
  vsphere_server       = var.vsphere_server
  user                 = var.vsphere_user
  password             = var.vsphere_password
  allow_unverified_ssl = "true"
}
 
//Datacenter Name
data "vsphere_datacenter" "datacenter" {
  name = var.datacenter_name
}
 
 
//Datastore Cluster Name
data "vsphere_datastore_cluster" "datastore_cluster" {
  name          = var.datastore_cluster_name
  datacenter_id = data.vsphere_datacenter.datacenter.id
}
  
//Cluster Name within the Datastore to be used for provisioning
data "vsphere_compute_cluster" "cluster" {
  name          = var.cluster_name
  datacenter_id = data.vsphere_datacenter.datacenter.id
}
 
//Network to be used by the virtual machine
data "vsphere_network" "network" {
  name          = var.network_name
  datacenter_id = data.vsphere_datacenter.datacenter.id
}
 
//Setting content Library name
data "vsphere_content_library" "library" {
  name = var.content_library_name
}
 
//Setting template name to be used
data "vsphere_content_library_item" "item" {
  name       = var.vm_name
  library_id = data.vsphere_content_library.library.id
}
 
//Creating VM resource from template and applying customization
resource "vsphere_virtual_machine" "vm" {
  name                 = var.vm_name
  resource_pool_id     = data.vsphere_compute_cluster.cluster.resource_pool_id
  datastore_cluster_id = data.vsphere_datastore_cluster.datastore_cluster.id
  
  //resource Configurations
  num_cpus = 1
  memory   = 2048

  clone {
    template_uuid = data.vsphere_content_library_item.item.id
  }
 
  //Adding Network interface to the vm
  network_interface {
    network_id = data.vsphere_network.network.id
  }

  disk {
    label            = "disk0"
    size             = "20"
    eagerly_scrub    = "false"
    thin_provisioned = "true"
  }
}

Debug Output

None

Panic Output

No response

Expected Behavior

Should create virtual machine in datastore cluster or at least clone vm into a datastore inside the datastore cluster and then move it to datastore cluster.

Actual Behavior

Error: Cannot user datastore_cluster_id with content library source

Steps to Reproduce

  • Create a content library
  • Create a content item
  • Create a virutal machine from the item on a datastore cluster

Environment Details

No response

Screenshots

No response

References

No response

melck avatar Nov 07 '23 17:11 melck

Hello, melck! 🖐

Thank you for submitting an issue for this provider. The issue will now enter into the issue lifecycle.

If you want to contribute to this project, please review the contributing guidelines and information on submitting pull requests.

github-actions[bot] avatar Nov 07 '23 17:11 github-actions[bot]

Hi , There is an active check in the code to prevent this case d.Id() == "": if contentlibrary.IsContentLibraryItem(meta.(*Client).restClient, d.Get("clone.0.template_uuid").(string)) { if _, ok := d.GetOk("datastore_cluster_id"); ok { return fmt.Errorf("Cannot use datastore_cluster_id with Content Library source") } } else if err := vmworkflow.ValidateVirtualMachineClone(d, client); err != nil { return err } fallthrough default: We have tested the PowerShell cli and vSpher UI, which is no longer blocking the use of data clusters. Please remove the validation in the provider code.

tlitovsk avatar Nov 12 '23 23:11 tlitovsk

We'll need to evaluate and test to ensure there's not a blocking issue with govmomi first. Milestone added.

tenthirtyam avatar Nov 12 '23 23:11 tenthirtyam

Running into the same issue, digging into it looks like a limitation due to https://kb.vmware.com/s/article/91103

From looking at how other communities (Ansible) handle this limitation, they have some additional logic to call StorageResourceManager RecommendDatastores.

https://github.com/ansible-collections/community.vmware/blob/22aa24102f3cf7367bc5d8ddb222b4ed478246e4/plugins/modules/vmware_content_deploy_ovf_template.py#L210-L217

https://github.com/ansible-collections/community.vmware/blob/main/plugins/module_utils/vmware.py#L1688-L1728

Even govc vm.clone looks like it calls StorageResourceManager RecommendDatastores.

https://github.com/vmware/govmomi/blob/39e6c495d8138885e6a6c58a563d1c11d47eefb5/govc/vm/clone.go#L376-L391

@tenthirtyam is it possible for y'all to create a terraform datasource called vsphere_recommended_datastores (or whatever name you choose) with the input of a datastore cluster and an output of a datastore name?

That way you don't have to change any existing functionality

bFekete avatar Nov 13 '23 07:11 bFekete

@bFekete the API and the web ui are handling this now. It is currently only blocked by the check in the provider.

tlitovsk avatar Nov 13 '23 07:11 tlitovsk

@bFekete the API and the web ui are handling this now. It is currently only blocked by the check in the provider.

@tlitovsk I couldn't find it in their API docs.

The provider will require additional changes outside of removing the check, which is why I'm suggesting a new terraform datasource and keeping that check.

bFekete avatar Nov 13 '23 08:11 bFekete

There's already some storage recommendation logic within this provider. Just made some small modifications on #2061. Tested.

bFekete avatar Nov 13 '23 12:11 bFekete

@bFekete What version of vsphere did you to test ?

melck avatar Nov 13 '23 13:11 melck

@bFekete What version of vsphere did you to test ?

v7.0

bFekete avatar Nov 13 '23 16:11 bFekete

Are we still good to merge #2061 for 2.7.0 release ?

melck avatar Dec 18 '23 13:12 melck

Hi @tenthirtyam . Can we still expect a merge of #2061 for v2.7.0?

FlorianLaunay avatar Feb 20 '24 14:02 FlorianLaunay

According to #2061, this fix is no longer planned for v2.8.0 :cry:

FlorianLaunay avatar Apr 29 '24 16:04 FlorianLaunay

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Jun 01 '24 02:06 github-actions[bot]