From 35c8972f818106ce71968c0504a409f248428d61 Mon Sep 17 00:00:00 2001 From: xu Date: Thu, 20 Jun 2024 11:37:10 +0800 Subject: [PATCH 1/9] remove forewNew from identity --- .../machine_learning_compute_cluster_resource.go | 2 +- website/docs/r/machine_learning_compute_cluster.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/machinelearning/machine_learning_compute_cluster_resource.go b/internal/services/machinelearning/machine_learning_compute_cluster_resource.go index 28a28518c29a..bb5eb1e879dd 100644 --- a/internal/services/machinelearning/machine_learning_compute_cluster_resource.go +++ b/internal/services/machinelearning/machine_learning_compute_cluster_resource.go @@ -69,7 +69,7 @@ func resourceComputeCluster() *pluginsdk.Resource { ValidateFunc: validation.StringInSlice([]string{string(machinelearningcomputes.VMPriorityDedicated), string(machinelearningcomputes.VMPriorityLowPriority)}, false), }, - "identity": commonschema.SystemAssignedUserAssignedIdentityOptionalForceNew(), + "identity": commonschema.SystemAssignedUserAssignedIdentityOptional(), "scale_settings": { Type: pluginsdk.TypeList, diff --git a/website/docs/r/machine_learning_compute_cluster.html.markdown b/website/docs/r/machine_learning_compute_cluster.html.markdown index f694ed67fff2..1128e7057462 100644 --- a/website/docs/r/machine_learning_compute_cluster.html.markdown +++ b/website/docs/r/machine_learning_compute_cluster.html.markdown @@ -119,7 +119,7 @@ The following arguments are supported: * `description` - (Optional) The description of the Machine Learning compute. Changing this forces a new Machine Learning Compute Cluster to be created. -* `identity` - (Optional) An `identity` block as defined below. Changing this forces a new Machine Learning Compute Cluster to be created. +* `identity` - (Optional) An `identity` block as defined below. * `local_auth_enabled` - (Optional) Whether local authentication methods is enabled. Defaults to `true`. Changing this forces a new Machine Learning Compute Cluster to be created. From 5b7a53120938a3b085ef9d939064de94590b8dd1 Mon Sep 17 00:00:00 2001 From: xu Date: Thu, 20 Jun 2024 15:15:50 +0800 Subject: [PATCH 2/9] add update --- ...chine_learning_compute_cluster_resource.go | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/internal/services/machinelearning/machine_learning_compute_cluster_resource.go b/internal/services/machinelearning/machine_learning_compute_cluster_resource.go index bb5eb1e879dd..da1ef7dee911 100644 --- a/internal/services/machinelearning/machine_learning_compute_cluster_resource.go +++ b/internal/services/machinelearning/machine_learning_compute_cluster_resource.go @@ -27,6 +27,7 @@ func resourceComputeCluster() *pluginsdk.Resource { return &pluginsdk.Resource{ Create: resourceComputeClusterCreate, Read: resourceComputeClusterRead, + Update: resourceComputeClusterUpdate, Delete: resourceComputeClusterDelete, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { @@ -355,6 +356,88 @@ func resourceComputeClusterRead(d *pluginsdk.ResourceData, meta interface{}) err return tags.FlattenAndSet(d, computeResource.Model.Tags) } +func resourceComputeClusterUpdate(d *pluginsdk.ResourceData, meta interface{}) error { + mlWorkspacesClient := meta.(*clients.Client).MachineLearning.Workspaces + client := meta.(*clients.Client).MachineLearning.MachineLearningComputes + ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) + defer cancel() + + workspaceID, err := workspaces.ParseWorkspaceID(d.Get("machine_learning_workspace_id").(string)) + if err != nil { + return err + } + + id, err := machinelearningcomputes.ParseComputeID(d.Id()) + if err != nil { + return err + } + + workspace, err := mlWorkspacesClient.Get(ctx, *workspaceID) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", workspaceID, err) + } + + workspaceModel := workspace.Model + if workspaceModel == nil { + return fmt.Errorf("retrieving %s: `model` was nil", workspaceID) + } + + identity, err := expandIdentity(d.Get("identity").([]interface{})) + if err != nil { + return fmt.Errorf("expanding `identity`: %+v", err) + } + + vmPriority := machinelearningcomputes.VMPriority(d.Get("vm_priority").(string)) + computeClusterAmlComputeProperties := machinelearningcomputes.AmlComputeProperties{ + VMSize: utils.String(d.Get("vm_size").(string)), + VMPriority: &vmPriority, + ScaleSettings: expandScaleSettings(d.Get("scale_settings").([]interface{})), + UserAccountCredentials: expandUserAccountCredentials(d.Get("ssh").([]interface{})), + EnableNodePublicIP: pointer.To(d.Get("node_public_ip_enabled").(bool)), + } + + computeClusterAmlComputeProperties.RemoteLoginPortPublicAccess = pointer.To(machinelearningcomputes.RemoteLoginPortPublicAccessDisabled) + if d.Get("ssh_public_access_enabled").(bool) { + computeClusterAmlComputeProperties.RemoteLoginPortPublicAccess = pointer.To(machinelearningcomputes.RemoteLoginPortPublicAccessEnabled) + } + + if subnetId, ok := d.GetOk("subnet_resource_id"); ok && subnetId.(string) != "" { + computeClusterAmlComputeProperties.Subnet = &machinelearningcomputes.ResourceId{Id: subnetId.(string)} + } + + // NOTE: The 'AmlCompute' 'ComputeLocation' field should always point + // to configuration files 'location' field... + computeClusterProperties := machinelearningcomputes.AmlCompute{ + Properties: &computeClusterAmlComputeProperties, + ComputeLocation: utils.String(d.Get("location").(string)), + Description: utils.String(d.Get("description").(string)), + DisableLocalAuth: utils.Bool(!d.Get("local_auth_enabled").(bool)), + } + + // NOTE: The 'ComputeResource' 'Location' field should always point + // to the workspace's 'location'... + computeClusterParameters := machinelearningcomputes.ComputeResource{ + Properties: computeClusterProperties, + Identity: identity, + Location: workspaceModel.Location, + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), + Sku: &machinelearningcomputes.Sku{ + Name: workspaceModel.Sku.Name, + Tier: pointer.To(machinelearningcomputes.SkuTier(*workspaceModel.Sku.Tier)), + }, + } + + future, err := client.ComputeCreateOrUpdate(ctx, *id, computeClusterParameters) + if err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + if err := future.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("waiting for creation of %s: %+v", id, err) + } + + return resourceComputeClusterRead(d, meta) +} + func resourceComputeClusterDelete(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).MachineLearning.MachineLearningComputes ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) From bcb49009a0ae9a8913066a50a0dea37deda7c5e4 Mon Sep 17 00:00:00 2001 From: xu Date: Thu, 20 Jun 2024 15:45:10 +0800 Subject: [PATCH 3/9] add tiomeout --- .../machinelearning/machine_learning_compute_cluster_resource.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/services/machinelearning/machine_learning_compute_cluster_resource.go b/internal/services/machinelearning/machine_learning_compute_cluster_resource.go index da1ef7dee911..7549ed845b3d 100644 --- a/internal/services/machinelearning/machine_learning_compute_cluster_resource.go +++ b/internal/services/machinelearning/machine_learning_compute_cluster_resource.go @@ -38,6 +38,7 @@ func resourceComputeCluster() *pluginsdk.Resource { Timeouts: &pluginsdk.ResourceTimeout{ Create: pluginsdk.DefaultTimeout(30 * time.Minute), Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(30 * time.Minute), Delete: pluginsdk.DefaultTimeout(30 * time.Minute), }, From f2089e217614c13be85ee60493fccd16a8e8c47c Mon Sep 17 00:00:00 2001 From: Xu Zhang Date: Fri, 21 Jun 2024 16:57:41 +0800 Subject: [PATCH 4/9] optimize the update --- .../machine_learning_compute_cluster_resource.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/internal/services/machinelearning/machine_learning_compute_cluster_resource.go b/internal/services/machinelearning/machine_learning_compute_cluster_resource.go index 7549ed845b3d..5a8ff8c4b001 100644 --- a/internal/services/machinelearning/machine_learning_compute_cluster_resource.go +++ b/internal/services/machinelearning/machine_learning_compute_cluster_resource.go @@ -428,12 +428,8 @@ func resourceComputeClusterUpdate(d *pluginsdk.ResourceData, meta interface{}) e }, } - future, err := client.ComputeCreateOrUpdate(ctx, *id, computeClusterParameters) - if err != nil { - return fmt.Errorf("creating %s: %+v", id, err) - } - if err := future.Poller.PollUntilDone(ctx); err != nil { - return fmt.Errorf("waiting for creation of %s: %+v", id, err) + if err := client.ComputeCreateOrUpdateThenPoll(ctx, *id, computeClusterParameters); err != nil { + return fmt.Errorf("updating %s: %+v", id, err) } return resourceComputeClusterRead(d, meta) From 3629a5132fcf389e4753aab0e81fc6ae005c4f7f Mon Sep 17 00:00:00 2001 From: Xu Zhang Date: Wed, 26 Jun 2024 14:13:30 +0800 Subject: [PATCH 5/9] remove mlw model in update --- ...chine_learning_compute_cluster_resource.go | 26 +++++-------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/internal/services/machinelearning/machine_learning_compute_cluster_resource.go b/internal/services/machinelearning/machine_learning_compute_cluster_resource.go index 5a8ff8c4b001..a3f9e0f1413b 100644 --- a/internal/services/machinelearning/machine_learning_compute_cluster_resource.go +++ b/internal/services/machinelearning/machine_learning_compute_cluster_resource.go @@ -358,29 +358,23 @@ func resourceComputeClusterRead(d *pluginsdk.ResourceData, meta interface{}) err } func resourceComputeClusterUpdate(d *pluginsdk.ResourceData, meta interface{}) error { - mlWorkspacesClient := meta.(*clients.Client).MachineLearning.Workspaces client := meta.(*clients.Client).MachineLearning.MachineLearningComputes ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - workspaceID, err := workspaces.ParseWorkspaceID(d.Get("machine_learning_workspace_id").(string)) - if err != nil { - return err - } - id, err := machinelearningcomputes.ParseComputeID(d.Id()) if err != nil { return err } - workspace, err := mlWorkspacesClient.Get(ctx, *workspaceID) + compute, err := client.ComputeGet(ctx, *id) if err != nil { - return fmt.Errorf("retrieving %s: %+v", workspaceID, err) + return fmt.Errorf("retrieving %s: %+v", *id, err) } - workspaceModel := workspace.Model - if workspaceModel == nil { - return fmt.Errorf("retrieving %s: `model` was nil", workspaceID) + computeModel := compute.Model + if computeModel == nil { + return fmt.Errorf("retrieving %s: `model` was nil", *id) } identity, err := expandIdentity(d.Get("identity").([]interface{})) @@ -406,8 +400,6 @@ func resourceComputeClusterUpdate(d *pluginsdk.ResourceData, meta interface{}) e computeClusterAmlComputeProperties.Subnet = &machinelearningcomputes.ResourceId{Id: subnetId.(string)} } - // NOTE: The 'AmlCompute' 'ComputeLocation' field should always point - // to configuration files 'location' field... computeClusterProperties := machinelearningcomputes.AmlCompute{ Properties: &computeClusterAmlComputeProperties, ComputeLocation: utils.String(d.Get("location").(string)), @@ -415,17 +407,11 @@ func resourceComputeClusterUpdate(d *pluginsdk.ResourceData, meta interface{}) e DisableLocalAuth: utils.Bool(!d.Get("local_auth_enabled").(bool)), } - // NOTE: The 'ComputeResource' 'Location' field should always point - // to the workspace's 'location'... computeClusterParameters := machinelearningcomputes.ComputeResource{ Properties: computeClusterProperties, Identity: identity, - Location: workspaceModel.Location, + Location: computeModel.Location, Tags: tags.Expand(d.Get("tags").(map[string]interface{})), - Sku: &machinelearningcomputes.Sku{ - Name: workspaceModel.Sku.Name, - Tier: pointer.To(machinelearningcomputes.SkuTier(*workspaceModel.Sku.Tier)), - }, } if err := client.ComputeCreateOrUpdateThenPoll(ctx, *id, computeClusterParameters); err != nil { From 1bf2541eb25949f65ffcc66b174d292539758ab1 Mon Sep 17 00:00:00 2001 From: Xu Zhang Date: Thu, 27 Jun 2024 13:34:22 +0800 Subject: [PATCH 6/9] optimize update --- ...chine_learning_compute_cluster_resource.go | 44 +++---------------- 1 file changed, 5 insertions(+), 39 deletions(-) diff --git a/internal/services/machinelearning/machine_learning_compute_cluster_resource.go b/internal/services/machinelearning/machine_learning_compute_cluster_resource.go index a3f9e0f1413b..aea83b485cb8 100644 --- a/internal/services/machinelearning/machine_learning_compute_cluster_resource.go +++ b/internal/services/machinelearning/machine_learning_compute_cluster_resource.go @@ -367,54 +367,20 @@ func resourceComputeClusterUpdate(d *pluginsdk.ResourceData, meta interface{}) e return err } - compute, err := client.ComputeGet(ctx, *id) + existing, err := client.ComputeGet(ctx, *id) if err != nil { return fmt.Errorf("retrieving %s: %+v", *id, err) } - - computeModel := compute.Model - if computeModel == nil { + payload := existing.Model + if payload == nil { return fmt.Errorf("retrieving %s: `model` was nil", *id) } - identity, err := expandIdentity(d.Get("identity").([]interface{})) if err != nil { return fmt.Errorf("expanding `identity`: %+v", err) } - - vmPriority := machinelearningcomputes.VMPriority(d.Get("vm_priority").(string)) - computeClusterAmlComputeProperties := machinelearningcomputes.AmlComputeProperties{ - VMSize: utils.String(d.Get("vm_size").(string)), - VMPriority: &vmPriority, - ScaleSettings: expandScaleSettings(d.Get("scale_settings").([]interface{})), - UserAccountCredentials: expandUserAccountCredentials(d.Get("ssh").([]interface{})), - EnableNodePublicIP: pointer.To(d.Get("node_public_ip_enabled").(bool)), - } - - computeClusterAmlComputeProperties.RemoteLoginPortPublicAccess = pointer.To(machinelearningcomputes.RemoteLoginPortPublicAccessDisabled) - if d.Get("ssh_public_access_enabled").(bool) { - computeClusterAmlComputeProperties.RemoteLoginPortPublicAccess = pointer.To(machinelearningcomputes.RemoteLoginPortPublicAccessEnabled) - } - - if subnetId, ok := d.GetOk("subnet_resource_id"); ok && subnetId.(string) != "" { - computeClusterAmlComputeProperties.Subnet = &machinelearningcomputes.ResourceId{Id: subnetId.(string)} - } - - computeClusterProperties := machinelearningcomputes.AmlCompute{ - Properties: &computeClusterAmlComputeProperties, - ComputeLocation: utils.String(d.Get("location").(string)), - Description: utils.String(d.Get("description").(string)), - DisableLocalAuth: utils.Bool(!d.Get("local_auth_enabled").(bool)), - } - - computeClusterParameters := machinelearningcomputes.ComputeResource{ - Properties: computeClusterProperties, - Identity: identity, - Location: computeModel.Location, - Tags: tags.Expand(d.Get("tags").(map[string]interface{})), - } - - if err := client.ComputeCreateOrUpdateThenPoll(ctx, *id, computeClusterParameters); err != nil { + payload.Identity = identity + if err := client.ComputeCreateOrUpdateThenPoll(ctx, *id, *payload); err != nil { return fmt.Errorf("updating %s: %+v", id, err) } From 3512d78e9dc70cf02e1f2fd397c5a924c7afb7e0 Mon Sep 17 00:00:00 2001 From: Xu Zhang Date: Thu, 27 Jun 2024 18:50:49 +0800 Subject: [PATCH 7/9] update test case --- .../machine_learning_compute_cluster_resource_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/services/machinelearning/machine_learning_compute_cluster_resource_test.go b/internal/services/machinelearning/machine_learning_compute_cluster_resource_test.go index 66a004d6ba61..c94de01feeb9 100644 --- a/internal/services/machinelearning/machine_learning_compute_cluster_resource_test.go +++ b/internal/services/machinelearning/machine_learning_compute_cluster_resource_test.go @@ -178,7 +178,6 @@ resource "azurerm_machine_learning_compute_cluster" "test" { vm_priority = "LowPriority" vm_size = "STANDARD_DS2_V2" machine_learning_workspace_id = azurerm_machine_learning_workspace.test.id - local_auth_enabled = false scale_settings { min_node_count = 0 From 515c029e67cb00e53382548bf190f9f7b4b6155c Mon Sep 17 00:00:00 2001 From: Xu Zhang Date: Fri, 28 Jun 2024 14:07:32 +0800 Subject: [PATCH 8/9] format test case --- .../machine_learning_compute_cluster_resource_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/services/machinelearning/machine_learning_compute_cluster_resource_test.go b/internal/services/machinelearning/machine_learning_compute_cluster_resource_test.go index c94de01feeb9..a51c6a3e9119 100644 --- a/internal/services/machinelearning/machine_learning_compute_cluster_resource_test.go +++ b/internal/services/machinelearning/machine_learning_compute_cluster_resource_test.go @@ -317,6 +317,7 @@ resource "azurerm_user_assigned_identity" "test" { location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name } + resource "azurerm_machine_learning_compute_cluster" "test" { name = "CC-%d" location = azurerm_resource_group.test.location @@ -342,22 +343,26 @@ func (r ComputeClusterResource) identitySystemAssignedUserAssigned(data acceptan template := r.template_basic(data) return fmt.Sprintf(` %s + resource "azurerm_user_assigned_identity" "test" { name = "acctestUAI-%d" location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name } + resource "azurerm_machine_learning_compute_cluster" "test" { name = "CC-%d" location = azurerm_resource_group.test.location vm_priority = "LowPriority" vm_size = "STANDARD_DS2_V2" + machine_learning_workspace_id = azurerm_machine_learning_workspace.test.id scale_settings { min_node_count = 0 max_node_count = 1 scale_down_nodes_after_idle_duration = "PT30S" # 30 seconds } + identity { type = "SystemAssigned, UserAssigned" identity_ids = [ From 2a85ab0e93baefcd14e8326cd00ce83dc137f9fd Mon Sep 17 00:00:00 2001 From: Xu Zhang Date: Fri, 28 Jun 2024 14:15:00 +0800 Subject: [PATCH 9/9] format test case --- .../machine_learning_compute_cluster_resource_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/services/machinelearning/machine_learning_compute_cluster_resource_test.go b/internal/services/machinelearning/machine_learning_compute_cluster_resource_test.go index a51c6a3e9119..461babfcd37b 100644 --- a/internal/services/machinelearning/machine_learning_compute_cluster_resource_test.go +++ b/internal/services/machinelearning/machine_learning_compute_cluster_resource_test.go @@ -351,10 +351,10 @@ resource "azurerm_user_assigned_identity" "test" { } resource "azurerm_machine_learning_compute_cluster" "test" { - name = "CC-%d" - location = azurerm_resource_group.test.location - vm_priority = "LowPriority" - vm_size = "STANDARD_DS2_V2" + name = "CC-%d" + location = azurerm_resource_group.test.location + vm_priority = "LowPriority" + vm_size = "STANDARD_DS2_V2" machine_learning_workspace_id = azurerm_machine_learning_workspace.test.id scale_settings {