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

New Resource: azurerm_route_map #19402

Merged
merged 8 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions .github/labeler-pull-request-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ service/mysql:
service/netapp:
- internal/services/netapp/**/*

service/network:
- internal/services/network/**/*

service/nginx:
- internal/services/nginx/**/*

Expand Down
1 change: 1 addition & 0 deletions internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration {
loganalytics.Registration{},
monitor.Registration{},
mssql.Registration{},
network.Registration{},
nginx.Registration{},
policy.Registration{},
privatednsresolver.Registration{},
Expand Down
5 changes: 5 additions & 0 deletions internal/services/network/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Client struct {
PrivateEndpointClient *network.PrivateEndpointsClient
PublicIPsClient *network.PublicIPAddressesClient
PublicIPPrefixesClient *network.PublicIPPrefixesClient
RouteMapsClient *network.RouteMapsClient
RoutesClient *network.RoutesClient
RouteFiltersClient *network.RouteFiltersClient
RouteTablesClient *network.RouteTablesClient
Expand Down Expand Up @@ -158,6 +159,9 @@ func NewClient(o *common.ClientOptions) *Client {
PrivateLinkServiceClient := network.NewPrivateLinkServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&PrivateLinkServiceClient.Client, o.ResourceManagerAuthorizer)

RouteMapsClient := network.NewRouteMapsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&RouteMapsClient.Client, o.ResourceManagerAuthorizer)

RoutesClient := network.NewRoutesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&RoutesClient.Client, o.ResourceManagerAuthorizer)

Expand Down Expand Up @@ -260,6 +264,7 @@ func NewClient(o *common.ClientOptions) *Client {
PrivateEndpointClient: &PrivateEndpointClient,
PublicIPsClient: &PublicIPsClient,
PublicIPPrefixesClient: &PublicIPPrefixesClient,
RouteMapsClient: &RouteMapsClient,
RoutesClient: &RoutesClient,
RouteFiltersClient: &RouteFiltersClient,
RouteTablesClient: &RouteTablesClient,
Expand Down
75 changes: 75 additions & 0 deletions internal/services/network/parse/route_map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"
"strings"

"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

type RouteMapId struct {
SubscriptionId string
ResourceGroup string
VirtualHubName string
Name string
}

func NewRouteMapID(subscriptionId, resourceGroup, virtualHubName, name string) RouteMapId {
return RouteMapId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
VirtualHubName: virtualHubName,
Name: name,
}
}

func (id RouteMapId) String() string {
segments := []string{
fmt.Sprintf("Name %q", id.Name),
fmt.Sprintf("Virtual Hub Name %q", id.VirtualHubName),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Route Map", segmentsStr)
}

func (id RouteMapId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualHubs/%s/routeMaps/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.VirtualHubName, id.Name)
}

// RouteMapID parses a RouteMap ID into an RouteMapId struct
func RouteMapID(input string) (*RouteMapId, error) {
id, err := resourceids.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

resourceId := RouteMapId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}

if resourceId.VirtualHubName, err = id.PopSegment("virtualHubs"); err != nil {
return nil, err
}
if resourceId.Name, err = id.PopSegment("routeMaps"); err != nil {
return nil, err
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &resourceId, nil
}
128 changes: 128 additions & 0 deletions internal/services/network/parse/route_map_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"testing"

"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

var _ resourceids.Id = RouteMapId{}

func TestRouteMapIDFormatter(t *testing.T) {
actual := NewRouteMapID("12345678-1234-9876-4563-123456789012", "resGroup1", "vhub1", "routeMap1").ID()
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/virtualHubs/vhub1/routeMaps/routeMap1"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
}

func TestRouteMapID(t *testing.T) {
testData := []struct {
Input string
Error bool
Expected *RouteMapId
}{

{
// empty
Input: "",
Error: true,
},

{
// missing SubscriptionId
Input: "/",
Error: true,
},

{
// missing value for SubscriptionId
Input: "/subscriptions/",
Error: true,
},

{
// missing ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/",
Error: true,
},

{
// missing value for ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/",
Error: true,
},

{
// missing VirtualHubName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/",
Error: true,
},

{
// missing value for VirtualHubName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/virtualHubs/",
Error: true,
},

{
// missing Name
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/virtualHubs/vhub1/",
Error: true,
},

{
// missing value for Name
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/virtualHubs/vhub1/routeMaps/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/virtualHubs/vhub1/routeMaps/routeMap1",
Expected: &RouteMapId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "resGroup1",
VirtualHubName: "vhub1",
Name: "routeMap1",
},
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/VIRTUALHUBS/VHUB1/ROUTEMAPS/ROUTEMAP1",
Error: true,
},
}

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

actual, err := RouteMapID(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 one")
}

if actual.SubscriptionId != v.Expected.SubscriptionId {
t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId)
}
if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}
if actual.VirtualHubName != v.Expected.VirtualHubName {
t.Fatalf("Expected %q but got %q for VirtualHubName", v.Expected.VirtualHubName, actual.VirtualHubName)
}
if actual.Name != v.Expected.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name)
}
}
}
20 changes: 20 additions & 0 deletions internal/services/network/registration.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
package network

import (
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

type Registration struct{}

var (
_ sdk.TypedServiceRegistration = Registration{}
_ sdk.UntypedServiceRegistrationWithAGitHubLabel = Registration{}
)

func (r Registration) AssociatedGitHubLabel() string {
return "service/network"
}

func (r Registration) DataSources() []sdk.DataSource {
return []sdk.DataSource{}
}

func (r Registration) Resources() []sdk.Resource {
return []sdk.Resource{
RouteMapResource{},
}
}

// Name is the name of this Service
func (r Registration) Name() string {
return "Network"
Expand Down
1 change: 1 addition & 0 deletions internal/services/network/resourceids.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ package network
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VpnServerConfigurationPolicyGroup -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/vpnServerConfigurations/serverConfiguration1/configurationPolicyGroups/configurationPolicyGroup1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VpnSite -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/vpnSites/vpnSite1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VpnSiteLink -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/vpnSites/vpnSite1/vpnSiteLinks/vpnSiteLink1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=RouteMap -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/virtualHubs/vhub1/routeMaps/routeMap1

// Subnet Service Endpoint Policy
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SubnetServiceEndpointStoragePolicy -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/serviceEndpointPolicies/policy1
Expand Down
Loading