From c5b5d13e183bb0bedaa06bb84e996777e59ce2d9 Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Wed, 26 Jul 2023 08:13:22 +0800 Subject: [PATCH 1/5] add code --- .../network/network_interface_resource.go | 52 +++++++++++++++ .../network_interface_resource_test.go | 65 +++++++++++++++++++ .../docs/r/network_interface.html.markdown | 6 ++ 3 files changed, 123 insertions(+) diff --git a/internal/services/network/network_interface_resource.go b/internal/services/network/network_interface_resource.go index 78881c29307f..cc0467316ca5 100644 --- a/internal/services/network/network_interface_resource.go +++ b/internal/services/network/network_interface_resource.go @@ -126,6 +126,32 @@ func resourceNetworkInterface() *pluginsdk.Resource { }, // Optional + "auxiliary_mode": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + string(networkinterfaces.NetworkInterfaceAuxiliaryModeAcceleratedConnections), + string(networkinterfaces.NetworkInterfaceAuxiliaryModeFloating), + string(networkinterfaces.NetworkInterfaceAuxiliaryModeNone), + }, false), + Default: string(networkinterfaces.NetworkInterfaceAuxiliaryModeNone), + RequiredWith: []string{"auxiliary_sku"}, + }, + + "auxiliary_sku": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + string(networkinterfaces.NetworkInterfaceAuxiliarySkuAEight), + string(networkinterfaces.NetworkInterfaceAuxiliarySkuAFour), + string(networkinterfaces.NetworkInterfaceAuxiliarySkuAOne), + string(networkinterfaces.NetworkInterfaceAuxiliarySkuATwo), + string(networkinterfaces.NetworkInterfaceAuxiliarySkuNone), + }, false), + Default: string(networkinterfaces.NetworkInterfaceAuxiliarySkuNone), + RequiredWith: []string{"auxiliary_mode"}, + }, + "dns_servers": { Type: pluginsdk.TypeList, Optional: true, @@ -232,6 +258,14 @@ func resourceNetworkInterfaceCreate(d *pluginsdk.ResourceData, meta interface{}) locks.ByName(id.NetworkInterfaceName, networkInterfaceResourceName) defer locks.UnlockByName(id.NetworkInterfaceName, networkInterfaceResourceName) + if auxiliaryMode, hasAuxiliaryMode := d.GetOk("auxiliary_mode"); hasAuxiliaryMode { + properties.AuxiliaryMode = pointer.To(networkinterfaces.NetworkInterfaceAuxiliaryMode(auxiliaryMode.(string))) + } + + if auxiliarySku, hasAuxiliarySku := d.GetOk("auxiliary_sku"); hasAuxiliarySku { + properties.AuxiliarySku = pointer.To(networkinterfaces.NetworkInterfaceAuxiliarySku(auxiliarySku.(string))) + } + dns, hasDns := d.GetOk("dns_servers") nameLabel, hasNameLabel := d.GetOk("internal_dns_name_label") if hasDns || hasNameLabel { @@ -325,6 +359,22 @@ func resourceNetworkInterfaceUpdate(d *pluginsdk.ResourceData, meta interface{}) }, } + if d.HasChange("auxiliary_mode") { + if auxiliaryMode, hasAuxiliaryMode := d.GetOk("auxiliary_mode"); hasAuxiliaryMode { + update.Properties.AuxiliaryMode = pointer.To(networkinterfaces.NetworkInterfaceAuxiliaryMode(auxiliaryMode.(string))) + } + } else { + update.Properties.AuxiliaryMode = existing.Model.Properties.AuxiliaryMode + } + + if d.HasChange("auxiliary_sku") { + if auxiliarySku, hasAuxiliarySku := d.GetOk("auxiliary_sku"); hasAuxiliarySku { + update.Properties.AuxiliarySku = pointer.To(networkinterfaces.NetworkInterfaceAuxiliarySku(auxiliarySku.(string))) + } + } else { + update.Properties.AuxiliarySku = existing.Model.Properties.AuxiliarySku + } + if d.HasChange("dns_servers") { dnsServersRaw := d.Get("dns_servers").([]interface{}) dnsServers := expandNetworkInterfaceDnsServers(dnsServersRaw) @@ -462,6 +512,8 @@ func resourceNetworkInterfaceRead(d *pluginsdk.ResourceData, meta interface{}) e return fmt.Errorf("setting `applied_dns_servers`: %+v", err) } + d.Set("auxiliary_mode", pointer.From(props.AuxiliaryMode)) + d.Set("auxiliary_sku", pointer.From(props.AuxiliarySku)) d.Set("enable_ip_forwarding", props.EnableIPForwarding) d.Set("enable_accelerated_networking", props.EnableAcceleratedNetworking) d.Set("internal_dns_name_label", internalDnsNameLabel) diff --git a/internal/services/network/network_interface_resource_test.go b/internal/services/network/network_interface_resource_test.go index 7234114bab2d..66b7b04b9d33 100644 --- a/internal/services/network/network_interface_resource_test.go +++ b/internal/services/network/network_interface_resource_test.go @@ -44,6 +44,34 @@ func TestAccNetworkInterface_disappears(t *testing.T) { }) } +func TestAccNetworkInterface_auxiliary(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") + r := NetworkInterfaceResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.auxiliary(data, "", ""), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.auxiliary(data, "AcceleratedConnections", "A2"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.auxiliary(data, "", ""), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccNetworkInterface_dnsServers(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") r := NetworkInterfaceResource{} @@ -388,6 +416,43 @@ resource "azurerm_network_interface" "test" { `, r.template(data), data.RandomInteger) } +func (r NetworkInterfaceResource) auxiliary(data acceptance.TestData, mode string, sku string) string { + // Auxiliary Mode Nic is enabled in specific regions (https://learn.microsoft.com/en-us/azure/networking/nva-accelerated-connections#supported-regions) for now + // To not affect other testcases of `Network`, hard-code to that for now + data.Locations.Primary = "westus" + + if mode != "" { + mode = fmt.Sprintf(`auxiliary_mode = "%s"`, mode) + } + + if sku != "" { + sku = fmt.Sprintf(`auxiliary_sku = "%s"`, sku) + } + + return fmt.Sprintf(` +%s + +resource "azurerm_network_interface" "test" { + name = "acctestni-%d" + location = "%s" + resource_group_name = azurerm_resource_group.test.name + %s + %s + enable_accelerated_networking = true + + ip_configuration { + name = "primary" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + } + + tags = { + fastpathenabled = "true" + } +} +`, r.template(data), data.RandomInteger, data.Locations.Primary, mode, sku) +} + func (r NetworkInterfaceResource) withMultipleParameters(data acceptance.TestData) string { return fmt.Sprintf(` %s diff --git a/website/docs/r/network_interface.html.markdown b/website/docs/r/network_interface.html.markdown index f5387f3f578b..f5fe847921fb 100644 --- a/website/docs/r/network_interface.html.markdown +++ b/website/docs/r/network_interface.html.markdown @@ -60,6 +60,12 @@ The following arguments are supported: --- +* `auxiliary_mode` - (Optional) The Auxiliary mode of the Network Interface. Possible values are `AcceleratedConnections`, `Floating` and `None`. Defaults to `None`. + +-> **Note:** This field requires the preview feature is enabled. See the [Prerequisites](https://learn.microsoft.com/en-us/azure/networking/nva-accelerated-connections#prerequisites) for more details. + +* `auxiliary_sku` - (Optional) The Auxiliary SKU of the Network Interface. Possible values are `A1`, `A2`, `A4`, `A8` and `None`. Defaults to `None`. + * `dns_servers` - (Optional) A list of IP Addresses defining the DNS Servers which should be used for this Network Interface. -> **Note:** Configuring DNS Servers on the Network Interface will override the DNS Servers defined on the Virtual Network. From decfbcbe6a0a276a610915f759cc5e4b2697fca3 Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Thu, 17 Aug 2023 09:22:10 +0800 Subject: [PATCH 2/5] resolve comments 0817 --- .../network/network_interface_resource.go | 19 ++++--- .../network_interface_resource_test.go | 51 +++++++++++++------ .../docs/r/network_interface.html.markdown | 6 +-- 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/internal/services/network/network_interface_resource.go b/internal/services/network/network_interface_resource.go index cc0467316ca5..05c25d803071 100644 --- a/internal/services/network/network_interface_resource.go +++ b/internal/services/network/network_interface_resource.go @@ -132,9 +132,7 @@ func resourceNetworkInterface() *pluginsdk.Resource { ValidateFunc: validation.StringInSlice([]string{ string(networkinterfaces.NetworkInterfaceAuxiliaryModeAcceleratedConnections), string(networkinterfaces.NetworkInterfaceAuxiliaryModeFloating), - string(networkinterfaces.NetworkInterfaceAuxiliaryModeNone), }, false), - Default: string(networkinterfaces.NetworkInterfaceAuxiliaryModeNone), RequiredWith: []string{"auxiliary_sku"}, }, @@ -146,9 +144,7 @@ func resourceNetworkInterface() *pluginsdk.Resource { string(networkinterfaces.NetworkInterfaceAuxiliarySkuAFour), string(networkinterfaces.NetworkInterfaceAuxiliarySkuAOne), string(networkinterfaces.NetworkInterfaceAuxiliarySkuATwo), - string(networkinterfaces.NetworkInterfaceAuxiliarySkuNone), }, false), - Default: string(networkinterfaces.NetworkInterfaceAuxiliarySkuNone), RequiredWith: []string{"auxiliary_mode"}, }, @@ -512,8 +508,19 @@ func resourceNetworkInterfaceRead(d *pluginsdk.ResourceData, meta interface{}) e return fmt.Errorf("setting `applied_dns_servers`: %+v", err) } - d.Set("auxiliary_mode", pointer.From(props.AuxiliaryMode)) - d.Set("auxiliary_sku", pointer.From(props.AuxiliarySku)) + auxiliaryMode := "" + if props.AuxiliaryMode != nil && *props.AuxiliaryMode != networkinterfaces.NetworkInterfaceAuxiliaryModeNone { + auxiliaryMode = string(*props.AuxiliaryMode) + } + + d.Set("auxiliary_mode", auxiliaryMode) + + auxiliarySku := "" + if props.AuxiliarySku != nil && *props.AuxiliarySku != networkinterfaces.NetworkInterfaceAuxiliarySkuNone { + auxiliarySku = string(*props.AuxiliarySku) + } + + d.Set("auxiliary_sku", auxiliarySku) d.Set("enable_ip_forwarding", props.EnableIPForwarding) d.Set("enable_accelerated_networking", props.EnableAcceleratedNetworking) d.Set("internal_dns_name_label", internalDnsNameLabel) diff --git a/internal/services/network/network_interface_resource_test.go b/internal/services/network/network_interface_resource_test.go index 66b7b04b9d33..fb180867b148 100644 --- a/internal/services/network/network_interface_resource_test.go +++ b/internal/services/network/network_interface_resource_test.go @@ -49,21 +49,21 @@ func TestAccNetworkInterface_auxiliary(t *testing.T) { r := NetworkInterfaceResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.auxiliary(data, "", ""), + Config: r.auxiliaryNone(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { - Config: r.auxiliary(data, "AcceleratedConnections", "A2"), + Config: r.auxiliaryAcceleratedConnections(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { - Config: r.auxiliary(data, "", ""), + Config: r.auxiliaryNone(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -416,28 +416,47 @@ resource "azurerm_network_interface" "test" { `, r.template(data), data.RandomInteger) } -func (r NetworkInterfaceResource) auxiliary(data acceptance.TestData, mode string, sku string) string { +func (r NetworkInterfaceResource) auxiliaryNone(data acceptance.TestData) string { // Auxiliary Mode Nic is enabled in specific regions (https://learn.microsoft.com/en-us/azure/networking/nva-accelerated-connections#supported-regions) for now // To not affect other testcases of `Network`, hard-code to that for now data.Locations.Primary = "westus" - if mode != "" { - mode = fmt.Sprintf(`auxiliary_mode = "%s"`, mode) - } + return fmt.Sprintf(` +%s - if sku != "" { - sku = fmt.Sprintf(`auxiliary_sku = "%s"`, sku) - } +resource "azurerm_network_interface" "test" { + name = "acctestni-%d" + location = "%s" + resource_group_name = azurerm_resource_group.test.name + enable_accelerated_networking = true + + ip_configuration { + name = "primary" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + } + + tags = { + fastpathenabled = "true" + } +} +`, r.template(data), data.RandomInteger, data.Locations.Primary) +} + +func (r NetworkInterfaceResource) auxiliaryAcceleratedConnections(data acceptance.TestData) string { + // Auxiliary Mode Nic is enabled in specific regions (https://learn.microsoft.com/en-us/azure/networking/nva-accelerated-connections#supported-regions) for now + // To not affect other testcases of `Network`, hard-code to that for now + data.Locations.Primary = "westus" return fmt.Sprintf(` %s resource "azurerm_network_interface" "test" { - name = "acctestni-%d" - location = "%s" - resource_group_name = azurerm_resource_group.test.name - %s - %s + name = "acctestni-%d" + location = "%s" + resource_group_name = azurerm_resource_group.test.name + auxiliary_mode = "AcceleratedConnections" + auxiliary_sku = "A2" enable_accelerated_networking = true ip_configuration { @@ -450,7 +469,7 @@ resource "azurerm_network_interface" "test" { fastpathenabled = "true" } } -`, r.template(data), data.RandomInteger, data.Locations.Primary, mode, sku) +`, r.template(data), data.RandomInteger, data.Locations.Primary) } func (r NetworkInterfaceResource) withMultipleParameters(data acceptance.TestData) string { diff --git a/website/docs/r/network_interface.html.markdown b/website/docs/r/network_interface.html.markdown index f5fe847921fb..1d64db92c5bd 100644 --- a/website/docs/r/network_interface.html.markdown +++ b/website/docs/r/network_interface.html.markdown @@ -60,11 +60,11 @@ The following arguments are supported: --- -* `auxiliary_mode` - (Optional) The Auxiliary mode of the Network Interface. Possible values are `AcceleratedConnections`, `Floating` and `None`. Defaults to `None`. +* `auxiliary_mode` - (Optional) The Auxiliary mode of the Network Interface. Possible values are `AcceleratedConnections` and `Floating`. --> **Note:** This field requires the preview feature is enabled. See the [Prerequisites](https://learn.microsoft.com/en-us/azure/networking/nva-accelerated-connections#prerequisites) for more details. +* `auxiliary_sku` - (Optional) The Auxiliary SKU of the Network Interface. Possible values are `A1`, `A2`, `A4` and `A8`. -* `auxiliary_sku` - (Optional) The Auxiliary SKU of the Network Interface. Possible values are `A1`, `A2`, `A4`, `A8` and `None`. Defaults to `None`. +-> **Note:** `auxiliary_mode` and `auxiliary_sku` require the preview feature is enabled. See the [Prerequisites](https://learn.microsoft.com/en-us/azure/networking/nva-accelerated-connections#prerequisites) for more details. * `dns_servers` - (Optional) A list of IP Addresses defining the DNS Servers which should be used for this Network Interface. From 3d23252d066670919881212464ea684ef5398dc4 Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Fri, 18 Aug 2023 09:48:49 +0800 Subject: [PATCH 3/5] resolve comments 0818 --- website/docs/r/network_interface.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/r/network_interface.html.markdown b/website/docs/r/network_interface.html.markdown index 1d64db92c5bd..9a8fec115cf5 100644 --- a/website/docs/r/network_interface.html.markdown +++ b/website/docs/r/network_interface.html.markdown @@ -60,9 +60,9 @@ The following arguments are supported: --- -* `auxiliary_mode` - (Optional) The Auxiliary mode of the Network Interface. Possible values are `AcceleratedConnections` and `Floating`. +* `auxiliary_mode` - (Optional) Specifies auxiliary mode for enabling [Accelerated Connections](https://learn.microsoft.com/en-us/azure/networking/nva-accelerated-connections) to improve networking performance. Possible values are `AcceleratedConnections` and `Floating`. -* `auxiliary_sku` - (Optional) The Auxiliary SKU of the Network Interface. Possible values are `A1`, `A2`, `A4` and `A8`. +* `auxiliary_sku` - (Optional) Specifies auxiliary SKU for tuning the performance of network connections. Possible values are `A1`, `A2`, `A4` and `A8`. -> **Note:** `auxiliary_mode` and `auxiliary_sku` require the preview feature is enabled. See the [Prerequisites](https://learn.microsoft.com/en-us/azure/networking/nva-accelerated-connections#prerequisites) for more details. From 401ed5a51d655a7b018eaf1cc3d01a16a50a33b9 Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Wed, 6 Sep 2023 10:07:34 +0800 Subject: [PATCH 4/5] resolve comments 0906 --- .../network/network_interface_resource.go | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/internal/services/network/network_interface_resource.go b/internal/services/network/network_interface_resource.go index 05c25d803071..4b92389afa0a 100644 --- a/internal/services/network/network_interface_resource.go +++ b/internal/services/network/network_interface_resource.go @@ -127,24 +127,16 @@ func resourceNetworkInterface() *pluginsdk.Resource { // Optional "auxiliary_mode": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice([]string{ - string(networkinterfaces.NetworkInterfaceAuxiliaryModeAcceleratedConnections), - string(networkinterfaces.NetworkInterfaceAuxiliaryModeFloating), - }, false), + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice(networkinterfaces.PossibleValuesForNetworkInterfaceAuxiliaryMode(), false), RequiredWith: []string{"auxiliary_sku"}, }, "auxiliary_sku": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice([]string{ - string(networkinterfaces.NetworkInterfaceAuxiliarySkuAEight), - string(networkinterfaces.NetworkInterfaceAuxiliarySkuAFour), - string(networkinterfaces.NetworkInterfaceAuxiliarySkuAOne), - string(networkinterfaces.NetworkInterfaceAuxiliarySkuATwo), - }, false), + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice(networkinterfaces.PossibleValuesForNetworkInterfaceAuxiliarySku(), false), RequiredWith: []string{"auxiliary_mode"}, }, From e553b9be17819231402dc59bec26732729b6f97e Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Thu, 14 Sep 2023 10:21:10 +0800 Subject: [PATCH 5/5] resolve comments 0914 --- website/docs/r/network_interface.html.markdown | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/website/docs/r/network_interface.html.markdown b/website/docs/r/network_interface.html.markdown index 9a8fec115cf5..a99bf6e523c0 100644 --- a/website/docs/r/network_interface.html.markdown +++ b/website/docs/r/network_interface.html.markdown @@ -60,11 +60,13 @@ The following arguments are supported: --- -* `auxiliary_mode` - (Optional) Specifies auxiliary mode for enabling [Accelerated Connections](https://learn.microsoft.com/en-us/azure/networking/nva-accelerated-connections) to improve networking performance. Possible values are `AcceleratedConnections` and `Floating`. +* `auxiliary_mode` - (Optional) Specifies the auxiliary mode used to enable network high-performance feature on Network Virtual Appliances (NVAs). This feature offers competitive performance in Connections Per Second (CPS) optimization, along with improvements to handling large amounts of simultaneous connections. Possible values are `AcceleratedConnections` and `Floating`. -* `auxiliary_sku` - (Optional) Specifies auxiliary SKU for tuning the performance of network connections. Possible values are `A1`, `A2`, `A4` and `A8`. +-> **Note:** `auxiliary_mode` is in **Preview** and requires that the preview is enabled - [more information can be found in the Azure documentation](https://learn.microsoft.com/azure/networking/nva-accelerated-connections#prerequisites). --> **Note:** `auxiliary_mode` and `auxiliary_sku` require the preview feature is enabled. See the [Prerequisites](https://learn.microsoft.com/en-us/azure/networking/nva-accelerated-connections#prerequisites) for more details. +* `auxiliary_sku` - (Optional) Specifies the SKU used for the network high-performance feature on Network Virtual Appliances (NVAs). Possible values are `A1`, `A2`, `A4` and `A8`. + +-> **Note:** `auxiliary_sku` is in **Preview** and requires that the preview is enabled - [more information can be found in the Azure documentation](https://learn.microsoft.com/azure/networking/nva-accelerated-connections#prerequisites). * `dns_servers` - (Optional) A list of IP Addresses defining the DNS Servers which should be used for this Network Interface.