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

Fork Sync: Update from parent repository #7

Merged
merged 2 commits into from
Sep 18, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ func resourceApiManagementApiCreateUpdate(d *pluginsdk.ResourceData, meta interf
ApiVersion: pointer.To(version),
},
}

if v, ok := d.GetOk("service_url"); ok {
apiParams.Properties.ServiceUrl = pointer.To(v.(string))
}

wsdlSelectorVs := importV["wsdl_selector"].([]interface{})

if len(wsdlSelectorVs) > 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,44 @@ func TestAccApiManagementApi_importSwagger(t *testing.T) {
})
}

func TestAccApiManagementApi_importSwaggerWithServiceUrl(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test")
r := ApiManagementApiResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.importSwaggerWithServiceUrl(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
{
ResourceName: data.ResourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
// not returned from the API
"import",
},
},
{
Config: r.importSwaggerWithServiceUrlUpdate(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
{
ResourceName: data.ResourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
// not returned from the API
"import",
},
},
})
}

func TestAccApiManagementApi_importWsdl(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test")
r := ApiManagementApiResource{}
Expand Down Expand Up @@ -606,6 +644,52 @@ resource "azurerm_api_management_api" "test" {
`, r.template(data, SkuNameConsumption), data.RandomInteger)
}

func (r ApiManagementApiResource) importSwaggerWithServiceUrl(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_api_management_api" "test" {
name = "acctestapi-%d"
resource_group_name = azurerm_resource_group.test.name
api_management_name = azurerm_api_management.test.name
display_name = "api1"
path = "api1"
protocols = ["https"]
revision = "1"
description = "import swagger"
service_url = "https://example.com/foo/bar"

import {
content_value = file("testdata/api_management_api_swagger.json")
content_format = "swagger-json"
}
}
`, r.template(data, SkuNameConsumption), data.RandomInteger)
}

func (r ApiManagementApiResource) importSwaggerWithServiceUrlUpdate(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_api_management_api" "test" {
name = "acctestapi-%d"
resource_group_name = azurerm_resource_group.test.name
api_management_name = azurerm_api_management.test.name
display_name = "api1"
path = "api1"
protocols = ["https"]
revision = "1"
description = "import swagger update"
service_url = "https://example.com/foo/bar"

import {
content_value = file("testdata/api_management_api_swagger.json")
content_format = "swagger-json"
}
}
`, r.template(data, SkuNameConsumption), data.RandomInteger)
}

func (r ApiManagementApiResource) importWsdl(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down
51 changes: 51 additions & 0 deletions internal/services/network/network_interface_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ func resourceNetworkInterface() *pluginsdk.Resource {
},

// Optional
"auxiliary_mode": {
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(networkinterfaces.PossibleValuesForNetworkInterfaceAuxiliarySku(), false),
RequiredWith: []string{"auxiliary_mode"},
},

"dns_servers": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -232,6 +246,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 {
Expand Down Expand Up @@ -325,6 +347,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)
Expand Down Expand Up @@ -462,6 +500,19 @@ func resourceNetworkInterfaceRead(d *pluginsdk.ResourceData, meta interface{}) e
return fmt.Errorf("setting `applied_dns_servers`: %+v", err)
}

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)
Expand Down
84 changes: 84 additions & 0 deletions internal/services/network/network_interface_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.auxiliaryNone(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.auxiliaryAcceleratedConnections(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.auxiliaryNone(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{}
Expand Down Expand Up @@ -388,6 +416,62 @@ resource "azurerm_network_interface" "test" {
`, r.template(data), data.RandomInteger)
}

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"

return fmt.Sprintf(`
%s

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
auxiliary_mode = "AcceleratedConnections"
auxiliary_sku = "A2"
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) withMultipleParameters(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/network_interface.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ The following arguments are supported:

---

* `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`.

-> **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).

* `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.

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