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

Add support for changing root disk size #345

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ require (
github.com/hashicorp/terraform v0.12.8
github.com/vmware/go-vcloud-director/v2 v2.4.0-alpha.11
)

replace github.com/vmware/go-vcloud-director/v2 => github.com/cheald/go-vcloud-director/v2 v2.0.0-20191004085034-4b17e65ce311
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ github.com/bmatcuk/doublestar v1.1.5/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
github.com/bsm/go-vlq v0.0.0-20150828105119-ec6e8d4f5f4e/go.mod h1:N+BjUcTjSxc2mtRGSCPsat1kze3CUtvJN3/jTXlp29k=
github.com/cheald/go-vcloud-director/v2 v2.0.0-20191004085034-4b17e65ce311 h1:eorqPrkM1UI/ooOLoKIUzeIo4ERWDxIZh78GETmOghI=
github.com/cheald/go-vcloud-director/v2 v2.0.0-20191004085034-4b17e65ce311/go.mod h1:VqfkCixIzRmj4EzF2yFJKB+aKDW6GkXlLbFh5xZ+qqs=
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
Expand Down Expand Up @@ -349,8 +351,6 @@ github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4A
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.1+incompatible h1:RMF1enSPeKTlXrXdOcqjFUElywVZjjC6pqse21bKbEU=
github.com/vmihailenco/msgpack v4.0.1+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmware/go-vcloud-director/v2 v2.4.0-alpha.11 h1:xgFpf3g9OKeBS0QAv8fs2zvR5RB07fWgqK5r6Xgh4rY=
github.com/vmware/go-vcloud-director/v2 v2.4.0-alpha.11/go.mod h1:VqfkCixIzRmj4EzF2yFJKB+aKDW6GkXlLbFh5xZ+qqs=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
Expand Down
23 changes: 22 additions & 1 deletion vcd/resource_vcd_vapp_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func resourceVcdVAppVm() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"root_disk": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
"cpu_cores": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -584,7 +588,7 @@ func resourceVcdVAppVmUpdateExecute(d *schema.ResourceData, meta interface{}) er
}

if d.HasChange("memory") || d.HasChange("cpus") || d.HasChange("cpu_cores") || d.HasChange("power_on") || d.HasChange("disk") ||
d.HasChange("expose_hardware_virtualization") || d.HasChange("network") || d.HasChange("computer_name") {
d.HasChange("expose_hardware_virtualization") || d.HasChange("network") || d.HasChange("computer_name") || d.HasChange("root_disk") {

log.Printf("[TRACE] VM %s has changes: memory(%t), cpus(%t), cpu_cores(%t), power_on(%t), disk(%t), expose_hardware_virtualization(%t), network(%t), computer_name(%t)",
vm.VM.Name, d.HasChange("memory"), d.HasChange("cpus"), d.HasChange("cpu_cores"), d.HasChange("power_on"), d.HasChange("disk"),
Expand Down Expand Up @@ -631,6 +635,18 @@ func resourceVcdVAppVmUpdateExecute(d *schema.ResourceData, meta interface{}) er
}
}

if d.HasChange("root_disk") {
vm.Refresh()
task, err := vm.ChangeDiskSize(0, 0, d.Get("root_disk").(int))
if err != nil {
return fmt.Errorf("error changing root disk size: %s: %s", vm.VM.Name, err)
}
err = task.WaitTaskCompletion()
if err != nil {
return fmt.Errorf("error waiting for disk size task for VM %s: %s", vm.VM.Name, err)
}
}

if d.HasChange("memory") {

task, err := vm.ChangeMemorySize(d.Get("memory").(int))
Expand Down Expand Up @@ -880,6 +896,11 @@ func resourceVcdVAppVmRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("unable to set guest properties in state: %s", err)
}

rootDisk := vm.GetDiskHardwareItem(0, 0)
if rootDisk != nil {
d.Set("root_disk", rootDisk.HostResource[0].Capacity)
}

err = updateStateOfAttachedDisks(d, *vm, vdc)
if err != nil {
d.Set("disk", nil)
Expand Down
3 changes: 3 additions & 0 deletions vcd/resource_vcd_vapp_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func TestAccVcdVAppVm_Basic(t *testing.T) {
"vcd_vapp_vm."+vmName, "power_on", "true"),
resource.TestCheckResourceAttr(
"vcd_vapp_vm."+vmName, "metadata.vm_metadata", "VM Metadata."),
resource.TestCheckResourceAttr(
"vcd_vapp_vm."+vmName, "root_disk", "16385"),
),
},
},
Expand Down Expand Up @@ -118,6 +120,7 @@ resource "vcd_vapp_vm" "{{.VmName}}" {
cpus = 2
cpu_cores = 1
ip = "10.10.102.161"
root_disk = 16385

metadata = {
vm_metadata = "VM Metadata."
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ github.com/ulikunitz/xz/lzma
# github.com/vmihailenco/msgpack v4.0.1+incompatible
github.com/vmihailenco/msgpack
github.com/vmihailenco/msgpack/codes
# github.com/vmware/go-vcloud-director/v2 v2.4.0-alpha.11
# github.com/vmware/go-vcloud-director/v2 v2.4.0-alpha.10 => github.com/cheald/go-vcloud-director/v2 v2.0.0-20191004085034-4b17e65ce311
github.com/vmware/go-vcloud-director/v2/govcd
github.com/vmware/go-vcloud-director/v2/types/v56
github.com/vmware/go-vcloud-director/v2/util
Expand Down