Skip to content

Commit

Permalink
Merge pull request #5916 from nxt-engineering/azurerm_app_service_vir…
Browse files Browse the repository at this point in the history
…tual_network_swift_connection_slot
  • Loading branch information
jackofallops authored Jul 6, 2020
2 parents bd3be3a + 62812dd commit b65a290
Show file tree
Hide file tree
Showing 12 changed files with 960 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package parse

import (
"fmt"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type SlotVirtualNetworkSwiftConnectionId struct {
VirtualNetworkSwiftConnectionId
SlotName string
}

func SlotVirtualNetworkSwiftConnectionID(resourceId string) (*SlotVirtualNetworkSwiftConnectionId, error) {
id, err := azure.ParseAzureResourceID(resourceId)
if err != nil {
return nil, fmt.Errorf("Error parsing Azure Resource ID %q", id)
}

virtualNetworkId, err := VirtualNetworkSwiftConnectionID(resourceId)
if err != nil {
return nil, err
}

slotVirtualNetworkId := &SlotVirtualNetworkSwiftConnectionId{
VirtualNetworkSwiftConnectionId: *virtualNetworkId,
}

if slotVirtualNetworkId.SlotName, err = id.PopSegment("slots"); err != nil {
return nil, err
}

return slotVirtualNetworkId, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package parse

import (
"testing"
)

func TestSlotVirtualNetworkSwiftConnectionID(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *SlotVirtualNetworkSwiftConnectionId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "No Resource Groups Segemt",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000",
Expected: nil,
},
{
Name: "No Sites Segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Web",
Expected: nil,
},
{
Name: "No Slot Segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Web/sites/instance1",
Expected: nil,
},
{
Name: "Valid Network Association But No Slot Segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Web/sites/instance1/networkconfig/virtualNetwork",
Expected: nil,
},
{
Name: "Slot Virtual Network Association",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Web/sites/instance1/slots/stageing/networkconfig/virtualNetwork",
Expected: &SlotVirtualNetworkSwiftConnectionId{
VirtualNetworkSwiftConnectionId: VirtualNetworkSwiftConnectionId{
SiteName: "instance1",
ResourceGroup: "mygroup1",
},
SlotName: "stageing",
},
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Name)

actual, err := SlotVirtualNetworkSwiftConnectionID(v.Input)
if err != nil {
if v.Expected == nil {
continue
}

t.Fatalf("Expected a value but got an error: %s", err)
}

if actual.SiteName != v.Expected.SiteName {
t.Fatalf("Expected %q but got %q for Name", v.Expected.SiteName, actual.SiteName)
}
if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}
if actual.SlotName != v.Expected.SlotName {
t.Fatalf("Expected %q but got %q for SlotName", v.Expected.SlotName, actual.SlotName)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package parse

import (
"fmt"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type VirtualNetworkSwiftConnectionId struct {
SiteName string
ResourceGroup string
}

func VirtualNetworkSwiftConnectionID(resourceId string) (*VirtualNetworkSwiftConnectionId, error) {
id, err := azure.ParseAzureResourceID(resourceId)
if err != nil {
return nil, fmt.Errorf("Error parsing Azure Resource ID %q", id)
}

virtualNetworkId := &VirtualNetworkSwiftConnectionId{
ResourceGroup: id.ResourceGroup,
}

if virtualNetworkId.SiteName, err = id.PopSegment("sites"); err != nil {
return nil, err
}

return virtualNetworkId, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package parse

import (
"testing"
)

func TestVirtualNetworkSwiftConnectionID(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *VirtualNetworkSwiftConnectionId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "No Resource Groups Segemt",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000",
Expected: nil,
},
{
Name: "No Sites Segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Web/",
Expected: nil,
},
{
Name: "Virtual Network Association",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Web/sites/instance1/networkconfig/virtualNetwork",
Expected: &VirtualNetworkSwiftConnectionId{
SiteName: "instance1",
ResourceGroup: "mygroup1",
},
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Name)

actual, err := VirtualNetworkSwiftConnectionID(v.Input)
if err != nil {
if v.Expected == nil {
continue
}

t.Fatalf("Expected a value but got an error: %s", err)
}

if actual.SiteName != v.Expected.SiteName {
t.Fatalf("Expected %q but got %q for Name", v.Expected.SiteName, actual.SiteName)
}
if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}
}
}
27 changes: 14 additions & 13 deletions azurerm/internal/services/web/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource {
// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(),
"azurerm_app_service_certificate": resourceArmAppServiceCertificate(),
"azurerm_app_service_certificate_order": resourceArmAppServiceCertificateOrder(),
"azurerm_app_service_custom_hostname_binding": resourceArmAppServiceCustomHostnameBinding(),
"azurerm_app_service_environment": resourceArmAppServiceEnvironment(),
"azurerm_app_service_hybrid_connection": resourceArmAppServiceHybridConnection(),
"azurerm_app_service_plan": resourceArmAppServicePlan(),
"azurerm_app_service_slot": resourceArmAppServiceSlot(),
"azurerm_app_service_source_control_token": resourceArmAppServiceSourceControlToken(),
"azurerm_app_service_virtual_network_swift_connection": resourceArmAppServiceVirtualNetworkSwiftConnection(),
"azurerm_app_service": resourceArmAppService(),
"azurerm_function_app": resourceArmFunctionApp(),
"azurerm_function_app_slot": resourceArmFunctionAppSlot(),
"azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(),
"azurerm_app_service_certificate": resourceArmAppServiceCertificate(),
"azurerm_app_service_certificate_order": resourceArmAppServiceCertificateOrder(),
"azurerm_app_service_custom_hostname_binding": resourceArmAppServiceCustomHostnameBinding(),
"azurerm_app_service_environment": resourceArmAppServiceEnvironment(),
"azurerm_app_service_hybrid_connection": resourceArmAppServiceHybridConnection(),
"azurerm_app_service_plan": resourceArmAppServicePlan(),
"azurerm_app_service_slot": resourceArmAppServiceSlot(),
"azurerm_app_service_source_control_token": resourceArmAppServiceSourceControlToken(),
"azurerm_app_service_virtual_network_swift_connection": resourceArmAppServiceVirtualNetworkSwiftConnection(),
"azurerm_app_service_slot_virtual_network_swift_connection": resourceArmAppServiceSlotVirtualNetworkSwiftConnection(),
"azurerm_app_service": resourceArmAppService(),
"azurerm_function_app": resourceArmFunctionApp(),
"azurerm_function_app_slot": resourceArmFunctionAppSlot(),
}
}
Loading

0 comments on commit b65a290

Please sign in to comment.