Skip to content

Commit

Permalink
Temp
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcturusZhang committed Dec 23, 2019
1 parent 69a2f75 commit 1ba5ed3
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 30 deletions.
3 changes: 3 additions & 0 deletions azurerm/internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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 @@ -103,6 +104,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 @@ -171,6 +173,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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package machinelearning
package client

import (
"github.com/Azure/azure-sdk-for-go/services/machinelearningservices/mgmt/2019-11-01/machinelearningservices"
Expand All @@ -12,7 +12,7 @@ type Client struct {
UsagesClient *machinelearningservices.UsagesClient
}

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

WorkspacesClient := machinelearningservices.NewWorkspacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&WorkspacesClient.Client, o.ResourceManagerAuthorizer)
Expand Down
20 changes: 20 additions & 0 deletions azurerm/internal/services/machinelearning/registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package machinelearning

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 "Machine Learning"
}

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

// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*schema.Resource {
return map[string]*schema.Resource{}
}
74 changes: 46 additions & 28 deletions azurerm/resource_arm_machine_learning_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"reflect"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"time"

"github.com/Azure/azure-sdk-for-go/services/machinelearningservices/mgmt/2019-11-01/machinelearningservices"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand All @@ -21,6 +22,13 @@ func resourceArmAmlWorkspace() *schema.Resource {
Update: resourceArmAmlWorkspaceCreateUpdate,
Delete: resourceArmAmlWorkspaceDelete,

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

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand All @@ -34,45 +42,48 @@ func resourceArmAmlWorkspace() *schema.Resource {

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

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

"key_vault": {
Type: schema.TypeString,
Required: true,
"key_vault_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: azure.ValidateResourceID,
},

"application_insights": {
Type: schema.TypeString,
Required: true,
"application_insights_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: azure.ValidateResourceID,
},

"container_registry": {
Type: schema.TypeString,
Required: true,
"container_registry_id": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: azure.ValidateResourceID,
},

"storage_account": {
Type: schema.TypeString,
Required: true,
"storage_account_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: azure.ValidateResourceID,
},

"discovery_url": {
Type: schema.TypeString,
Required: true,
Optional: true,
},

"tags": tags.Schema(),

"identity": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -106,17 +117,18 @@ func resourceArmAmlWorkspace() *schema.Resource {

func resourceArmAmlWorkspaceCreateUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).MachineLearning.WorkspacesClient
ctx := meta.(*ArmClient).StopContext
ctx, cancel := timeouts.ForCreateUpdate(meta.(*ArmClient).StopContext, d)
defer cancel()

name := d.Get("name").(string)
resGroup := d.Get("resource_group_name").(string)
location := azure.NormalizeLocation(d.Get("location").(string))
description := d.Get("description").(string)
friendlyName := d.Get("friendly_name").(string)
storageAccount := d.Get("storage_account").(string)
keyVault := d.Get("key_vault").(string)
containerRegistry := d.Get("container_registry").(string)
applicationInsights := d.Get("application_insights").(string)
storageAccount := d.Get("storage_account_id").(string)
keyVault := d.Get("key_vault_id").(string)
containerRegistry := d.Get("container_registry_id").(string)
applicationInsights := d.Get("application_insights_id").(string)
discoveryUrl := d.Get("discovery_url").(string)
t := d.Get("tags").(map[string]interface{})

Expand All @@ -131,6 +143,7 @@ func resourceArmAmlWorkspaceCreateUpdate(d *schema.ResourceData, meta interface{
}
}

// TODO -- should validate container registry enable_admin is enabled.
workspace := machinelearningservices.Workspace{
Name: &name,
Location: &location,
Expand All @@ -144,7 +157,7 @@ func resourceArmAmlWorkspaceCreateUpdate(d *schema.ResourceData, meta interface{
ApplicationInsights: &applicationInsights,
KeyVault: &keyVault,
},
Identity: &machinelearningservices.Identity{Type: machinelearningservices.SystemAssigned},
Identity: expandAmlIdentity(d),
}

result, err := client.CreateOrUpdate(ctx, resGroup, name, workspace)
Expand All @@ -170,7 +183,8 @@ func resourceArmAmlWorkspaceCreateUpdate(d *schema.ResourceData, meta interface{

func resourceArmAmlWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).MachineLearning.WorkspacesClient
ctx := meta.(*ArmClient).StopContext
ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d)
defer cancel()

id, err := azure.ParseAzureResourceID(d.Id())
if err != nil {
Expand Down Expand Up @@ -198,11 +212,11 @@ func resourceArmAmlWorkspaceRead(d *schema.ResourceData, meta interface{}) error
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("storage_account_id", 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("container_registry_id", props.ContainerRegistry)
d.Set("application_insights_id", props.ApplicationInsights)
d.Set("key_vault_id", props.KeyVault)
}
if err := d.Set("identity", flattenAmlIdentity(resp.Identity)); err != nil {
return fmt.Errorf("Error flattening identity on Workspace %q (Resource Group %q): %+v", name, resGroup, err)
Expand Down Expand Up @@ -248,6 +262,10 @@ func flattenAmlIdentity(identity *machinelearningservices.Identity) interface{}

func expandAmlIdentity(d *schema.ResourceData) *machinelearningservices.Identity {
v := d.Get("identity")
// Rest api will return an error if you did not set the identity field.
if v == nil {
return &machinelearningservices.Identity{Type: machinelearningservices.SystemAssigned}
}
identities := v.([]interface{})
identity := identities[0].(map[string]interface{})
identityType := machinelearningservices.ResourceIdentityType(identity["type"].(string))
Expand Down
12 changes: 12 additions & 0 deletions azurerm/resource_arm_machine_learning_workspace_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package azurerm

import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"testing"
)

func TestAccAzureRMMachineLearningWorkspace_basic(t *testing.T) {
resourceName := "azurerm_machine_learning_workspace.test"
ri := tf.AccRandTimeInt()
location := testLocation()
}

0 comments on commit 1ba5ed3

Please sign in to comment.