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

created adapter_type variable for network interfaces #193

Merged
merged 4 commits into from Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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