Skip to content
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

fix: r/vsphere_virtual_disk with lazy forces replacement #2033

Merged

Conversation

vasilsatanasov
Copy link
Contributor

Fixes #1824

Description

Issue addressed - when r/vsphere_virtual_disk.type is set as "lazy" as documented here:
https://registry.terraform.io/providers/hashicorp/vsphere/latest/docs/resources/virtual_disk#type i.e. Thick Provisioned Lazy Zeroed it is sent and received as "preallocated". The value is mapped when sent but not when received which causes disk recreaion when terraform apply is executed for the second time without changing the HCL config.

Fix applied - when virtual disk type is read from the backend the value is transformed to "lazy" if "preallocated" is received.

Testing done:
With HCL:

resource "vsphere_virtual_disk" "virtual_disk_test" {
  count              = 1
  datacenter         = data.vsphere_datacenter.datacenter.name
  datastore          = data.vsphere_datastore.datastore.name
  vmdk_path          = "/${var.VSPHERE_ESXI1}/test.vmdk"
  create_directories = true

  size               = 2
  type               = "lazy" # Thick Provision Lazy Zeroed (allocate then zero on first write)
}

executed terraform apply twice

Output from the second execution:

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Acceptance tests

  • Have you added an acceptance test for the functionality being added?
  • Have you run the acceptance tests on this branch?

Output from acceptance testing:

vasila@vasila2VDJN terraform-provider-vsphere % make testacc TESTARGS='-run=TestAccResourceVSphereVirtualDisk'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run=TestAccResourceVSphereVirtualDisk -timeout 360m
?       github.com/hashicorp/terraform-provider-vsphere [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/administrationroles    [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/computeresource [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/clustercomputeresource  [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/customattribute [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/contentlibrary  [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/datacenter      [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/datastore       [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/envbrowse       [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/folder  [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/dvportgroup     [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/provider        [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/network [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/nsx     [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/ovfdeploy       [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/resourcepool    [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/spbm    [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/storagepod      [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/structure       [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/testhelper      [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/hostsystem      [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/utils   [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/vappcontainer   [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/virtualmachine  [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/vsanclient      [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/vsansystem      [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/vmworkflow     [no test files]
=== RUN   TestAccResourceVSphereVirtualDisk_basic
--- PASS: TestAccResourceVSphereVirtualDisk_basic (93.77s)
=== RUN   TestAccResourceVSphereVirtualDisk_multi
--- PASS: TestAccResourceVSphereVirtualDisk_multi (105.79s)
=== RUN   TestAccResourceVSphereVirtualDisk_multiWithParent
--- PASS: TestAccResourceVSphereVirtualDisk_multiWithParent (107.49s)
=== RUN   TestAccResourceVSphereVirtualDisk_withParent
--- PASS: TestAccResourceVSphereVirtualDisk_withParent (100.44s)
PASS
ok      github.com/hashicorp/terraform-provider-vsphere/vsphere 408.441s
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/viapi   0.950s [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/virtualdisk     1.124s [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/virtualdevice  1.202s [no tests to run]


...

Release Note

Release note for CHANGELOG:

Fixes #1824 - r/vsphere_virtual_disk is recreated due to bad disk type handling

References

#1824

Fixes hashicorp#1824
Issue addressed - when r/vsphere_virtual_disk.type is set as "lazy" as
documented here:
https://registry.terraform.io/providers/hashicorp/vsphere/latest/docs/resources/virtual_disk#type
i.e. Thick Provisioned Lazy Zeroed it is sent and received as
"preallocated". The value is mapped when sent but not when received
which causes disk recreaion when terraform apply is executed for the
second time without changing the HCL config.

Fix applied - when virtual disk type is read from the backend the value
is transformed to "lazy" if "preallocated" is received.

Testing done:
With HCL:
resource "vsphere_virtual_disk" "virtual_disk_test" {
  count              = 1
  datacenter         = data.vsphere_datacenter.datacenter.name
  datastore          = data.vsphere_datastore.datastore.name
  vmdk_path          = "/${var.VSPHERE_ESXI1}/test.vmdk"
  create_directories = true

  size               = 2
  type               = "lazy" # Thick Provision Lazy Zeroed (allocate then zero on first write)
}

executed `terraform apply` twice

Output from the second execution:

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Signed-off-by: Vasil Atanasov <vasila@vmware.com>
@vasilsatanasov vasilsatanasov requested a review from a team as a code owner October 10, 2023 15:42
@github-actions github-actions bot added provider Type: Provider size/xs Relative Sizing: Extra-Small labels Oct 10, 2023
Copy link
Collaborator

@tenthirtyam tenthirtyam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Vasil! 🚀

Thank you!

@tenthirtyam tenthirtyam merged commit dde2002 into hashicorp:main Oct 10, 2023
@tenthirtyam tenthirtyam added this to the v2.6.0 milestone Oct 10, 2023
@tenthirtyam tenthirtyam added the bug Type: Bug label Oct 10, 2023
@tenthirtyam tenthirtyam modified the milestones: v2.6.0, v2.5.1 Oct 12, 2023
@github-actions
Copy link

This functionality has been released in v2.5.1 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

I'm going to lock this pull request 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 related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 12, 2023
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug Type: Bug provider Type: Provider size/xs Relative Sizing: Extra-Small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

r/vsphere_virtual_disk with lazy forces replacement because of bad type reconciliation
3 participants