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 4 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,84 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to get the workspace here? Can't we retrieve all the info on the Compute Cluster by calling client.ComputeGet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SKU used by the compute cluster resources is the SKU of the workspace. And compute GET API will not return the SKU, but nil.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a bug we should raise on the Rest API Spec, can you please open one?

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)),
},
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still be able to retrieve the existing Compute Cluster and patch the SKU from the workspace into the model instead of having to set everything from the config like in the create?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or we can try update without SKU? if this works we don't need to get the workspace in update

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, try it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried, can update without SKU. Also the API doc the SKU is the SKU for the workspace(https://learn.microsoft.com/en-us/rest/api/azureml/compute/create-or-update?view=rest-azureml-2024-04-01&tabs=HTTP#request-body). So we can ignore it or get it from the workspace, do we need to remove it in update?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can update successfully without sending anything for the SKU (and it doesn't change the SKU) then it's fine to omit getting it from the workspace.


if err := client.ComputeCreateOrUpdateThenPoll(ctx, *id, computeClusterParameters); 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 @@ -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