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 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 @@ -171,21 +171,63 @@ 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 fmt.Errorf("retrieving %s: %+v", workspaceID, err)
}

workspaceModel := workspace.Model
if workspaceModel == nil {
return fmt.Errorf("retrieving %s: `model` was nil", workspaceID)
}

if workspaceModel.Sku == nil || workspaceModel.Sku.Tier == nil || workspaceModel.Sku.Name == "" {
return fmt.Errorf("retrieving %s: `sku` was nil or empty", workspaceID)
}

if workspaceModel.Location == nil {
return fmt.Errorf("retrieving %s: `location` was nil", workspaceID)
}

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())
}
nodePublicIPEnabled, ok := d.Get("node_public_ip_enabled").(bool)
if !ok {
return fmt.Errorf("unable to assert type for `node_public_ip_enabled`")
}

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`")
subnetResourceID, ok := d.Get("subnet_resource_id").(string)
if !ok {
return fmt.Errorf("unable to assert type for `subnet_resource_id`")
}

workspaceInManagedVnet := false

if workspaceModel.Properties != nil &&
workspaceModel.Properties.ManagedNetwork != nil &&
workspaceModel.Properties.ManagedNetwork.Status != nil &&
workspaceModel.Properties.ManagedNetwork.Status.Status != nil {
workspaceInManagedVnet = *workspaceModel.Properties.ManagedNetwork.Status.Status == workspaces.ManagedNetworkStatusActive
}

if !nodePublicIPEnabled && subnetResourceID == "" && !workspaceInManagedVnet {
return fmt.Errorf("`subnet_resource_id` must be set if `node_public_ip_enabled` is set to `false` or the workspace is not in a managed network")
}

vmPriority := machinelearningcomputes.VMPriority(d.Get("vm_priority").(string))
Expand Down Expand Up @@ -215,30 +257,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
Loading