diff --git a/internal/services/machinelearning/machine_learning_compute_cluster_resource.go b/internal/services/machinelearning/machine_learning_compute_cluster_resource.go index 28a28518c29a..aea83b485cb8 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 { @@ -37,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), }, @@ -69,7 +71,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, @@ -355,6 +357,36 @@ func resourceComputeClusterRead(d *pluginsdk.ResourceData, meta interface{}) err return tags.FlattenAndSet(d, computeResource.Model.Tags) } +func resourceComputeClusterUpdate(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).MachineLearning.MachineLearningComputes + ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := machinelearningcomputes.ParseComputeID(d.Id()) + if err != nil { + return err + } + + existing, err := client.ComputeGet(ctx, *id) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + 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) + } + payload.Identity = identity + if err := client.ComputeCreateOrUpdateThenPoll(ctx, *id, *payload); err != nil { + return fmt.Errorf("updating %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) 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..461babfcd37b 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 @@ -318,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 @@ -343,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" + 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 = [ 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.