Skip to content

Commit

Permalink
add resource "azurerm_synapse_integration_runtime_self_hosted" (#13264)
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-henglu authored Sep 13, 2021
1 parent f430ac7 commit 2b6f271
Show file tree
Hide file tree
Showing 11 changed files with 754 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ func resourceDataFactoryIntegrationRuntimeSelfHosted() *pluginsdk.Resource {
},
},

// todo: rename to authorization_key_primary in v3.0
"auth_key_1": {
Type: pluginsdk.TypeString,
Computed: true,
},

// todo: rename to authorization_key_secondary in v3.0
"auth_key_2": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down
10 changes: 10 additions & 0 deletions internal/services/synapse/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

type Client struct {
FirewallRulesClient *synapse.IPFirewallRulesClient
IntegrationRuntimesClient *synapse.IntegrationRuntimesClient
IntegrationRuntimeAuthKeysClient *synapse.IntegrationRuntimeAuthKeysClient
PrivateLinkHubsClient *synapse.PrivateLinkHubsClient
SparkPoolClient *synapse.BigDataPoolsClient
SqlPoolClient *synapse.SQLPoolsClient
Expand All @@ -27,6 +29,12 @@ func NewClient(o *common.ClientOptions) *Client {
firewallRuleClient := synapse.NewIPFirewallRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&firewallRuleClient.Client, o.ResourceManagerAuthorizer)

integrationRuntimesClient := synapse.NewIntegrationRuntimesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&integrationRuntimesClient.Client, o.ResourceManagerAuthorizer)

integrationRuntimeAuthKeysClient := synapse.NewIntegrationRuntimeAuthKeysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&integrationRuntimeAuthKeysClient.Client, o.ResourceManagerAuthorizer)

privateLinkHubsClient := synapse.NewPrivateLinkHubsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&privateLinkHubsClient.Client, o.ResourceManagerAuthorizer)

Expand All @@ -51,6 +59,8 @@ func NewClient(o *common.ClientOptions) *Client {

return &Client{
FirewallRulesClient: &firewallRuleClient,
IntegrationRuntimesClient: &integrationRuntimesClient,
IntegrationRuntimeAuthKeysClient: &integrationRuntimeAuthKeysClient,
PrivateLinkHubsClient: &privateLinkHubsClient,
SparkPoolClient: &sparkPoolClient,
SqlPoolClient: &sqlPoolClient,
Expand Down
75 changes: 75 additions & 0 deletions internal/services/synapse/parse/integration_runtime.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/terraform-provider-azurerm/helpers/azure"
)

type IntegrationRuntimeId struct {
SubscriptionId string
ResourceGroup string
WorkspaceName string
Name string
}

func NewIntegrationRuntimeID(subscriptionId, resourceGroup, workspaceName, name string) IntegrationRuntimeId {
return IntegrationRuntimeId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
WorkspaceName: workspaceName,
Name: name,
}
}

func (id IntegrationRuntimeId) String() string {
segments := []string{
fmt.Sprintf("Name %q", id.Name),
fmt.Sprintf("Workspace Name %q", id.WorkspaceName),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Integration Runtime", segmentsStr)
}

func (id IntegrationRuntimeId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/integrationruntimes/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.WorkspaceName, id.Name)
}

// IntegrationRuntimeID parses a IntegrationRuntime ID into an IntegrationRuntimeId struct
func IntegrationRuntimeID(input string) (*IntegrationRuntimeId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

resourceId := IntegrationRuntimeId{
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.WorkspaceName, err = id.PopSegment("workspaces"); err != nil {
return nil, err
}
if resourceId.Name, err = id.PopSegment("integrationruntimes"); 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/synapse/parse/integration_runtime_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/terraform-provider-azurerm/internal/resourceid"
)

var _ resourceid.Formatter = IntegrationRuntimeId{}

func TestIntegrationRuntimeIDFormatter(t *testing.T) {
actual := NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "resGroup1", "workspace1", "IntegrationRuntime1").ID()
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/workspace1/integrationruntimes/IntegrationRuntime1"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
}

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

{
// 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 WorkspaceName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/",
Error: true,
},

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

{
// missing Name
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/workspace1/",
Error: true,
},

{
// missing value for Name
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/workspace1/integrationruntimes/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/workspace1/integrationruntimes/IntegrationRuntime1",
Expected: &IntegrationRuntimeId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "resGroup1",
WorkspaceName: "workspace1",
Name: "IntegrationRuntime1",
},
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.SYNAPSE/WORKSPACES/WORKSPACE1/INTEGRATIONRUNTIMES/INTEGRATIONRUNTIME1",
Error: true,
},
}

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

actual, err := IntegrationRuntimeID(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.WorkspaceName != v.Expected.WorkspaceName {
t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName)
}
if actual.Name != v.Expected.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name)
}
}
}
15 changes: 8 additions & 7 deletions internal/services/synapse/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource {
// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*pluginsdk.Resource {
return map[string]*pluginsdk.Resource{
"azurerm_synapse_firewall_rule": resourceSynapseFirewallRule(),
"azurerm_synapse_private_link_hub": resourceSynapsePrivateLinkHub(),
"azurerm_synapse_managed_private_endpoint": resourceSynapseManagedPrivateEndpoint(),
"azurerm_synapse_role_assignment": resourceSynapseRoleAssignment(),
"azurerm_synapse_spark_pool": resourceSynapseSparkPool(),
"azurerm_synapse_sql_pool": resourceSynapseSqlPool(),
"azurerm_synapse_workspace": resourceSynapseWorkspace(),
"azurerm_synapse_firewall_rule": resourceSynapseFirewallRule(),
"azurerm_synapse_integration_runtime_self_hosted": resourceSynapseIntegrationRuntimeSelfHosted(),
"azurerm_synapse_private_link_hub": resourceSynapsePrivateLinkHub(),
"azurerm_synapse_managed_private_endpoint": resourceSynapseManagedPrivateEndpoint(),
"azurerm_synapse_role_assignment": resourceSynapseRoleAssignment(),
"azurerm_synapse_spark_pool": resourceSynapseSparkPool(),
"azurerm_synapse_sql_pool": resourceSynapseSqlPool(),
"azurerm_synapse_workspace": resourceSynapseWorkspace(),
}
}
1 change: 1 addition & 0 deletions internal/services/synapse/resourceids.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ package synapse
//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
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=IntegrationRuntime -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/workspace1/integrationruntimes/IntegrationRuntime1
Loading

0 comments on commit 2b6f271

Please sign in to comment.