From 94b43c8fa7b28c339078c5216112ca9a53a00952 Mon Sep 17 00:00:00 2001 From: Owen Farrell Date: Wed, 14 Jul 2021 21:18:32 -0400 Subject: [PATCH] Autogenerate Synapse Private Link Hub ID source Signed-off-by: Owen Farrell --- .../synapse/parse/private_link_hub.go | 2 +- .../internal/services/synapse/resourceids.go | 1 + .../synapse/validate/private_link_hub_id.go | 23 ++++++ .../validate/private_link_hub_id_test.go | 76 +++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 azurerm/internal/services/synapse/validate/private_link_hub_id.go create mode 100644 azurerm/internal/services/synapse/validate/private_link_hub_id_test.go diff --git a/azurerm/internal/services/synapse/parse/private_link_hub.go b/azurerm/internal/services/synapse/parse/private_link_hub.go index cc86e78a3c2d..50cadfbc5be4 100644 --- a/azurerm/internal/services/synapse/parse/private_link_hub.go +++ b/azurerm/internal/services/synapse/parse/private_link_hub.go @@ -37,7 +37,7 @@ func (id PrivateLinkHubId) ID() string { return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.Name) } -// PrivateLinkHubID parses a Private Link Hub ID into an PrivateLinkHubId struct +// PrivateLinkHubID parses a PrivateLinkHub ID into an PrivateLinkHubId struct func PrivateLinkHubID(input string) (*PrivateLinkHubId, error) { id, err := azure.ParseAzureResourceID(input) if err != nil { diff --git a/azurerm/internal/services/synapse/resourceids.go b/azurerm/internal/services/synapse/resourceids.go index 44e5b456af33..19a9765b2362 100644 --- a/azurerm/internal/services/synapse/resourceids.go +++ b/azurerm/internal/services/synapse/resourceids.go @@ -6,3 +6,4 @@ package synapse //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SqlPool -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/workspace1/sqlPools/sqlPool1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Workspace -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/workspace1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=ManagedPrivateEndpoint -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/workspace1/managedVirtualNetworks/default/managedPrivateEndpoints/endpoint1 +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=PrivateLinkHub -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHub1 diff --git a/azurerm/internal/services/synapse/validate/private_link_hub_id.go b/azurerm/internal/services/synapse/validate/private_link_hub_id.go new file mode 100644 index 000000000000..142fd407b59c --- /dev/null +++ b/azurerm/internal/services/synapse/validate/private_link_hub_id.go @@ -0,0 +1,23 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/synapse/parse" +) + +func PrivateLinkHubID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := parse.PrivateLinkHubID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/azurerm/internal/services/synapse/validate/private_link_hub_id_test.go b/azurerm/internal/services/synapse/validate/private_link_hub_id_test.go new file mode 100644 index 000000000000..f714c73b41b9 --- /dev/null +++ b/azurerm/internal/services/synapse/validate/private_link_hub_id_test.go @@ -0,0 +1,76 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestPrivateLinkHubID(t *testing.T) { + cases := []struct { + Input string + Valid bool + }{ + + { + // empty + Input: "", + Valid: false, + }, + + { + // missing SubscriptionId + Input: "/", + Valid: false, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Valid: false, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Valid: false, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Valid: false, + }, + + { + // missing Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/", + Valid: false, + }, + + { + // missing value for Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/privateLinkHubs/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHub1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.SYNAPSE/PRIVATELINKHUBS/PRIVATELINKHUB1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := PrivateLinkHubID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +}