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

Fix 202-machine-learning-moderately-secure example #303

Merged
merged 8 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
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 @@ -3,7 +3,7 @@ resource "random_string" "ci_prefix" {
length = 8
upper = false
special = false
number = false
numeric = false
}

# Compute instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.78.0"
version = ">=2.78.0, <3.0"
}

azureml = {
source = "registry.terraform.io/Telemaco019/azureml"
source = "registry.terraform.io/orobix/azureml"
version = "0.0.5"
}
random = {
source = "hashicorp/random"
version = "3.6.0"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
resource "random_string" "suffix" {
length = 6
special = false
upper = false
}

resource "azurerm_resource_group" "network" {
location = var.location
name = "rg-202-mlmsev-network-${random_string.suffix.result}"
}

resource "azurerm_virtual_network" "vnet" {
address_space = ["192.168.0.0/16"]
location = azurerm_resource_group.network.location
name = "202-mlmsev-vnet"
resource_group_name = azurerm_resource_group.network.name
}

locals {
subnet_names = [
"training",
"aks",
"ml",
]
}

resource "azurerm_subnet" "subnet" {
count = length(local.subnet_names)

address_prefixes = [cidrsubnet("192.168.0.0/16", 8, count.index)]
name = local.subnet_names[count.index]
resource_group_name = azurerm_resource_group.network.name
virtual_network_name = azurerm_virtual_network.vnet.name
}

locals {
private_dns_names = toset([
"privatelink.api.azureml.ms",
"privatelink.azurecr.io",
"privatelink.notebooks.azure.net",
"privatelink.blob.core.windows.net",
"privatelink.file.core.windows.net",
"privatelink.vaultcore.azure.net",
])
}

resource "azurerm_private_dns_zone" "private_dns_zone" {
for_each = local.private_dns_names

name = each.value
resource_group_name = azurerm_resource_group.network.name
}

resource "azurerm_private_dns_zone_virtual_network_link" "link" {
for_each = local.private_dns_names

name = each.value
private_dns_zone_name = azurerm_private_dns_zone.private_dns_zone[each.value].name
resource_group_name = azurerm_resource_group.network.name
virtual_network_id = azurerm_virtual_network.vnet.id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
output "aks_subnet_name" {
description = "Name of the existing aks subnet"
value = azurerm_subnet.subnet[index(local.subnet_names, "aks")].name
}

output "ml_subnet_name" {
description = "Name of the existing ML workspace subnet"
value = azurerm_subnet.subnet[index(local.subnet_names, "ml")].name
}

output "privatelink_api_azureml_ms_resource_id" {
description = "Resource ID of the existing privatelink.api.azureml.ms private dns zone"
value = azurerm_private_dns_zone.private_dns_zone["privatelink.api.azureml.ms"].id
}

output "privatelink_azurecr_io_resource_id" {
description = "Resource ID of the existing privatelink.azurecr.io private dns zone"
value = azurerm_private_dns_zone.private_dns_zone["privatelink.azurecr.io"].id
}

output "privatelink_blob_core_windows_net_resource_id" {
description = "Resource ID of the existing privatelink.blob.core.windows.net private dns zone"
value = azurerm_private_dns_zone.private_dns_zone["privatelink.blob.core.windows.net"].id
}

output "privatelink_file_core_windows_net_resource_id" {
description = "Resource ID of the existing privatelink.file.core.windows.net private dns zone"
value = azurerm_private_dns_zone.private_dns_zone["privatelink.file.core.windows.net"].id
}

output "privatelink_notebooks_azure_net_resource_id" {
description = "Resource ID of the existing privatelink.notebooks.azure.net private dns zone"
value = azurerm_private_dns_zone.private_dns_zone["privatelink.notebooks.azure.net"].id
}

output "privatelink_vaultcore_azure_net_resource_id" {
description = "Resource ID of the existing privatelink.vaultcore.azure.net private dns zone"
value = azurerm_private_dns_zone.private_dns_zone["privatelink.vaultcore.azure.net"].id
}

output "training_subnet_name" {
description = "Name of the existing training subnet"
value = azurerm_subnet.subnet[index(local.subnet_names, "training")].name
}

output vnet_name {
value = azurerm_virtual_network.vnet.name
}

output "resource_group_name" {
value = azurerm_resource_group.network.name
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "location" {
type = string
default = "East US"
description = "Location of the resources"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
terraform {
required_version = ">=1.0"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">=2.78.0, <3.0"
}
random = {
source = "hashicorp/random"
version = "3.6.0"
}
}
}

provider "azurerm" {
features {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
variable "name" {
type = string
description = "Name of the deployment"
default = "202mlmsev"
}

variable "environment" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ resource "azurerm_key_vault" "default" {
}

resource "azurerm_storage_account" "default" {
name = "st${var.name}${var.environment}"
location = azurerm_resource_group.default.location
resource_group_name = azurerm_resource_group.default.name
account_tier = "Standard"
account_replication_type = "GRS"
allow_nested_items_to_be_public = false
name = "st${var.name}${var.environment}"
location = azurerm_resource_group.default.location
resource_group_name = azurerm_resource_group.default.name
account_tier = "Standard"
account_replication_type = "GRS"
allow_blob_public_access = false

network_rules {
default_action = "Deny"
Expand All @@ -47,9 +47,14 @@ resource "azurerm_container_registry" "default" {
public_network_access_enabled = false
}

resource "random_string" "workspace_suffix" {
length = 10
special = false
}

# Machine Learning workspace
resource "azurerm_machine_learning_workspace" "default" {
name = "mlw-${var.name}-${var.environment}"
name = "mlw-${var.name}-${var.environment}-${random_string.workspace_suffix.result}"
location = azurerm_resource_group.default.location
resource_group_name = azurerm_resource_group.default.name
application_insights_id = azurerm_application_insights.default.id
Expand Down Expand Up @@ -150,7 +155,7 @@ resource "azurerm_private_endpoint" "mlw_ple" {
subnet_id = data.azurerm_subnet.ml.id

private_dns_zone_group {
name = "private-dns-zone-group"
name = "private-dns-zone-group"
private_dns_zone_ids = [
var.privatelink_api_azureml_ms_resource_id,
var.privatelink_notebooks_azure_net_resource_id
Expand Down
31 changes: 27 additions & 4 deletions test/e2e/quickstart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (
"strings"
"testing"

helper "github.com/Azure/terraform-module-test-helper"
"github.com/gruntwork-io/terratest/modules/files"
"github.com/gruntwork-io/terratest/modules/packer"
"github.com/gruntwork-io/terratest/modules/terraform"
test_structure "github.com/gruntwork-io/terratest/modules/test-structure"
"github.com/stretchr/testify/require"

helper "github.com/Azure/terraform-module-test-helper"
"github.com/gruntwork-io/terratest/modules/terraform"
)

var speicalTests = map[string]func(*testing.T){
"quickstart/201-vmss-packer-jumpbox": test201VmssPackerJumpbox,
"quickstart/101-virtual-network-manager-create-management-group-scope": test101VirtualNetworkManagerCreateManagementGroupScope,
"quickstart/201-vmss-packer-jumpbox": test201VmssPackerJumpbox,
"quickstart/202-machine-learning-moderately-secure-existing-VNet": test202machineLearningModeratelySecureExistingVnet,
}

func Test_Quickstarts(t *testing.T) {
Expand Down Expand Up @@ -174,6 +174,29 @@ func test101VirtualNetworkManagerCreateManagementGroupScope(t *testing.T) {
}, nil)
}

func test202machineLearningModeratelySecureExistingVnet(t *testing.T) {
rootPath := filepath.Join("..", "..")
examplePath := filepath.Join("quickstart", "202-machine-learning-moderately-secure-existing-VNet")
prequistePath := filepath.Join(examplePath, "prequisite")
helper.RunE2ETest(t, rootPath, prequistePath, terraform.Options{}, func(t *testing.T, output helper.TerraformOutput) {
helper.RunE2ETest(t, rootPath, examplePath, terraform.Options{
Vars: map[string]interface{}{
"vnet_name": output["vnet_name"],
"vnet_resource_group_name": output["resource_group_name"],
"training_subnet_name": output["training_subnet_name"],
"aks_subnet_name": output["aks_subnet_name"],
"ml_subnet_name": output["ml_subnet_name"],
"privatelink_api_azureml_ms_resource_id": output["privatelink_api_azureml_ms_resource_id"],
"privatelink_azurecr_io_resource_id": output["privatelink_azurecr_io_resource_id"],
"privatelink_notebooks_azure_net_resource_id": output["privatelink_notebooks_azure_net_resource_id"],
"privatelink_blob_core_windows_net_resource_id": output["privatelink_blob_core_windows_net_resource_id"],
"privatelink_file_core_windows_net_resource_id": output["privatelink_file_core_windows_net_resource_id"],
"privatelink_vaultcore_azure_net_resource_id": output["privatelink_vaultcore_azure_net_resource_id"],
},
}, nil)
})
}

func removeDuplicates(s []string) []string {
m := make(map[string]struct{})
result := []string{}
Expand Down