-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource: azurerm_machine_learning_workspace (#5696)
Terraform resource provider to create a basic Azure Machine Learning Workspace.
- Loading branch information
Showing
28 changed files
with
7,248 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
azurerm/internal/services/machinelearning/client/client.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/Azure/azure-sdk-for-go/services/machinelearningservices/mgmt/2019-11-01/machinelearningservices" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common" | ||
) | ||
|
||
type Client struct { | ||
WorkspacesClient *machinelearningservices.WorkspacesClient | ||
} | ||
|
||
func NewClient(o *common.ClientOptions) *Client { | ||
WorkspacesClient := machinelearningservices.NewWorkspacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) | ||
o.ConfigureClient(&WorkspacesClient.Client, o.ResourceManagerAuthorizer) | ||
|
||
return &Client{ | ||
WorkspacesClient: &WorkspacesClient, | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
azurerm/internal/services/machinelearning/data_source_machine_learning_workspace.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package machinelearning | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/machinelearning/validate" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmMachineLearningWorkspace() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmAMLWorkspaceRead, | ||
Timeouts: &schema.ResourceTimeout{ | ||
Read: schema.DefaultTimeout(5 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validate.WorkspaceName, | ||
}, | ||
|
||
"location": azure.SchemaLocationForDataSource(), | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(), | ||
|
||
"tags": tags.SchemaDataSource(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmAMLWorkspaceRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).MachineLearning.WorkspacesClient | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Error: Machine Learning Workspace %q (Resource Group %q) was not found: %+v", name, resourceGroup, err) | ||
} | ||
return fmt.Errorf("Error reading Machine Learning Workspace %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
if resp.ID == nil || *resp.ID == "" { | ||
return fmt.Errorf("Cannot read Machine Learning Workspace %q (Resource Group %q) ID", name, resourceGroup) | ||
} | ||
d.SetId(*resp.ID) | ||
|
||
d.Set("name", resp.Name) | ||
d.Set("resource_group_name", resourceGroup) | ||
|
||
return tags.FlattenAndSet(d, resp.Tags) | ||
} |
57 changes: 57 additions & 0 deletions
57
azurerm/internal/services/machinelearning/parse/workspace.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package parse | ||
|
||
import ( | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
accountParser "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/parsers" | ||
) | ||
|
||
type WorkspaceId struct { | ||
Name string | ||
ResourceGroup string | ||
} | ||
|
||
func WorkspaceID(input string) (*WorkspaceId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
workspace := WorkspaceId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if workspace.Name, err = id.PopSegment("workspaces"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &workspace, nil | ||
} | ||
|
||
// TODO -- use parse function "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/parsers".ParseAccountID | ||
// when issue https://github.com/Azure/azure-rest-api-specs/issues/8323 is addressed | ||
func AccountIDCaseDiffSuppress(input string) (*accountParser.AccountID, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
account := accountParser.AccountID{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if account.Name, err = id.PopSegment("storageAccounts"); err != nil { | ||
if account.Name, err = id.PopSegment("storageaccounts"); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &account, nil | ||
} |
Oops, something went wrong.