Skip to content

Commit

Permalink
Merge pull request #672 from becoinc/master
Browse files Browse the repository at this point in the history
Add Support for Accelerated Networking (SR-IOV)
  • Loading branch information
tombuildsstuff authored Jan 11, 2018
2 parents ac87eda + 80db544 commit 159976f
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 1 deletion.
19 changes: 18 additions & 1 deletion azurerm/resource_arm_network_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ func resourceArmNetworkInterface() *schema.Resource {
Computed: true,
},

/**
* As of 2018-01-06: AN (aka. SR-IOV) on Azure is GA on Windows and Linux.
*
* Refer to: https://azure.microsoft.com/en-us/blog/maximize-your-vm-s-performance-with-accelerated-networking-now-generally-available-for-both-windows-and-linux/
*
* Refer to: https://docs.microsoft.com/en-us/azure/virtual-network/create-vm-accelerated-networking-cli
* For details, VM configuration and caveats.
*/
"enable_accelerated_networking": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"enable_ip_forwarding": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -173,10 +187,12 @@ func resourceArmNetworkInterfaceCreateUpdate(d *schema.ResourceData, meta interf
location := d.Get("location").(string)
resGroup := d.Get("resource_group_name").(string)
enableIpForwarding := d.Get("enable_ip_forwarding").(bool)
enableAcceleratedNetworking := d.Get("enable_accelerated_networking").(bool)
tags := d.Get("tags").(map[string]interface{})

properties := network.InterfacePropertiesFormat{
EnableIPForwarding: &enableIpForwarding,
EnableIPForwarding: &enableIpForwarding,
EnableAcceleratedNetworking: &enableAcceleratedNetworking,
}

if v, ok := d.GetOk("network_security_group_id"); ok {
Expand Down Expand Up @@ -347,6 +363,7 @@ func resourceArmNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) e
d.Set("applied_dns_servers", appliedDNSServers)
d.Set("dns_servers", dnsServers)
d.Set("enable_ip_forwarding", resp.EnableIPForwarding)
d.Set("enable_accelerated_networking", resp.EnableAcceleratedNetworking)

flattenAndSetTags(d, resp.Tags)

Expand Down
56 changes: 56 additions & 0 deletions azurerm/resource_arm_network_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,25 @@ func TestAccAzureRMNetworkInterface_enableIPForwarding(t *testing.T) {
})
}

func TestAccAzureRMNetworkInterface_enableAcceleratedNetworking(t *testing.T) {
resourceName := "azurerm_network_interface.test"
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkInterface_acceleratedNetworking(rInt, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkInterfaceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "enable_accelerated_networking", "true"),
),
},
},
})
}

func TestAccAzureRMNetworkInterface_multipleLoadBalancers(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -581,6 +600,43 @@ resource "azurerm_network_interface" "test" {
`, rInt, location, rInt, rInt)
}

func testAccAzureRMNetworkInterface_acceleratedNetworking(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctest-rg-%d"
location = "%s"
}
resource "azurerm_virtual_network" "test" {
name = "acctestvn-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "testsubnet"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_network_interface" "test" {
name = "acctestni-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
enable_ip_forwarding = false
enable_accelerated_networking = true
ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.test.id}"
private_ip_address_allocation = "dynamic"
}
}
`, rInt, location, rInt, rInt)
}

func testAccAzureRMNetworkInterface_withTags(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
95 changes: 95 additions & 0 deletions azurerm/resource_arm_virtual_machine_managed_disks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/hashicorp/terraform/terraform"
)

// NOTE: Test `TestAccAzureRMVirtualMachine_enableAnWithVM` requires a machine of size `D8_v3` which is large/expensive - you may wish to ignore this test"

func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(t *testing.T) {
var vm compute.VirtualMachine
ri := acctest.RandInt()
Expand Down Expand Up @@ -341,6 +343,25 @@ func TestAccAzureRMVirtualMachine_managedServiceIdentity(t *testing.T) {
})
}

func TestAccAzureRMVirtualMachine_enableAnWithVM(t *testing.T) {
var vm compute.VirtualMachine
resourceName := "azurerm_virtual_machine.test"
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMVirtualMachine_anWithVM(rInt, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineExists(resourceName, &vm),
),
},
},
})
}

func testAccAzureRMVirtualMachine_withManagedServiceIdentity(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down Expand Up @@ -1576,3 +1597,77 @@ resource "azurerm_virtual_machine" "test" {
}
`, rInt, location, rInt, rInt, rInt, rInt, rString, rString)
}

func testAccAzureRMVirtualMachine_anWithVM(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctest-rg-%d"
location = "%s"
}
resource "azurerm_virtual_network" "test" {
name = "acctestvn-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "testsubnet"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_network_interface" "test" {
name = "acctestni-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
enable_ip_forwarding = false
enable_accelerated_networking = true
ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.test.id}"
private_ip_address_allocation = "dynamic"
}
}
resource "azurerm_virtual_machine" "test" {
name = "acctestvm-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
primary_network_interface_id = "${azurerm_network_interface.test.id}"
network_interface_ids = [ "${azurerm_network_interface.test.id}" ]
// Only large VMs allow AN
vm_size = "Standard_D8_v3"
delete_os_disk_on_termination = true
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "antest-%d-OSDisk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
disk_size_gb = 32
}
os_profile {
computer_name = "antestMachine-%d"
admin_username = "antestuser"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
}
`, rInt, location, rInt, rInt, rInt, rInt, rInt)
}
2 changes: 2 additions & 0 deletions website/docs/r/network_interface.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ The following arguments are supported:

* `enable_ip_forwarding` - (Optional) Enables IP Forwarding on the NIC. Defaults to `false`.

* `enable_accelerated_networking` - (Optional) Enables Azure Accelerated Networking using SR-IOV. Only certain VM instance sizes are supported. Refer to [Create a Virtual Machine with Accelerated Networking](https://docs.microsoft.com/en-us/azure/virtual-network/create-vm-accelerated-networking-cli). Defaults to `false`.

* `dns_servers` - (Optional) List of DNS servers IP addresses to use for this NIC, overrides the VNet-level server list

* `ip_configuration` - (Required) One or more `ip_configuration` associated with this NIC as documented below.
Expand Down

0 comments on commit 159976f

Please sign in to comment.