Skip to content

Commit eaf1224

Browse files
mahhanifiMahsa Hanifi
andauthored
Mahanifi/ml workspace module (#398)
* added mlw module with the associated test harness file * updated the mlw module's version to 2.9 * removed the azurerm version from the version.tf file it was unnecessary * updated the code with the requested changes on the PR comments Co-authored-by: Mahsa Hanifi <[email protected]>
1 parent c16df5a commit eaf1224

File tree

13 files changed

+278
-0
lines changed

13 files changed

+278
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Module: Azure Machine Learning Workspace
2+
3+
This is terraform module can be used to provision an Azure ML Workspace with the following characteristics:
4+
5+
- Ability to specify the existing resource group name in which the ML Workspace will be deployed.
6+
- Ability to specify the existing resource group location, so that the ML Workspace will be deployed in the same location.
7+
- Also gives ability to specify following settings for Azure ML Workspace based on the requirements:
8+
- resource_group_name : Name of the existing resource group in which the ML Workspace will be created.
9+
- application_insights_id : ID of the existing App Insight that is existing in the same resource group.
10+
- key_vault_id : ID of the existing KeyVault that is existing in the same resource group.
11+
- storage_account_id : ID of the storage account that is existing in the same resource group.
12+
13+
Please click the [link](https://www.terraform.io/docs/providers/azurerm/r/machine_learning_workspace.html) to get additional details on settings in Terraform for Azure Machine Learning Workspace.
14+
15+
## Usage
16+
17+
### Module Definition
18+
19+
ML Workspace Module : infra/modules/providers/azure/ml-workspace
20+
21+
```terraform
22+
module "ml_workspace_walkthrough_app" {
23+
source = "../../modules/providers/azure/ml-workspace"
24+
name = "name of the workspace"
25+
resource_group_name = "name of the resource group"
26+
application_insights_id = "ID of the application insights"
27+
key_vault_id = "ID of the KeyVault"
28+
storage_account_id = "ID of the storage account"
29+
sku_name = "Basic or Enterprise"
30+
}
31+
```
32+
33+
## Outputs
34+
35+
Once the deployments are completed successfully, the output will be generated as it is in the [output.tf file](./output.tf).
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
module "azure-provider" {
3+
source = "../provider"
4+
}
5+
6+
data "azurerm_resource_group" "ml_resource_group" {
7+
name = var.resource_group_name
8+
}
9+
10+
resource "azurerm_machine_learning_workspace" "mlworkspace" {
11+
name = var.name
12+
location = data.azurerm_resource_group.ml_resource_group.location
13+
resource_group_name = var.resource_group_name
14+
application_insights_id = var.application_insights_id
15+
key_vault_id = var.key_vault_id
16+
storage_account_id = var.storage_account_id
17+
sku_name = var.sku_name
18+
identity {
19+
type = "SystemAssigned" //This is the only supported type at this time
20+
}
21+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "id" {
2+
description = "The azure machine learning workspace ID."
3+
value = azurerm_machine_learning_workspace.mlworkspace.id
4+
}
5+
6+
output "mlw_identity_principal_id" {
7+
description = "The ID of the principal(client) in Azure active directory"
8+
value = azurerm_machine_learning_workspace.mlworkspace.identity[0].principal_id
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resource_group_name = ""
2+
application_insights_id = ""
3+
key_vault_id = ""
4+
storage_account_id = ""
5+
sku_name = ""
6+
name = ""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
RESOURCE_GROUP_NAME=""
2+
ARM_SUBSCRIPTION_ID=""
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package integration
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/microsoft/cobalt/infra/modules/providers/azure/ml-workspace/tests"
8+
"github.com/microsoft/terratest-abstraction/integration"
9+
)
10+
11+
var subscription = os.Getenv("ARM_SUBSCRIPTION_ID")
12+
var resorurcegroupname = os.Getenv("RESOURCE_GROUP_NAME")
13+
14+
func TestMLWorkspace(t *testing.T) {
15+
testFixture := integration.IntegrationTestFixture{
16+
GoTest: t,
17+
TfOptions: tests.MLWorkspaceTFOptions,
18+
ExpectedTfOutputCount: 1,
19+
TfOutputAssertions: []integration.TerraformOutputValidation{
20+
VerifyCreatedMLworkspace(subscription,
21+
"resource_group_name",
22+
"id",
23+
),
24+
},
25+
}
26+
integration.RunIntegrationTests(&testFixture)
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package integration
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/cobalt/test-harness/terratest-extensions/modules/azure"
7+
"github.com/microsoft/terratest-abstraction/integration"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
// healthCheck - Asserts that the deployment was successful.
12+
func healthCheck(t *testing.T, provisionState *string) {
13+
require.Equal(t, "Succeeded", *provisionState, "The deployment hasn't succeeded.")
14+
}
15+
16+
// VerifyCreatedMLworkspace - validate the created ML Workspace
17+
func VerifyCreatedMLworkspace(subscriptionID, resourceGroupName, mlWorkSpaceOutputID string) func(goTest *testing.T, output integration.TerraformOutput) {
18+
return func(goTest *testing.T, output integration.TerraformOutput) {
19+
mlWorkspace := output[mlWorkSpaceOutputID].(string)
20+
mlResourceGroup := output[resourceGroupName].(string)
21+
22+
mlWorkspaceNameFromAzure := azure.GetMLWorkspaceIDByResourceGroup(
23+
goTest,
24+
subscriptionID,
25+
mlResourceGroup)
26+
27+
require.Equal(goTest, mlWorkspaceNameFromAzure, mlWorkspace, "The machine learning workspace does not exist")
28+
}
29+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resource_group_name = ""
2+
application_insights_id = ""
3+
key_vault_id = ""
4+
storage_account_id = ""
5+
sku_name = ""
6+
name = ""
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package tests
2+
3+
import (
4+
"os"
5+
6+
"github.com/gruntwork-io/terratest/modules/terraform"
7+
)
8+
9+
// ResourceGroupName - The Resource Group Name
10+
var ResourceGroupName = os.Getenv("RESOURCE_GROUP_NAME")
11+
12+
// MLWorkspaceTFOptions common terraform options used for unit and integration testing
13+
var MLWorkspaceTFOptions = &terraform.Options{
14+
TerraformDir: "../../",
15+
VarFiles: []string{"./tests/test.tfvars"},
16+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package unit
2+
3+
import (
4+
"encoding/json"
5+
"strings"
6+
"testing"
7+
8+
"github.com/gruntwork-io/terratest/modules/random"
9+
tests "github.com/microsoft/cobalt/infra/modules/providers/azure/ml-workspace/tests"
10+
"github.com/microsoft/terratest-abstraction/unit"
11+
)
12+
13+
var resourceCount = 1
14+
var workspace = "sample-" + strings.ToLower(random.UniqueId())
15+
16+
// helper function to parse blocks of JSON into a generic Go map
17+
func asMap(t *testing.T, jsonString string) map[string]interface{} {
18+
var theMap map[string]interface{}
19+
if err := json.Unmarshal([]byte(jsonString), &theMap); err != nil {
20+
t.Fatal(err)
21+
}
22+
return theMap
23+
}
24+
25+
func TestAzureMLWorkspaceDeployment_Unit(t *testing.T) {
26+
27+
expectedResult := map[string]interface{}{
28+
"name": "demo0012",
29+
"resource_group_name": "azmltest",
30+
"sku_name": "Enterprise",
31+
}
32+
testFixture := unit.UnitTestFixture{
33+
GoTest: t,
34+
TfOptions: tests.MLWorkspaceTFOptions,
35+
Workspace: workspace,
36+
PlanAssertions: nil,
37+
ExpectedResourceCount: resourceCount,
38+
ExpectedResourceAttributeValues: unit.ResourceDescription{
39+
"azurerm_machine_learning_workspace.mlworkspace": expectedResult,
40+
},
41+
}
42+
43+
unit.RunUnitTests(&testFixture)
44+
}

0 commit comments

Comments
 (0)