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

azurerm_machine_learning_compute_cluster - Add support for update identity #26404

Merged
merged 9 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
},

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading