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

Support for Edge Zones #15890

Merged
merged 14 commits into from
Mar 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions internal/services/network/edge_zone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package network

import (
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-05-01/network"
"github.com/hashicorp/go-azure-helpers/resourcemanager/edgezones"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

func expandEdgeZone(input string) *network.ExtendedLocation {
normalized := edgezones.Normalize(input)
if normalized == "" {
return nil
}

return &network.ExtendedLocation{
Name: utils.String(normalized),
Type: network.ExtendedLocationTypesEdgeZone,
}
}

func flattenEdgeZone(input *network.ExtendedLocation) string {
if input == nil || input.Type != network.ExtendedLocationTypesEdgeZone || input.Name == nil {
return ""
}
return edgezones.NormalizeNilable(input.Name)
}
16 changes: 11 additions & 5 deletions internal/services/network/network_interface_resource.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ package network

import (
"fmt"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"log"
"time"

@@ -119,6 +121,7 @@ func resourceNetworkInterface() *pluginsdk.Resource {
},
},

// Optional
"dns_servers": {
Type: pluginsdk.TypeList,
Optional: true,
@@ -129,6 +132,8 @@ func resourceNetworkInterface() *pluginsdk.Resource {
},
},

"edge_zone": commonschema.EdgeZoneOptionalForceNew(),

// TODO 4.0: change this from enable_* to *_enabled
"enable_accelerated_networking": {
Type: pluginsdk.TypeBool,
@@ -262,6 +267,7 @@ func resourceNetworkInterfaceCreate(d *pluginsdk.ResourceData, meta interface{})

iface := network.Interface{
Name: utils.String(id.Name),
ExtendedLocation: expandEdgeZone(d.Get("edge_zone").(string)),
Location: utils.String(location),
InterfacePropertiesFormat: &properties,
Tags: tags.Expand(t),
@@ -308,8 +314,9 @@ func resourceNetworkInterfaceUpdate(d *pluginsdk.ResourceData, meta interface{})

location := azure.NormalizeLocation(d.Get("location").(string))
update := network.Interface{
Name: utils.String(id.Name),
Location: utils.String(location),
Name: utils.String(id.Name),
ExtendedLocation: expandEdgeZone(d.Get("edge_zone").(string)),
Location: utils.String(location),
InterfacePropertiesFormat: &network.InterfacePropertiesFormat{
EnableAcceleratedNetworking: utils.Bool(d.Get("enable_accelerated_networking").(bool)),
DNSSettings: &network.InterfaceDNSSettings{},
@@ -401,9 +408,8 @@ func resourceNetworkInterfaceRead(d *pluginsdk.ResourceData, meta interface{}) e

d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}
d.Set("location", location.NormalizeNilable(resp.Location))
d.Set("edge_zone", flattenEdgeZone(resp.ExtendedLocation))

if props := resp.InterfacePropertiesFormat; props != nil {
primaryPrivateIPAddress := ""
40 changes: 40 additions & 0 deletions internal/services/network/network_interface_resource_test.go
Original file line number Diff line number Diff line change
@@ -61,6 +61,20 @@ func TestAccNetworkInterface_dnsServers(t *testing.T) {
})
}

func TestAccNetworkInterface_edgeZone(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_network_interface", "test")
r := NetworkInterfaceResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.edgeZone(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccNetworkInterface_enableAcceleratedNetworking(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_network_interface", "test")
r := NetworkInterfaceResource{}
@@ -478,6 +492,32 @@ resource "azurerm_network_interface" "test" {
`, r.template(data), data.RandomInteger)
}

func (r NetworkInterfaceResource) edgeZone(data acceptance.TestData) string {
// @tombuildsstuff: WestUS has an edge zone available - so hard-code to that for now
data.Locations.Primary = "westus"

return fmt.Sprintf(`
%[1]s

data "azurerm_extended_locations" "test" {
location = azurerm_resource_group.test.location
}

resource "azurerm_network_interface" "test" {
name = "acctestni-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
edge_zone = data.azurerm_extended_locations.test.extended_locations[0]

ip_configuration {
name = "primary"
subnet_id = azurerm_subnet.test.id
private_ip_address_allocation = "Dynamic"
}
}
`, r.template(data), data.RandomInteger)
}

func (r NetworkInterfaceResource) enableAcceleratedNetworking(data acceptance.TestData, enabled bool) string {
return fmt.Sprintf(`
%s
2 changes: 2 additions & 0 deletions website/docs/r/network_interface.html.markdown
Original file line number Diff line number Diff line change
@@ -64,6 +64,8 @@ The following arguments are supported:

-> **Note:** Configuring DNS Servers on the Network Interface will override the DNS Servers defined on the Virtual Network.

* `edge_zone` - (Optional) Specifies the Edge Zone within the Azure Region where this Network Interface should exist. Changing this forces a new Network Interface to be created.

* `enable_ip_forwarding` - (Optional) Should IP Forwarding be enabled? Defaults to `false`.

* `enable_accelerated_networking` - (Optional) Should Accelerated Networking be enabled? Defaults to `false`.