Skip to content

Commit

Permalink
Merge pull request #7517 from njuCZ/synapse_workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops authored Jul 23, 2020
2 parents 63ebff1 + 26e55ec commit df68bab
Show file tree
Hide file tree
Showing 58 changed files with 23,003 additions and 0 deletions.
3 changes: 3 additions & 0 deletions azurerm/internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import (
storage "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/client"
streamAnalytics "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/streamanalytics/client"
subscription "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/subscription/client"
synapse "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/synapse/client"
trafficManager "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/trafficmanager/client"
web "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web/client"
)
Expand Down Expand Up @@ -161,6 +162,7 @@ type Client struct {
StreamAnalytics *streamAnalytics.Client
Subscription *subscription.Client
Sql *sql.Client
Synapse *synapse.Client
TrafficManager *trafficManager.Client
Web *web.Client
}
Expand Down Expand Up @@ -245,6 +247,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.Storage = storage.NewClient(o)
client.StreamAnalytics = streamAnalytics.NewClient(o)
client.Subscription = subscription.NewClient(o)
client.Synapse = synapse.NewClient(o)
client.TrafficManager = trafficManager.NewClient(o)
client.Web = web.NewClient(o)

Expand Down
2 changes: 2 additions & 0 deletions azurerm/internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/streamanalytics"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/subscription"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/synapse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/trafficmanager"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web"
)
Expand Down Expand Up @@ -153,6 +154,7 @@ func SupportedServices() []common.ServiceRegistration {
storage.Registration{},
streamanalytics.Registration{},
subscription.Registration{},
synapse.Registration{},
iottimeseriesinsights.Registration{},
trafficmanager.Registration{},
web.Registration{},
Expand Down
24 changes: 24 additions & 0 deletions azurerm/internal/services/synapse/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/preview/synapse/mgmt/2019-06-01-preview/synapse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
WorkspaceClient *synapse.WorkspacesClient
WorkspaceAadAdminsClient *synapse.WorkspaceAadAdminsClient
}

func NewClient(o *common.ClientOptions) *Client {
workspaceClient := synapse.NewWorkspacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&workspaceClient.Client, o.ResourceManagerAuthorizer)

workspaceAadAdminsClient := synapse.NewWorkspaceAadAdminsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&workspaceAadAdminsClient.Client, o.ResourceManagerAuthorizer)

return &Client{
WorkspaceClient: &workspaceClient,
WorkspaceAadAdminsClient: &workspaceAadAdminsClient,
}
}
31 changes: 31 additions & 0 deletions azurerm/internal/services/synapse/parse/synapse_workspace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package parse

import (
"fmt"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type SynapseWorkspaceId struct {
ResourceGroup string
Name string
}

func SynapseWorkspaceID(input string) (*SynapseWorkspaceId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("parsing synapseWorkspace ID %q: %+v", input, err)
}

synapseWorkspace := SynapseWorkspaceId{
ResourceGroup: id.ResourceGroup,
}
if synapseWorkspace.Name, err = id.PopSegment("workspaces"); err != nil {
return nil, err
}
if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &synapseWorkspace, nil
}
72 changes: 72 additions & 0 deletions azurerm/internal/services/synapse/parse/synapse_workspace_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package parse

import (
"testing"
)

func TestSynapseWorkspaceID(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *SynapseWorkspaceId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "No Resource Groups Segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000",
Expected: nil,
},
{
Name: "No Resource Groups Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/",
Expected: nil,
},
{
Name: "Resource Group ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/",
Expected: nil,
},
{
Name: "Missing Workspace Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Synapse/workspaces",
Expected: nil,
},
{
Name: "synapse Workspace ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Synapse/workspaces/workspace1",
Expected: &SynapseWorkspaceId{
ResourceGroup: "resourceGroup1",
Name: "workspace1",
},
},
{
Name: "Wrong Casing",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Synapse/Workspaces/workspace1",
Expected: nil,
},
}

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

actual, err := SynapseWorkspaceID(v.Input)
if err != nil {
if v.Expected == nil {
continue
}
t.Fatalf("Expected a value but got an error: %s", err)
}

if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}

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

import "github.com/hashicorp/terraform-plugin-sdk/helper/schema"

type Registration struct{}

// Name is the name of this Service
func (r Registration) Name() string {
return "Synapse"
}

// WebsiteCategories returns a list of categories which can be used for the sidebar
func (r Registration) WebsiteCategories() []string {
return []string{
"Synapse",
}
}

// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_synapse_workspace": dataSourceSynapseWorkspace(),
}
}

// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_synapse_workspace": resourceArmSynapseWorkspace(),
}
}
76 changes: 76 additions & 0 deletions azurerm/internal/services/synapse/synapse_workspace_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package synapse

import (
"fmt"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/location"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/synapse/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceSynapseWorkspace() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmSynapseWorkspaceRead,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.SynapseWorkspaceName,
},

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"location": azure.SchemaLocationForDataSource(),

"connectivity_endpoints": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"tags": tags.SchemaDataSource(),
},
}
}

func dataSourceArmSynapseWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Synapse.WorkspaceClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("synapse Workspace %q does not exist", name)
}
return fmt.Errorf("retrieving Synapse Workspace %q (Resource Group %q): %+v", name, resourceGroup, err)
}
if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("empty or nil ID returned for Synapse Workspace %q (Resource Group %q) ID", name, resourceGroup)
}

d.SetId(*resp.ID)
d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
d.Set("location", location.NormalizeNilable(resp.Location))
if props := resp.WorkspaceProperties; props != nil {
d.Set("connectivity_endpoints", utils.FlattenMapStringPtrString(props.ConnectivityEndpoints))
}
return tags.FlattenAndSet(d, resp.Tags)
}
Loading

0 comments on commit df68bab

Please sign in to comment.