-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5916 from nxt-engineering/azurerm_app_service_vir…
…tual_network_swift_connection_slot
- Loading branch information
Showing
12 changed files
with
960 additions
and
91 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
azurerm/internal/services/web/parse/slot_virtual_network_swift_connection.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
73 changes: 73 additions & 0 deletions
73
azurerm/internal/services/web/parse/slot_virtual_network_swift_connection_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
azurerm/internal/services/web/parse/virtual_network_swift_connection.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
57 changes: 57 additions & 0 deletions
57
azurerm/internal/services/web/parse/virtual_network_swift_connection_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.