Skip to content

Commit

Permalink
Add public IP option to AzureML Computes (#21377)
Browse files Browse the repository at this point in the history
* Add identity to iothub data source.

* Add public ip option to azure ML computes.

* Fix comments.

* fix property name in the acceptance tests

* Add private endpoint to tests.

* Add subresource names.

* Open all traffic on NSG.

* Add DNS zone configuration.

* Add fmt arguments.

* Fix private dns zone name.

* Fix private endpoint for cluster.

* Change providers to allow Resource group deletion.

* Go back to less permissive NSG

* Remove public iip option from compute instance as it isn`t returned yet.

* remove RequiresWith for node_public_ip_enabled since it only applies if the property is set to false

---------

Co-authored-by: Steph <steph@hashicorp.com>
  • Loading branch information
Lucasjuv and stephybun authored May 31, 2023
1 parent fd2b791 commit 3e5769f
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ func resourceComputeCluster() *pluginsdk.Resource {
ForceNew: true,
},

"node_public_ip_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
ForceNew: true,
},

"ssh": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -175,12 +182,17 @@ func resourceComputeClusterCreate(d *pluginsdk.ResourceData, meta interface{}) e
return tf.ImportAsExistsError("azurerm_machine_learning_compute_cluster", id.ID())
}

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`")
}

vmPriority := machinelearningcomputes.VMPriority(d.Get("vm_priority").(string))
computeClusterAmlComputeProperties := machinelearningcomputes.AmlComputeProperties{
VMSize: utils.String(d.Get("vm_size").(string)),
VMPriority: &vmPriority,
ScaleSettings: expandScaleSettings(d.Get("scale_settings").([]interface{})),
UserAccountCredentials: expandUserAccountCredentials(d.Get("ssh").([]interface{})),
EnableNodePublicIP: pointer.To(d.Get("node_public_ip_enabled").(bool)),
}

computeClusterAmlComputeProperties.RemoteLoginPortPublicAccess = utils.ToPtr(machinelearningcomputes.RemoteLoginPortPublicAccessDisabled)
Expand Down Expand Up @@ -270,6 +282,11 @@ func resourceComputeClusterRead(d *pluginsdk.ResourceData, meta interface{}) err
d.Set("vm_priority", string(pointer.From(props.VMPriority)))
d.Set("scale_settings", flattenScaleSettings(props.ScaleSettings))
d.Set("ssh", flattenUserAccountCredentials(props.UserAccountCredentials))
enableNodePublicIP := true
if props.EnableNodePublicIP != nil {
enableNodePublicIP = *props.EnableNodePublicIP
}
d.Set("node_public_ip_enabled", enableNodePublicIP)
if props.Subnet != nil {
d.Set("subnet_resource_id", props.Subnet.Id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ resource "azurerm_machine_learning_compute_cluster" "test" {
vm_size = "STANDARD_DS2_V2"
machine_learning_workspace_id = azurerm_machine_learning_workspace.test.id
subnet_resource_id = azurerm_subnet.test.id
node_public_ip_enabled = false
description = "Machine Learning"
tags = {
environment = "test"
Expand All @@ -225,7 +226,8 @@ resource "azurerm_machine_learning_compute_cluster" "test" {
key_value = var.ssh_key
}
depends_on = [
azurerm_subnet_network_security_group_association.test
azurerm_subnet_network_security_group_association.test,
azurerm_private_endpoint.test,
]
}
`, template, data.RandomIntOfLength(8))
Expand Down Expand Up @@ -367,7 +369,11 @@ resource "azurerm_machine_learning_compute_cluster" "test" {
func (r ComputeClusterResource) template_basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
data "azurerm_client_config" "current" {}
Expand Down Expand Up @@ -426,7 +432,11 @@ resource "azurerm_machine_learning_workspace" "test" {
func (r ComputeClusterResource) template_complete(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
data "azurerm_client_config" "current" {}
Expand Down Expand Up @@ -478,6 +488,37 @@ resource "azurerm_machine_learning_workspace" "test" {
}
}
resource "azurerm_private_dns_zone" "test" {
name = "privatelink.api.azureml.ms"
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_private_dns_zone_virtual_network_link" "test" {
name = "test-vlink"
resource_group_name = azurerm_resource_group.test.name
private_dns_zone_name = azurerm_private_dns_zone.test.name
virtual_network_id = azurerm_virtual_network.test.id
}
resource "azurerm_private_endpoint" "test" {
name = "test-pe-%[6]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
subnet_id = azurerm_subnet.test.id
private_service_connection {
name = "test-mlworkspace-%[7]d"
private_connection_resource_id = azurerm_machine_learning_workspace.test.id
subresource_names = ["amlworkspace"]
is_manual_connection = false
}
private_dns_zone_group {
name = "test"
private_dns_zone_ids = [azurerm_private_dns_zone.test.id]
}
}
resource "azurerm_virtual_network" "test" {
name = "acctestvirtnet%[6]d"
address_space = ["10.1.0.0/16"]
Expand Down Expand Up @@ -515,5 +556,6 @@ resource "azurerm_subnet_network_security_group_association" "test" {
}
`, data.RandomInteger, data.Locations.Primary,
data.RandomIntOfLength(12), data.RandomIntOfLength(15), data.RandomIntOfLength(16),
data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger,
data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ resource "azurerm_machine_learning_compute_instance" "test" {
Label1 = "Value1"
}
depends_on = [
azurerm_subnet_network_security_group_association.test
azurerm_subnet_network_security_group_association.test,
]
}
`, template, data.RandomIntOfLength(8), data.RandomIntOfLength(8), data.RandomIntOfLength(8))
Expand Down Expand Up @@ -287,7 +287,11 @@ resource "azurerm_machine_learning_compute_instance" "test" {
func (r ComputeInstanceResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
data "azurerm_client_config" "current" {}
Expand Down Expand Up @@ -338,5 +342,6 @@ resource "azurerm_machine_learning_workspace" "test" {
}
`, data.RandomInteger, data.Locations.Primary,
data.RandomIntOfLength(12), data.RandomIntOfLength(15), data.RandomIntOfLength(16),
data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger,
data.RandomInteger, data.RandomInteger)
}
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@ resource "azurerm_machine_learning_inference_cluster" "test" {
func (r InferenceClusterResource) template(data acceptance.TestData, vmSize string, nodeCount int) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
data "azurerm_client_config" "current" {}
Expand Down Expand Up @@ -468,7 +472,11 @@ resource "azurerm_kubernetes_cluster" "test" {
func (r InferenceClusterResource) privateTemplate(data acceptance.TestData, vmSize string, nodeCount int) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
data "azurerm_client_config" "current" {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ resource "azurerm_machine_learning_synapse_spark" "test" {
func (r SynapseSparkResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
data "azurerm_client_config" "current" {}
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/machine_learning_compute_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ The following arguments are supported:

* `local_auth_enabled` - (Optional) Whether local authentication methods is enabled. Defaults to `true`. Changing this forces a new Machine Learning Compute Cluster to be created.

* `node_public_ip_enabled` - (Optional) Whether the compute cluster will have a public ip. To set this to false a `subnet_resource_id` needs to be set. Defaults to `true`. Changing this forces a new Machine Learning Compute Cluster to be created.

* `ssh_public_access_enabled` - (Optional) A boolean value indicating whether enable the public SSH port. Changing this forces a new Machine Learning Compute Cluster to be created.

* `subnet_resource_id` - (Optional) The ID of the Subnet that the Compute Cluster should reside in. Changing this forces a new Machine Learning Compute Cluster to be created.
Expand Down

0 comments on commit 3e5769f

Please sign in to comment.