Skip to content

Commit

Permalink
Merge pull request #193 from shelson/add_adapter_type_variable
Browse files Browse the repository at this point in the history
created adapter_type variable for network interfaces
  • Loading branch information
vancluever committed Oct 11, 2017
2 parents 5d9bcc6 + 5534569 commit 6f4416a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 20 additions & 11 deletions vsphere/resource_vsphere_virtual_machine.go
Expand Up @@ -36,6 +36,11 @@ var DiskControllerTypes = []string{
"ide",
}

var virtualMachineNetworkAdapterTypeAllowedValues = []string{
"vmxnet3",
"e1000",
}

type networkInterface struct {
deviceName string
label string
Expand All @@ -45,7 +50,7 @@ type networkInterface struct {
ipv6Address string
ipv6PrefixLength int
ipv6Gateway string
adapterType string // TODO: Make "adapter_type" argument
adapterType string
macAddress string
}

Expand Down Expand Up @@ -379,9 +384,11 @@ func resourceVSphereVirtualMachine() *schema.Resource {
DiffSuppressFunc: suppressIpDifferences},

"adapter_type": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "vmxnet3",
ValidateFunc: validation.StringInSlice(virtualMachineNetworkAdapterTypeAllowedValues, false),
},

"mac_address": &schema.Schema{
Expand Down Expand Up @@ -867,6 +874,9 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{
if v, ok := network["mac_address"].(string); ok && v != "" {
networks[i].macAddress = v
}
if v, ok := network["adapter_type"].(string); ok && v != "" {
networks[i].adapterType = v
}
}
vm.networkInterfaces = networks
log.Printf("[DEBUG] network_interface init: %v", networks)
Expand Down Expand Up @@ -1144,6 +1154,11 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{})
log.Printf("[DEBUG] Device list %+v", deviceList)
for _, device := range deviceList {
networkInterface := make(map[string]interface{})
if _, ok := device.(*types.VirtualE1000); ok {
networkInterface["adapter_type"] = "e1000"
} else {
networkInterface["adapter_type"] = "vmxnet3"
}
virtualDevice := device.GetVirtualDevice()
nic := device.(types.BaseVirtualEthernetCard)
DeviceName, _ := getNetworkName(client, vm, nic)
Expand Down Expand Up @@ -1999,13 +2014,7 @@ func (vm *virtualMachine) setupVirtualMachine(c *govmomi.Client) error {
networkConfigs := []types.CustomizationAdapterMapping{}
for _, network := range vm.networkInterfaces {
// network device
var networkDeviceType string
if vm.template == "" {
networkDeviceType = "e1000"
} else {
networkDeviceType = "vmxnet3"
}
nd, err := buildNetworkDevice(finder, network.label, networkDeviceType, network.macAddress)
nd, err := buildNetworkDevice(finder, network.label, network.adapterType, network.macAddress)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/virtual_machine.html.markdown
Expand Up @@ -127,6 +127,8 @@ requires vCenter 6.0 or higher.
The `network_interface` block supports:

* `label` - (Required) Label to assign to this network interface
* `adapter_type` - (Optional) The adapter type on the network interface. Can be
one of `vmxnet3` or `e1000`. Default: `vmxnet3`.
* `ipv4_address` - (Optional) Static IPv4 to assign to this network interface.
Interface will use DHCP if this is left blank.
* `ipv4_prefix_length` - (Optional) prefix length to use when statically
Expand Down

0 comments on commit 6f4416a

Please sign in to comment.