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 change subnet_resource_id constraint: Respect Managed Vnet when creating compute clusters fixes #25901 #26073

Merged
merged 6 commits into from
May 23, 2024
Merged
Changes from 1 commit
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 @@ -14,7 +14,6 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/machinelearningservices/2023-10-01/machinelearningcomputes"
"github.com/hashicorp/go-azure-sdk/resource-manager/machinelearningservices/2023-10-01/workspaces"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down Expand Up @@ -171,21 +170,41 @@ func resourceComputeClusterCreate(d *pluginsdk.ResourceData, meta interface{}) e
if err != nil {
return err
}

// Get the Machine Learning Workspace...
id := machinelearningcomputes.NewComputeID(workspaceID.SubscriptionId, workspaceID.ResourceGroupName, workspaceID.WorkspaceName, d.Get("name").(string))

workspace, err := mlWorkspacesClient.Get(ctx, *workspaceID)
if err != nil {
return err
hmrc87 marked this conversation as resolved.
Show resolved Hide resolved
}

workspaceModel := workspace.Model
if workspaceModel == nil {
return fmt.Errorf("machine learning %s Workspace: model was nil", id)
hmrc87 marked this conversation as resolved.
Show resolved Hide resolved
}

if workspaceModel.Sku == nil || workspaceModel.Sku.Tier == nil || workspaceModel.Sku.Name == "" {
return fmt.Errorf("machine learning %s Workspace: `SKU` was nil or empty", id)
hmrc87 marked this conversation as resolved.
Show resolved Hide resolved
}

if workspaceModel.Location == nil {
return fmt.Errorf("machine learning %s Workspace: `Location` was nil", id)
hmrc87 marked this conversation as resolved.
Show resolved Hide resolved
}

identity, err := expandIdentity(d.Get("identity").([]interface{}))
if err != nil {
return fmt.Errorf("expanding `identity`: %+v", err)
}

existing, err := client.ComputeGet(ctx, id)
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("checking for presence of existing %s: %+v", id, err)
}
}
if !response.WasNotFound(existing.HttpResponse) {
return tf.ImportAsExistsError("azurerm_machine_learning_compute_cluster", id.ID())
hmrc87 marked this conversation as resolved.
Show resolved Hide resolved
}

if !d.Get("node_public_ip_enabled").(bool) && d.Get("subnet_resource_id").(string) == "" {
return fmt.Errorf("`subnet_resource_id` must be set if `node_public_ip_enabled` is set to `false`")
if !d.Get("node_public_ip_enabled").(bool) && d.Get("subnet_resource_id").(string) == "" && *workspaceModel.Properties.ManagedNetwork.Status.Status != workspaces.ManagedNetworkStatusActive {
hmrc87 marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("`subnet_resource_id` must be set if `node_public_ip_enabled` is set to `false` if the workspace is not in a managed network")
hmrc87 marked this conversation as resolved.
Show resolved Hide resolved
}

vmPriority := machinelearningcomputes.VMPriority(d.Get("vm_priority").(string))
Expand Down Expand Up @@ -215,30 +234,6 @@ func resourceComputeClusterCreate(d *pluginsdk.ResourceData, meta interface{}) e
DisableLocalAuth: utils.Bool(!d.Get("local_auth_enabled").(bool)),
}

// Get the Machine Learning Workspace...
workspace, err := mlWorkspacesClient.Get(ctx, *workspaceID)
if err != nil {
return err
}

workspaceModel := workspace.Model
if workspaceModel == nil {
return fmt.Errorf("machine learning %s Workspace: model was nil", id)
}

if workspaceModel.Sku == nil || workspaceModel.Sku.Tier == nil || workspaceModel.Sku.Name == "" {
return fmt.Errorf("machine learning %s Workspace: `SKU` was nil or empty", id)
}

if workspaceModel.Location == nil {
return fmt.Errorf("machine learning %s Workspace: `Location` was nil", id)
}

identity, err := expandIdentity(d.Get("identity").([]interface{}))
if err != nil {
return fmt.Errorf("expanding `identity`: %+v", err)
}

// NOTE: The 'ComputeResource' 'Location' field should always point
// to the workspace's 'location'...
computeClusterParameters := machinelearningcomputes.ComputeResource{
Expand Down