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

Remove size attribute for attached disks #528

Merged
merged 3 commits into from
May 25, 2018

Conversation

luis-silva
Copy link

@luis-silva luis-silva commented May 15, 2018

Current Problem
When creating a disk resource and attaching it to a VM resource the terraform apply operation shows this plan below (notice the size set to zero):

disk.2.attach:                                      "true"
disk.2.datastore_id:                                "datastore-1160"
disk.2.device_address:                              <computed>
disk.2.disk_mode:                                   "persistent"
disk.2.disk_sharing:                                "sharingNone"
disk.2.eagerly_scrub:                               "false"
disk.2.io_limit:                                    "-1"
disk.2.io_reservation:                              "0"
disk.2.io_share_count:                              "0"
disk.2.io_share_level:                              "normal"
disk.2.keep_on_remove:                              "false"
disk.2.key:                                         "0"
disk.2.label:                                       "disk2"
disk.2.path:                                        "mypath/disk2.vmdk"
disk.2.size:                                        "0"
disk.2.thin_provisioned:                            "true"
disk.2.unit_number:                                 "2"
disk.2.uuid:                                        <computed>
disk.2.write_through:                               "false"

If the VM resource is then tainted to force a replacement using terraform taint the plan is then displayed as below (notice no size attribute present)

disk.2.attach:                                      "true" => "true"
disk.2.datastore_id:                                "datastore-1160" => "datastore-1160"
disk.2.device_address:                              "scsi:0:2" => <computed>
disk.2.disk_mode:                                   "persistent" => "persistent"
disk.2.disk_sharing:                                "sharingNone" => "sharingNone"
disk.2.eagerly_scrub:                               "false" => "false"
disk.2.io_limit:                                    "-1" => "-1"
disk.2.io_reservation:                              "0" => "0"
disk.2.io_share_count:                              "1000" => "0"
disk.2.io_share_level:                              "normal" => "normal"
disk.2.keep_on_remove:                              "false" => "false"
disk.2.key:                                         "2002" => <computed>
disk.2.label:                                       "disk2" => "disk2"
disk.2.path:                                        "mypath/disk2.vmdk" => "mypath/disk2.vmdk"
disk.2.thin_provisioned:                            "true" => "true"
disk.2.unit_number:                                 "2" => "2"
disk.2.uuid:                                        "6000C299-a45d-a4b9-51c6-7107ec6816a2" => <computed>
disk.2.write_through:                               "false" => "false"

This goes on to fail with an error Mismatch reason: extra attributes: disk.2.size producing an output with two sectionsDiff One (usually from plan): and Diff Two (usually from apply):. Comparing the two shows that Diff Two (usually from apply): contains this extra part:

"disk.2.size":*terraform.ResourceAttrDiff{Old:"", New:"0", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0},

This happens when running with Terraform Version: 0.11.7 and provider.vsphere = 1.5.0

My Fix

Since both the documentation and the code itself mention that when attaching a disk the size attribute can't be used, I force that attribute to be removed if it is set and the operation is attach.

Destroying everything and starting fresh with the fix applied results in the below (No size is set):

disk.2.attach:                                      "true"
disk.2.datastore_id:                                "datastore-1160"
disk.2.device_address:                              <computed>
disk.2.disk_mode:                                   "persistent"
disk.2.disk_sharing:                                "sharingNone"
disk.2.eagerly_scrub:                               "false"
disk.2.io_limit:                                    "-1"
disk.2.io_reservation:                              "0"
disk.2.io_share_count:                              "0"
disk.2.io_share_level:                              "normal"
disk.2.keep_on_remove:                              "false"
disk.2.key:                                         "0"
disk.2.label:                                       "disk2"
disk.2.path:                                        "mypath/disk2.vmdk"
disk.2.thin_provisioned:                            "true"
disk.2.unit_number:                                 "2"
disk.2.uuid:                                        <computed>
disk.2.write_through:                               "false"

And then tainting the VM and running the apply again results in the below (No size is set).

disk.2.attach:                                      "true" => "true"
disk.2.datastore_id:                                "datastore-1160" => "datastore-1160"
disk.2.device_address:                              "scsi:0:2" => <computed>
disk.2.disk_mode:                                   "persistent" => "persistent"
disk.2.disk_sharing:                                "sharingNone" => "sharingNone"
disk.2.eagerly_scrub:                               "false" => "false"
disk.2.io_limit:                                    "-1" => "-1"
disk.2.io_reservation:                              "0" => "0"
disk.2.io_share_count:                              "1000" => "0"
disk.2.io_share_level:                              "normal" => "normal"
disk.2.keep_on_remove:                              "false" => "false"
disk.2.key:                                         "2002" => <computed>
disk.2.label:                                       "disk2" => "disk2"
disk.2.path:                                        "mypath/disk2.vmdk" => "mypath/disk2.vmdk"
disk.2.thin_provisioned:                            "true" => "true"
disk.2.unit_number:                                 "2" => "2"
disk.2.uuid:                                        "6000C293-6c39-40fd-231e-699b461843ce" => <computed>
disk.2.write_through:                               "false" => "false"

And this time the VM replacement finishes without errors and the disk is reattached correctly.

@vancluever vancluever added the bug Type: Bug label May 17, 2018
To get resource tainting facilities. This ensures that we don't have to
do it ourselves.
This is a test for the diff mismatch issue defined in hashicorp#528, where
tainting a VM resource with an attached disk gives the mismatch via an
erroneously present disks attribute.
@vancluever
Copy link
Contributor

Hey @luis-silva thanks for this and sorry for the delay!

I've added a test for this to make sure we have the error covered, and it looks like your fix fixes this perfectly! Thanks again!

@vancluever vancluever merged commit 14a86d1 into hashicorp:master May 25, 2018
@luis-silva
Copy link
Author

@vancluever No problem, thanks for adding the test!

bill-rich pushed a commit that referenced this pull request Jul 13, 2018
This is a test for the diff mismatch issue defined in #528, where
tainting a VM resource with an attached disk gives the mismatch via an
erroneously present disks attribute.
@ghost ghost locked and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Type: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants