try to make 202-mlmsev testable

This commit is contained in:
hezijie
2024-01-02 15:05:51 +08:00
committed by lonegunmanb
parent a39e09c2d5
commit 9259270d0c
10 changed files with 213 additions and 14 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -0,0 +1,5 @@
variable "location" {
type = string
default = "East US"
description = "Location of the resources"
}

View File

@ -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 {}
}