-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new resource: azurerm_vpn_site (#8896)
Co-authored-by: kt <[email protected]>
- Loading branch information
Showing
12 changed files
with
1,289 additions
and
0 deletions.
There are no files selected for viewing
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
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,45 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type VirtualWanId struct { | ||
ResourceGroup string | ||
Name string | ||
} | ||
|
||
func (id VirtualWanId) ID(subscriptionId string) string { | ||
return fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualWans/%s", | ||
subscriptionId, id.ResourceGroup, id.Name) | ||
} | ||
|
||
func NewVirtualWanID(resourceGroup, name string) VirtualWanId { | ||
return VirtualWanId{ | ||
ResourceGroup: resourceGroup, | ||
Name: name, | ||
} | ||
} | ||
|
||
func VirtualWanID(input string) (*VirtualWanId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing Virtual Wan ID %q: %+v", input, err) | ||
} | ||
|
||
vwanId := VirtualWanId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if vwanId.Name, err = id.PopSegment("virtualWans"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &vwanId, nil | ||
} |
90 changes: 90 additions & 0 deletions
90
azurerm/internal/services/network/parse/virtual_wan_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,90 @@ | ||
package parse | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/resourceid" | ||
) | ||
|
||
var _ resourceid.Formatter = VirtualWanId{} | ||
|
||
func TestVirtualWanIDFormatter(t *testing.T) { | ||
subscriptionId := "12345678-1234-5678-1234-123456789012" | ||
actual := NewVirtualWanID("group1", "wan1").ID(subscriptionId) | ||
expected := "/subscriptions/12345678-1234-5678-1234-123456789012/resourceGroups/group1/providers/Microsoft.Network/virtualWans/wan1" | ||
if actual != expected { | ||
t.Fatalf("Expected %q but got %q", expected, actual) | ||
} | ||
} | ||
|
||
func TestVirtualWanID(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Error bool | ||
Expect *VirtualWanId | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "No Resource Groups Segment", | ||
Input: "/subscriptions/11111111-1111-1111-1111-111111111111", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "No Resource Groups Value", | ||
Input: "/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Missing leading slash", | ||
Input: "subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/group1", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Malformed segments", | ||
Input: "/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/group1/foo/bar", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Missing vwan segment", | ||
Input: "subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/group1/providers/Microsoft.Network", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Correct", | ||
Input: "/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/group1/providers/Microsoft.Network/virtualWans/wan1", | ||
Expect: &VirtualWanId{ | ||
ResourceGroup: "group1", | ||
Name: "wan1", | ||
}, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := VirtualWanID(v.Input) | ||
if err != nil { | ||
if v.Error { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expect a value but got an error: %s", err) | ||
} | ||
if v.Error { | ||
t.Fatal("Expect an error but didn't get") | ||
} | ||
|
||
if actual.ResourceGroup != v.Expect.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for Resource Group", v.Expect.ResourceGroup, actual.ResourceGroup) | ||
} | ||
|
||
if actual.Name != v.Expect.Name { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expect.Name, actual.Name) | ||
} | ||
} | ||
} |
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,89 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type VpnSiteId struct { | ||
ResourceGroup string | ||
Name string | ||
} | ||
|
||
func (id VpnSiteId) ID(subscriptionId string) string { | ||
return fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/vpnSites/%s", | ||
subscriptionId, id.ResourceGroup, id.Name) | ||
} | ||
|
||
func NewVpnSiteID(resourceGroup, name string) VpnSiteId { | ||
return VpnSiteId{ | ||
ResourceGroup: resourceGroup, | ||
Name: name, | ||
} | ||
} | ||
|
||
func VpnSiteID(input string) (*VpnSiteId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing Vpn Site ID %q: %+v", input, err) | ||
} | ||
|
||
vpnSiteId := VpnSiteId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if vpnSiteId.Name, err = id.PopSegment("vpnSites"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &vpnSiteId, nil | ||
} | ||
|
||
type VpnSiteLinkId struct { | ||
ResourceGroup string | ||
Site string | ||
Name string | ||
} | ||
|
||
func (id VpnSiteLinkId) ID(subscriptionId string) string { | ||
return fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/vpnSites/%s/vpnSiteLinks/%s", | ||
subscriptionId, id.ResourceGroup, id.Site, id.Name) | ||
} | ||
|
||
func NewVpnSiteLinkID(vpnSiteId VpnSiteId, name string) VpnSiteLinkId { | ||
return VpnSiteLinkId{ | ||
ResourceGroup: vpnSiteId.ResourceGroup, | ||
Site: vpnSiteId.Name, | ||
Name: name, | ||
} | ||
} | ||
|
||
func VpnSiteLinkID(input string) (*VpnSiteLinkId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing Vpn Site Link ID %q: %+v", input, err) | ||
} | ||
|
||
vpnSiteLinkId := VpnSiteLinkId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if vpnSiteLinkId.Site, err = id.PopSegment("vpnSites"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if vpnSiteLinkId.Name, err = id.PopSegment("vpnSiteLinks"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &vpnSiteLinkId, nil | ||
} |
Oops, something went wrong.