Skip to content

Commit

Permalink
Changes from Dapeng
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcturusZhang committed Feb 12, 2020
1 parent f548458 commit a2faf47
Show file tree
Hide file tree
Showing 14 changed files with 1,021 additions and 544 deletions.
98 changes: 49 additions & 49 deletions azurerm/internal/provider/required_resource_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,56 @@ 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.Databricks": {},
"Microsoft.DataLakeAnalytics": {},
"Microsoft.DataLakeStore": {},
"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.ApiManagement": {},
"Microsoft.Authorization": {},
"Microsoft.Automation": {},
"Microsoft.BotService": {},
"Microsoft.Cache": {},
"Microsoft.Cdn": {},
"Microsoft.CognitiveServices": {},
"Microsoft.Compute": {},
"Microsoft.ContainerInstance": {},
"Microsoft.ContainerRegistry": {},
"Microsoft.ContainerService": {},
"Microsoft.Databricks": {},
"Microsoft.DataLakeAnalytics": {},
"Microsoft.DataLakeStore": {},
"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.Network": {},
"Microsoft.NotificationHubs": {},
"Microsoft.OperationalInsights": {},
"Microsoft.OperationsManagement": {},
"Microsoft.Relay": {},
"Microsoft.RecoveryServices": {},
"Microsoft.Resources": {},
"Microsoft.Scheduler": {},
"Microsoft.Search": {},
"Microsoft.Security": {},
"Microsoft.ServiceBus": {},
"Microsoft.ServiceFabric": {},
"Microsoft.Sql": {},
"Microsoft.Storage": {},
"Microsoft.StreamAnalytics": {},
"Microsoft.Web": {},
"Microsoft.ManagedIdentity": {},
"Microsoft.Management": {},
"Microsoft.Maps": {},
"Microsoft.MarketplaceOrdering": {},
"Microsoft.Media": {},
"Microsoft.Network": {},
"Microsoft.NotificationHubs": {},
"Microsoft.OperationalInsights": {},
"Microsoft.OperationsManagement": {},
"Microsoft.Relay": {},
"Microsoft.RecoveryServices": {},
"Microsoft.Resources": {},
"Microsoft.Scheduler": {},
"Microsoft.Search": {},
"Microsoft.Security": {},
"Microsoft.ServiceBus": {},
"Microsoft.ServiceFabric": {},
"Microsoft.Sql": {},
"Microsoft.Storage": {},
"Microsoft.StreamAnalytics": {},
"Microsoft.Web": {},
}
}

Expand Down
21 changes: 3 additions & 18 deletions azurerm/internal/services/machinelearning/client/client.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
package machinelearning
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
VirtualMachineSizesClient *machinelearningservices.VirtualMachineSizesClient
MachineLearningComputeClient *machinelearningservices.MachineLearningComputeClient
UsagesClient *machinelearningservices.UsagesClient
WorkspacesClient *machinelearningservices.WorkspacesClient
}

func NewClient(o *common.ClientOptions) *Client {

WorkspacesClient := machinelearningservices.NewWorkspacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&WorkspacesClient.Client, o.ResourceManagerAuthorizer)

VirtualMachineSizesClient := machinelearningservices.NewVirtualMachineSizesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&VirtualMachineSizesClient.Client, o.ResourceManagerAuthorizer)

MachineLearningComputeClient := machinelearningservices.NewMachineLearningComputeClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&MachineLearningComputeClient.Client, o.ResourceManagerAuthorizer)

UsagesClient := machinelearningservices.NewUsagesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&UsagesClient.Client, o.ResourceManagerAuthorizer)

return &Client{
WorkspacesClient: &WorkspacesClient,
VirtualMachineSizesClient: &VirtualMachineSizesClient,
MachineLearningComputeClient: &MachineLearningComputeClient,
UsagesClient: &UsagesClient,
WorkspacesClient: &WorkspacesClient,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/machinelearningservices/mgmt/2019-11-01/machinelearningservices"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
Expand All @@ -17,8 +14,7 @@ import (

func dataSourceArmMachineLearningWorkspace() *schema.Resource {
return &schema.Resource{
Read: resourceArmMachineLearningWorkspaceRead,

Read: dataSourceArmAMLWorkspaceRead,
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},
Expand All @@ -29,115 +25,37 @@ func dataSourceArmMachineLearningWorkspace() *schema.Resource {
Required: true,
},

"location": azure.SchemaLocation(),

"resource_group_name": azure.SchemaResourceGroupName(),

"description": {
Type: schema.TypeString,
Optional: true,
},

"friendly_name": {
Type: schema.TypeString,
Optional: true,
},

"key_vault": {
Type: schema.TypeString,
Optional: true,
},

"application_insights": {
Type: schema.TypeString,
Optional: true,
},

"container_registry": {
Type: schema.TypeString,
Optional: true,
},

"storage_account": {
Type: schema.TypeString,
Optional: true,
},

"discovery_url": {
Type: schema.TypeString,
Optional: true,
},
"location": azure.SchemaLocationForDataSource(),

"tags": tags.Schema(),
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"identity": {
Type: schema.TypeList,
Required: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
string(machinelearningservices.SystemAssigned),
"systemAssigned",
}, true),
},
"principal_id": {
Type: schema.TypeString,
Computed: true,
},
"tenant_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"tags": tags.SchemaDataSource(),
},
}
}

func dataSourceArmMachineLearningWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceArmAMLWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).MachineLearning.WorkspacesClient
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := azure.ParseAzureResourceID(d.Id())
if err != nil {
return err
}

resGroup := id.ResourceGroup
name := id.Path["machineLearningServices"]
name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

resp, err := client.Get(ctx, resGroup, name)
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
return nil
return fmt.Errorf("Error: Machine Learning Workspace %q (Resource Group %q) was not found: %+v", name, resourceGroup, err)
}
return fmt.Errorf("Error making Read request on Workspace %q (Resource Group %q): %+v", name, resGroup, err)
return fmt.Errorf("Error reading Machine Learning Workspace %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.Set("name", resp.Name)
d.Set("resource_group_name", resGroup)
if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
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)

if props := resp.WorkspaceProperties; props != nil {
d.Set("description", props.Description)
d.Set("friendly_name", props.FriendlyName)
d.Set("storage_account", props.StorageAccount)
d.Set("discovery_url", props.DiscoveryURL)
d.Set("container_registry", props.ContainerRegistry)
d.Set("application_insights", props.ApplicationInsights)
d.Set("key_vault", props.KeyVault)
}
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
}
Loading

0 comments on commit a2faf47

Please sign in to comment.