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_machine_learning_workspace #5696

Merged
merged 11 commits into from
Mar 24, 2020
3 changes: 3 additions & 0 deletions azurerm/internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
kusto "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/kusto/client"
loganalytics "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics/client"
logic "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/logic/client"
machinelearning "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/machinelearning/client"
managementgroup "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/managementgroup/client"
maps "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/maps/client"
mariadb "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mariadb/client"
Expand Down Expand Up @@ -111,6 +112,7 @@ type Client struct {
Kusto *kusto.Client
LogAnalytics *loganalytics.Client
Logic *logic.Client
MachineLearning *machinelearning.Client
ManagementGroups *managementgroup.Client
Maps *maps.Client
MariaDB *mariadb.Client
Expand Down Expand Up @@ -185,6 +187,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.Kusto = kusto.NewClient(o)
client.LogAnalytics = loganalytics.NewClient(o)
client.Logic = logic.NewClient(o)
client.MachineLearning = machinelearning.NewClient(o)
client.ManagementGroups = managementgroup.NewClient(o)
client.Maps = maps.NewClient(o)
client.MariaDB = mariadb.NewClient(o)
Expand Down
107 changes: 54 additions & 53 deletions azurerm/internal/provider/required_resource_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,60 @@ import (
func RequiredResourceProviders() map[string]struct{} {
// NOTE: Resource Providers in this list are case sensitive
return map[string]struct{}{
"Microsoft.ApiManagement": {},
"Microsoft.Authorization": {},
"Microsoft.Automation": {},
"Microsoft.BotService": {},
"Microsoft.Cache": {},
"Microsoft.Cdn": {},
"Microsoft.CognitiveServices": {},
"Microsoft.Compute": {},
"Microsoft.ContainerInstance": {},
"Microsoft.ContainerRegistry": {},
"Microsoft.ContainerService": {},
"Microsoft.CostManagement": {},
"Microsoft.Databricks": {},
"Microsoft.DataLakeAnalytics": {},
"Microsoft.DataLakeStore": {},
"Microsoft.DataMigration": {},
"Microsoft.DBforMySQL": {},
"Microsoft.DBforPostgreSQL": {},
"Microsoft.Devices": {},
"Microsoft.DevSpaces": {},
"Microsoft.DevTestLab": {},
"Microsoft.DocumentDB": {},
"Microsoft.EventGrid": {},
"Microsoft.EventHub": {},
"Microsoft.HDInsight": {},
"Microsoft.Healthcare": {},
"Microsoft.KeyVault": {},
"Microsoft.Kusto": {},
"microsoft.insights": {},
"Microsoft.Logic": {},
"Microsoft.ManagedIdentity": {},
"Microsoft.Management": {},
"Microsoft.Maps": {},
"Microsoft.MarketplaceOrdering": {},
"Microsoft.Media": {},
"Microsoft.MixedReality": {},
"Microsoft.Network": {},
"Microsoft.NotificationHubs": {},
"Microsoft.OperationalInsights": {},
"Microsoft.OperationsManagement": {},
"Microsoft.PowerBIDedicated": {},
"Microsoft.Relay": {},
"Microsoft.RecoveryServices": {},
"Microsoft.Resources": {},
"Microsoft.Search": {},
"Microsoft.Security": {},
"Microsoft.ServiceBus": {},
"Microsoft.ServiceFabric": {},
"Microsoft.Sql": {},
"Microsoft.Storage": {},
"Microsoft.StorageCache": {},
"Microsoft.StreamAnalytics": {},
"Microsoft.Web": {},
"Microsoft.ApiManagement": {},
"Microsoft.Authorization": {},
"Microsoft.Automation": {},
"Microsoft.BotService": {},
"Microsoft.Cache": {},
"Microsoft.Cdn": {},
"Microsoft.CognitiveServices": {},
"Microsoft.Compute": {},
"Microsoft.ContainerInstance": {},
"Microsoft.ContainerRegistry": {},
"Microsoft.ContainerService": {},
"Microsoft.CostManagement": {},
"Microsoft.Databricks": {},
"Microsoft.DataLakeAnalytics": {},
"Microsoft.DataLakeStore": {},
"Microsoft.DataMigration": {},
"Microsoft.DBforMySQL": {},
"Microsoft.DBforPostgreSQL": {},
"Microsoft.Devices": {},
"Microsoft.DevSpaces": {},
"Microsoft.DevTestLab": {},
"Microsoft.DocumentDB": {},
"Microsoft.EventGrid": {},
"Microsoft.EventHub": {},
"Microsoft.HDInsight": {},
"Microsoft.Healthcare": {},
"Microsoft.KeyVault": {},
"Microsoft.Kusto": {},
"microsoft.insights": {},
"Microsoft.Logic": {},
"Microsoft.MachineLearningServices": {},
"Microsoft.ManagedIdentity": {},
"Microsoft.Management": {},
"Microsoft.Maps": {},
"Microsoft.MarketplaceOrdering": {},
"Microsoft.Media": {},
"Microsoft.MixedReality": {},
"Microsoft.Network": {},
"Microsoft.NotificationHubs": {},
"Microsoft.OperationalInsights": {},
"Microsoft.OperationsManagement": {},
"Microsoft.PowerBIDedicated": {},
"Microsoft.Relay": {},
"Microsoft.RecoveryServices": {},
"Microsoft.Resources": {},
"Microsoft.Search": {},
"Microsoft.Security": {},
"Microsoft.ServiceBus": {},
"Microsoft.ServiceFabric": {},
"Microsoft.Sql": {},
"Microsoft.Storage": {},
"Microsoft.StorageCache": {},
"Microsoft.StreamAnalytics": {},
"Microsoft.Web": {},
}
}

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 @@ -34,6 +34,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/kusto"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/logic"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/machinelearning"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/managementgroup"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/maps"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mariadb"
Expand Down Expand Up @@ -104,6 +105,7 @@ func SupportedServices() []common.ServiceRegistration {
kusto.Registration{},
loganalytics.Registration{},
logic.Registration{},
machinelearning.Registration{},
managementgroup.Registration{},
maps.Registration{},
mariadb.Registration{},
Expand Down
19 changes: 19 additions & 0 deletions azurerm/internal/services/machinelearning/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package client

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

type Client struct {
WorkspacesClient *machinelearningservices.WorkspacesClient
}

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

return &Client{
WorkspacesClient: &WorkspacesClient,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package machinelearning

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/services/machinelearning/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 dataSourceArmMachineLearningWorkspace() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmAMLWorkspaceRead,
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.WorkspaceName,
},
katbyte marked this conversation as resolved.
Show resolved Hide resolved

"location": azure.SchemaLocationForDataSource(),

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

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

func dataSourceArmAMLWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).MachineLearning.WorkspacesClient
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("Error: Machine Learning Workspace %q (Resource Group %q) was not found: %+v", name, resourceGroup, err)
}
return fmt.Errorf("Error reading Machine Learning Workspace %q (Resource Group %q): %+v", name, resourceGroup, err)
}
if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("Cannot read Machine Learning Workspace %q (Resource Group %q) ID", name, resourceGroup)
}
d.SetId(*resp.ID)

d.Set("name", resp.Name)
d.Set("resource_group_name", resourceGroup)

return tags.FlattenAndSet(d, resp.Tags)
}
57 changes: 57 additions & 0 deletions azurerm/internal/services/machinelearning/parse/workspace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package parse

import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
accountParser "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/parsers"
)

type WorkspaceId struct {
Name string
ResourceGroup string
}

func WorkspaceID(input string) (*WorkspaceId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

workspace := WorkspaceId{
ResourceGroup: id.ResourceGroup,
}

if workspace.Name, err = id.PopSegment("workspaces"); err != nil {
return nil, err
}

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

return &workspace, nil
}

// TODO -- use parse function "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/parsers".ParseAccountID
// when issue https://github.com/Azure/azure-rest-api-specs/issues/8323 is addressed
func AccountIDCaseDiffSuppress(input string) (*accountParser.AccountID, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

account := accountParser.AccountID{
ResourceGroup: id.ResourceGroup,
}

if account.Name, err = id.PopSegment("storageAccounts"); err != nil {
if account.Name, err = id.PopSegment("storageaccounts"); err != nil {
return nil, err
}
}

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

return &account, nil
}