Skip to content

Commit

Permalink
Fix virtdisk count. Fixes to support Terraform 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
josenk committed May 11, 2019
1 parent b4c5ff5 commit ec8b4fd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ Known issues with vmware_esxi

Version History
---------------
* 1.4.3 Fix virtdisk count. Fixes to support Terraform 0.12
* 1.4.2 Support 10 nics, more README changes
* 1.4.1 Fix README build instructions, static binaries, update guest types
* 1.4.0 Add GuestInfo (Cloud-init, Ignition!). Fix, allow esxi passwords with special characters.
Expand Down
18 changes: 17 additions & 1 deletion esxi/guest-read.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ func resourceGUESTRead(d *schema.ResourceData, m interface{}) error {
d.Set("notes", notes)
d.Set("guestinfo", guestinfo)

if d.Get("guest_startup_timeout").(int) > 1 {
d.Set("guest_startup_timeout", d.Get("guest_startup_timeout").(int))
} else {
d.Set("guest_startup_timeout", 60)
}
if d.Get("guest_shutdown_timeout").(int) > 0 {
d.Set("guest_shutdown_timeout", d.Get("guest_shutdown_timeout").(int))
} else {
d.Set("guest_shutdown_timeout", 20)
}

// Do network interfaces
log.Printf("virtual_networks: %q\n", virtual_networks)
nics := make([]map[string]interface{}, 0, 1)
Expand All @@ -59,7 +70,12 @@ func resourceGUESTRead(d *schema.ResourceData, m interface{}) error {
log.Printf("virtual_disks: %q\n", virtual_disks)
vdisks := make([]map[string]interface{}, 0, 1)

for vdisk := 0; vdisk < 3; vdisk++ {
if virtual_disks[0][0] == "" {
out := make(map[string]interface{})
vdisks = append(vdisks, out)
}

for vdisk := 0; vdisk < 60; vdisk++ {
if virtual_disks[vdisk][0] != "" {
out := make(map[string]interface{})
out["virtual_disk_id"] = virtual_disks[vdisk][0]
Expand Down
26 changes: 15 additions & 11 deletions esxi/resource_guest.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func resourceGUEST() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DefaultFunc: schema.EnvDefaultFunc("boot_disk_type", "thin"),
Description: "Guest boot disk type. thin, zeroedthick, eagerzeroedthick",
},
"boot_disk_size": &schema.Schema{
Expand Down Expand Up @@ -141,32 +140,31 @@ func resourceGUEST() *schema.Resource {
"guest_startup_timeout": {
Type: schema.TypeInt,
Optional: true,
Default: 60,
Computed: true,
Description: "The amount of guest uptime, in seconds, to wait for an available IP address on this virtual machine.",
ValidateFunc: validation.IntBetween(1, 600),
},
"guest_shutdown_timeout": {
Type: schema.TypeInt,
Optional: true,
Default: 20,
Computed: true,
Description: "The amount of time, in seconds, to wait for a graceful shutdown before doing a forced power off.",
ValidateFunc: validation.IntBetween(0, 600),
},
"virtual_disks": &schema.Schema{
Type: schema.TypeList,
Optional: true,
ForceNew: false,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"virtual_disk_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: false,
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("virtual_disk_id", ""),
},
"slot": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: false,
Computed: true,
Description: "SCSI_Ctrl:SCSI_id. Range '0:1' to '0:15'. SCSI_id 7 is not allowed.",
},
Expand Down Expand Up @@ -198,7 +196,7 @@ func resourceGUESTCreate(d *schema.ResourceData, m interface{}) error {
var virtual_networks [10][3]string
var virtual_disks [60][2]string
var src_path string
var tmpint, i int
var tmpint, i, virtualDiskCount int

clone_from_vm := d.Get("clone_from_vm").(string)
ovf_source := d.Get("ovf_source").(string)
Expand All @@ -211,9 +209,9 @@ func resourceGUESTCreate(d *schema.ResourceData, m interface{}) error {
numvcpus := d.Get("numvcpus").(string)
virthwver := d.Get("virthwver").(string)
guestos := d.Get("guestos").(string)
guest_shutdown_timeout := d.Get("guest_shutdown_timeout").(int)
notes := d.Get("notes").(string)
power := d.Get("power").(string)
guest_shutdown_timeout := d.Get("guest_shutdown_timeout").(int)

guestinfo, ok := d.Get("guestinfo").(map[string]interface{})
if !ok {
Expand Down Expand Up @@ -292,7 +290,12 @@ func resourceGUESTCreate(d *schema.ResourceData, m interface{}) error {
}

// Validate virtual_disks
virtualDiskCount := d.Get("virtual_disks.#").(int)
virtualDiskCount, ok = d.Get("virtual_disks.#").(int)
if !ok {
virtualDiskCount = 0
virtual_disks[0][0] = ""
}

if virtualDiskCount > 59 {
virtualDiskCount = 59
}
Expand All @@ -305,6 +308,7 @@ func resourceGUESTCreate(d *schema.ResourceData, m interface{}) error {

if attr, ok := d.Get(prefix + "slot").(string); ok && attr != "" {
virtual_disks[i][1] = d.Get(prefix + "slot").(string)
validateVirtualDiskSlot(virtual_disks[i][1])
result := validateVirtualDiskSlot(virtual_disks[i][1])
if result != "ok" {
return errors.New(result)
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.4.2
v1.4.3

0 comments on commit ec8b4fd

Please sign in to comment.