Skip to content

Commit

Permalink
1.3.0, Add storage without ForceNew
Browse files Browse the repository at this point in the history
  • Loading branch information
josenk committed Jan 21, 2019
1 parent c508027 commit feb3698
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 26 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Requirements
- You MUST enable ssh access on your ESXi hypervisor.
* Google 'How to enable ssh access on esxi'
- In general, you should know how to use terraform, esxi and some networking...
* You will most likely need a DHCP server on your primary network if you are deploying VMs with public OVF/OVA/VMX images. (Sources that have unconfigured primary interfaces.)
- The source OVF/OVA/VMX images must have open-vm-tools or vmware-tools installed to properly import an IPaddress. (you need this to run provisioners)


Building The Provider
Expand Down Expand Up @@ -68,14 +70,12 @@ Features and Compatibility
* Terraform will Create, Destroy, Update & Read Extra Storage for Guests.


Requirements
------------
1. This is a Terraform plugin, so you need Terraform installed... :-)
2. This plugin requires ovftool from VMware. Download from VMware website. NOTE: ovftool installer for windows doesn't put ovftool.exe in your path. You will need to manually set your path.
>https://www.vmware.com/support/developer/ovf/
3. You MUST enable ssh access on your ESXi hypervisor.
* Google 'How to enable ssh access on esxi'
4. In general, you should know how to use terraform, esxi and some networking...
Vagrant vs Terraform.
---------------------
If you are using vagrant as a deployment tool (infa as code), you may want to consider a better tool. Terraform. Vagrant is better for development environments, while Terraform is better at managing infrastructure. Please give my terraform plugin a try and give me some feedback. What you're trying to do, what's missing, what works, what doesn't work, etc...
>https://www.vagrantup.com/intro/vs/terraform.html
>https://github.com/josenk/terraform-provider-esxi
>https://github.com/josenk/vagrant-vmware-esxi

Why this plugin?
Expand All @@ -86,7 +86,7 @@ Not everyone has vCenter, vSphere, expensive APIs... These cost $$$. ESXi is f
How to install
--------------
Download and install Terraform on your local system using instructions from https://www.terraform.io/downloads.html.
Clone this plugin from github, build and place a copy of it in your path or current directory of your terraform project.
Clone this plugin from github, build and place a copy of it in your path or current directory of your terraform project. Or download pre-built binaries from https://github.com/josenk/terraform-provider-esxi/releases.


How to use and configure a main.tf file
Expand Down Expand Up @@ -193,6 +193,7 @@ Known issues with vmware_esxi

Version History
---------------
* 1.3.0 Add support to Update storage attachments.
* 1.2.2 fix guest_update power, boot_disk_type defaults, README, windows support
* 1.2.1 Fix ssh connection retries.
* 1.2.0 Add support for notes (annotation)
Expand Down
64 changes: 49 additions & 15 deletions esxi/guest_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,59 @@ func updateVmx_contents(c *Config, vmid string, iscreate bool, memsize int, numv
}

//
// Create/update networks network_interfaces
// add/modify virtual disks
//
var tmpvar string
var vmx_contents_new string
var i, j int

//
// Remove all disks
//
regexReplacement = fmt.Sprintf("")
for i = 0; i < 4; i++ {
for j = 0; j < 16; j++ {

if (i != 0 || j != 0) && j != 7 {
re := regexp.MustCompile(fmt.Sprintf("scsi%d:%d.*\n", i, j))
vmx_contents = re.ReplaceAllString(vmx_contents, regexReplacement)
}
}
}

//
// Add disks that are managed by terraform
//
for i = 0; i < 59; i++ {
if virtual_disks[i][0] != "" {

log.Printf("[updateVmx_contents] Adding: %s\n", virtual_disks[i][1])
tmpvar = fmt.Sprintf("scsi%s.deviceType = \"scsi-hardDisk\"\n", virtual_disks[i][1])
if !strings.Contains(vmx_contents, tmpvar) {
vmx_contents += "\n" + tmpvar
}

tmpvar = fmt.Sprintf("scsi%s.fileName", virtual_disks[i][1])
if strings.Contains(vmx_contents, tmpvar) {
re := regexp.MustCompile(tmpvar + " = \".*\"")
regexReplacement = fmt.Sprintf(tmpvar+" = \"%s\"", virtual_disks[i][0])
vmx_contents = re.ReplaceAllString(vmx_contents, regexReplacement)
} else {
regexReplacement = fmt.Sprintf("\n"+tmpvar+" = \"%s\"", virtual_disks[i][0])
vmx_contents += "\n" + regexReplacement
}

tmpvar = fmt.Sprintf("scsi%s.present = \"true\"\n", virtual_disks[i][1])
if !strings.Contains(vmx_contents, tmpvar) {
vmx_contents += "\n" + tmpvar
}

}
}

//
// Create/update networks network_interfaces
//
if iscreate == true {

// This is create network interfaces. Clean out old network interfaces.
Expand Down Expand Up @@ -224,20 +272,6 @@ func updateVmx_contents(c *Config, vmid string, iscreate bool, memsize int, numv
}
}

// add virtual disks
for i := 0; i < 59; i++ {
if virtual_disks[i][0] != "" {
tmpvar = fmt.Sprintf("scsi%s.deviceType = \"scsi-hardDisk\"\n", virtual_disks[i][1])
vmx_contents_new = vmx_contents_new + tmpvar

tmpvar = fmt.Sprintf("scsi%s.fileName = \"%s\"\n", virtual_disks[i][1], virtual_disks[i][0])
vmx_contents_new = vmx_contents_new + tmpvar

tmpvar = fmt.Sprintf("scsi%s.present = \"true\"\n", virtual_disks[i][1])
vmx_contents_new = vmx_contents_new + tmpvar
}
}

// Save
vmx_contents = vmx_contents_new

Expand Down
2 changes: 1 addition & 1 deletion esxi/resource_guest.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func resourceGUEST() *schema.Resource {
"virtual_disk_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ForceNew: false,
},
"slot": &schema.Schema{
Type: schema.TypeString,
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.2.2
v1.3.0

0 comments on commit feb3698

Please sign in to comment.