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

Storage Policy ID / Datastore is not applied to VM #991

Closed
Satak opened this issue Mar 11, 2020 · 6 comments
Closed

Storage Policy ID / Datastore is not applied to VM #991

Satak opened this issue Mar 11, 2020 · 6 comments
Labels
acknowledged Status: Issue or Pull Request Acknowledged bug Type: Bug size/m Relative Sizing: Medium

Comments

@Satak
Copy link

Satak commented Mar 11, 2020

Terraform Version

0.12.23

vSphere Provider Version

1.17.0

Affected Resource(s)

  • vsphere_virtual_machine

Terraform Configuration Files

provider "vsphere" {
  user                 = var.username
  password             = var.password
  vsphere_server       = var.server
  allow_unverified_ssl = true
}

data "vsphere_datacenter" "dc" {
  name = "datacenterName"
}

data "vsphere_resource_pool" "pool" {
  name          = "poolName"
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_network" "network" {
  name          = "networkName"
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_content_library" "library" {
  name = "libraryName"
}

data "vsphere_content_library_item" "item" {
  name       = "templateName"
  library_id = data.vsphere_content_library.library.id
}

data "vsphere_storage_policy" "policy" {
  name = "policyName"
}

resource "vsphere_virtual_machine" "vm" {
  name              = var.vmName
  resource_pool_id  = data.vsphere_resource_pool.pool.id
  storage_policy_id = data.vsphere_storage_policy.policy.id

  num_cpus = 2
  memory   = 4096
  guest_id = "windows9Server64Guest"

  network_interface {
    network_id = data.vsphere_network.network.id
  }

  disk {
    storage_policy_id = data.vsphere_storage_policy.policy.id
    label             = "disk0"
    size              = 120
  }

  clone {
    template_uuid = data.vsphere_content_library_item.item.id
    customize {
      windows_options {
        computer_name  = var.vmName
        admin_password = var.vmPassword
        workgroup      = "WORKGROUP"
        auto_logon     = true
      }
      network_interface {
        ipv4_address = var.ipAddress
        ipv4_netmask = 24
      }
      ipv4_gateway = var.gateway
    }
  }
}

Error

Error: ServerFaultCode: The object 'vim.Datastore:' has already been deleted or has not been completely created

  on main.tf line 55, in resource "vsphere_virtual_machine" "vm":
  55: resource "vsphere_virtual_machine" "vm" { 

Expected Behavior

Terraform should create VM with disk in a datastore attached to the storage policy

Actual Behavior

Terraform creates VM with disk that is in a datastore where the template is. storage_policy_id doesn't affect at all to what datastore the disk is put. Even when I hardcode the storage policy id to the module level storage_policy_id parameter it is not working.

Noticed that the policy is set to VM and it's just the datastore that is not picked correctly from the policy.

We are using templates from the vCenter folder and not content library templates.

Steps to Reproduce

  1. Create storage policy in vCenter and add datastore to it
  2. Create main.tf file where you clone a VM template with storage_policy_id
  3. VM is created but not to a datastore where you have set your policy
@Satak
Copy link
Author

Satak commented Mar 17, 2020

This is pending support for content libraries which probably solves this issue:
#985

@aareet aareet added the bug Type: Bug label Mar 17, 2020
@Satak
Copy link
Author

Satak commented Apr 2, 2020

@bill-rich Now the vSphere supports storage policies and content library items. Problem is that one must provide datastore_id or datastore_cluster_id stated in the documentation:

NOTE: One of datastore_id or datastore_cluster_id must be specified.

We provisioning VM from the content library item with storage_policy_id that automatically assigns a correct datastore based on the storage policy rule. So we don't want to send any datastore and just let the policy assign the datastore, is this currently possible? Any thoughts?

@Satak
Copy link
Author

Satak commented Apr 2, 2020

Error when not setting any datastore_id and trying to just use storage_policy_id:

Error: ServerFaultCode: The object 'vim.Datastore:' has already been deleted or has not been completely created

  on main.tf line 55, in resource "vsphere_virtual_machine" "vm":
  55: resource "vsphere_virtual_machine" "vm" { 

@Satak
Copy link
Author

Satak commented Apr 8, 2020

@bill-rich just noticed that if you use content library item based VM provisioning (template uuid) your datastore_id that you provide to the resource is overwritten by the datastore that the template has. Is this intentional?

Other bug is that with the version 1.17.1 guest_id value is overwritten to empty string if you use content library item based provisioning and then your customization block will fail. This was working before. You should put an if condition before you overwrite user input variables to empty strings.

Bottom line is that currently provisioning with content library item with datastore and guest_id is broken.

@bill-rich bill-rich added acknowledged Status: Issue or Pull Request Acknowledged size/m Relative Sizing: Medium labels Aug 5, 2020
@bill-rich
Copy link
Contributor

This should be fixed in #1183. Please try again after the next provider release and let me know if you're still experiencing this issue.

@ghost
Copy link

ghost commented Oct 10, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Oct 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
acknowledged Status: Issue or Pull Request Acknowledged bug Type: Bug size/m Relative Sizing: Medium
Projects
None yet
Development

No branches or pull requests

3 participants