Skip to content

Files

Latest commit

6167641 · Mar 29, 2022

History

History
232 lines (166 loc) · 15.5 KB

tutorial-create-secure-workspace-template.md

File metadata and controls

232 lines (166 loc) · 15.5 KB
title titleSuffix description services ms.service ms.subservice ms.reviewer ms.author author ms.date ms.topic
Use a template to create a secure workspace
Azure Machine Learning
Use a template to create an Azure Machine Learning workspace and required Azure services inside a secure virtual network.
machine-learning
machine-learning
enterprise-readiness
jhirono
larryfr
blackmist
12/02/2021
tutorial

How to create a secure workspace by using template

Templates provide a convenient way to create reproducible service deployments. The template defines what will be created, with some information provided by you when you use the template. For example, specifying a unique name for the Azure Machine Learning workspace.

In this tutorial, you learn how to use a Microsoft Bicep and Hashicorp Terraform template to create the following Azure resources:

  • Azure Virtual Network. The following resources are secured behind this VNet:
    • Azure Machine Learning workspace
      • Azure Machine Learning compute instance
      • Azure Machine Learning compute cluster
    • Azure Storage Account
    • Azure Key Vault
    • Azure Application Insights
    • Azure Container Registry
    • Azure Bastion host
    • Azure Machine Learning Virtual Machine (Data Science Virtual Machine)
    • The Bicep template also creates an Azure Kubernetes Service cluster, and a separate resource group for it.

Prerequisites

Before using the steps in this article, you must have an Azure subscription. If you don't have an Azure subscription, create a free account.

You must also have either a Bash or Azure PowerShell command line.

Tip

When reading this article, use the tabs in each section to select whether to view information on using Bicep or Terraform templates.

  1. To install the command-line tools, see Set up Bicep development and deployment environments.

  2. The Bicep template used in this article is located at https://github.com/Azure/azure-quickstart-templates/blob/master/quickstarts/microsoft.machinelearningservices/machine-learning-end-to-end-secure. Use the following commands to clone the GitHub repo to your development environment:

    [!TIP] If you do not have the git command on your development environment, you can install it from https://git-scm.com/.

    git clone https://github.com/Azure/azure-quickstart-templates
    cd azure-quickstart-templates/quickstarts/microsoft.machinelearningservices/machine-learning-end-to-end-secure
    
  1. To install, configure, and authenticate Terraform to your Azure subscription, use the steps in one of the following articles:

  2. The Terraform template files used in this article are located at https://github.com/Azure/terraform/tree/master/quickstart/201-machine-learning-moderately-secure. To clone the repo locally and change directory to where the template files are located, use the following commands from the command line:

    [!TIP] If you do not have the git command on your development environment, you can install it from https://git-scm.com/.

    git clone https://github.com/Azure/terraform
    cd terraform/quickstart/201-machine-learning-moderately-secure
    

Understanding the template

The Bicep template is made up of the main.bicep and the .bicep files in the modules subdirectory. The following table describes what each file is responsible for:

File Description
main.bicep Parameters and variables. Passing parameters & variables to other modules in the modules subdirectory.
vnet.bicep Defines the Azure Virtual Network and subnets.
nsg.bicep Defines the network security group rules for the VNet.
bastion.bicep Defines the Azure Bastion host and subnet. Azure Bastion allows you to easily access a VM inside the VNet using your web browser.
dsvmjumpbox.bicep Defines the Data Science Virtual Machine (DSVM). Azure Bastion is used to access this VM through your web browser.
storage.bicep Defines the Azure Storage account used by the workspace for default storage.
keyvault.bicep Defines the Azure Key Vault used by the workspace.
containerregistry.bicep Defines the Azure Container Registry used by the workspace.
applicationinsights.bicep Defines the Azure Application Insights instance used by the workspace.
machinelearningnetworking.bicep Defines te private endpoints and DNS zones for the Azure Machine Learning workspace.
Machinelearning.bicep Defines the Azure Machine Learning workspace.
machinelearningcompute.bicep Defines an Azure Machine Learning compute cluster and compute instance.
privateaks.bicep Defines an Azure Kubernetes Services cluster instance.

The template consists of multiple files. The following table describes what each file is responsible for:

File Description
variables.tf Variables and default values used by the template.
main.tf Specifies the Azure Resource Manager provider and defines the resource group.
network.tf Defines the Azure Virtual Network, subnets, and network security groups.
bastion.tf Defines the Azure Bastion host and associated NSG. Azure Bastion allows you to easily access a VM inside a VNet using your web browser.
dsvm.tf Defines the Data Science Virtual Machine (DSVM). Azure Bastion is used to access this VM through your web browser.
workspace.tf Defines the Azure Machine Learning workspace. Including dependency resources for Azure Storage, Key Vault, Application Insights, and Container Registry.
compute.tf Defines an Azure Machine Learning compute instance and cluster.

Tip

The Terraform Azure provider supports additional arguments that are not used in this tutorial. For example, the environment argument allows you to target cloud regions such as Azure Government and Azure China 21ViaNet.


Important

The DSVM and Azure Bastion is used as an easy way to connect to the secured workspace for this tutorial. In a production environment, we recommend using an Azure VPN gateway or Azure ExpressRoute to access the resources inside the VNet directly from your on-premises network.

Configure the template

To run the Bicep template, use the following commands from the machine-learning-end-to-end-secure where the main.bicep file is:

  1. To create a new Azure Resource Group, use the following command. Replace exampleRG with your resource group name, and eastus with the Azure region you want to use:

    az group create --name exampleRG --location eastus
    
    New-AzResourceGroup -Name exampleRG -Location eastus
    

  2. To run the template, use the following command:

    az deployment group create \
        --resource-group exampleRG \
        --template-file main.bicep \
        --parameters \
        prefix=myprefix \
        dsvmJumpboxUsername=azureadmin \
        dsvmJumpboxPassword=securepassword
    
    $dsvmPassword = ConvertTo-SecureString "mysecurepassword" -AsPlainText -Force
    New-AzResourceGroupDeployment -ResourceGroupName exampleRG `
        -TemplateFile ./main.bicep `
        -prefix "myprefix" `
        -dsvmJumpboxUsername "azureadmin" `
        -dsvmJumpboxPassword $dsvmPassword
    

    [!WARNING] You should avoid using plain text strings in script or from the command line. The plain text can show up in event logs and command history. For more information, see ConvertTo-SecureString.


To run the Terraform template, use the following commands from the 201-machine-learning-moderately-secure directory where the template files are:

  1. To initialize the directory for working with Terraform, use the following command:

    terraform init
    
  2. To create a configuration, use the following command. Use the -var parameter to set the value for the variables used by the template. For a full list of variables, see the variables.tf file:

    terraform plan \
        -var name=myworkspace \
        -var environment=dev \
        -var location=westus \
        -var dsvm_name=jumpbox \
        -var dsvm_host_password=secure_password \
        -out azureml.tfplan
    

    After this command completes, the configuration is displayed in the terminal. To display it again, use the terraform show azureml.tfplan command.

  3. To run the template and apply the saved configuration to your Azure subscription, use the following command:

    terraform apply azureml.tfplan
    

    The progress is displayed as the template is processed.


Connect to the workspace

After the template completes, use the following steps to connect to the DSVM:

  1. From the Azure portal, select the Azure Resource Group you used with the template. Then, select the Data Science Virtual Machine that was created by the template. If you have trouble finding it, use the filters section to filter the Type to virtual machine.

    :::image type="content" source="./media/tutorial-create-secure-workspace-template/select-vm.png" alt-text="Screenshot of filtering and selecting the vm.":::

  2. From the Overview section of the Virtual Machine, select Connect, and then select Bastion from the dropdown.

    :::image type="content" source="./media/tutorial-create-secure-workspace-template/connect-bastion.png" alt-text="Screenshot of selecting to connect using Bastion.":::

  3. When prompted, provide the username and password you specified when configuring the template and then select Connect.

    [!IMPORTANT] The first time you connect to the DSVM desktop, a PowerShell window opens and begins running a script. Allow this to complete before continuing with the next step.

  4. From the DSVM desktop, start Microsoft Edge and enter https://ml.azure.com as the address. Sign in to your Azure subscription, and then select the workspace created by the template. The studio for your workspace is displayed.

Next steps

Important

The Data Science Virtual Machine (DSVM) and any compute instance resources bill you for every hour that they are running. To avoid excess charges, you should stop these resources when they are not in use. For more information, see the following articles:

To continue learning how to use the secured workspace from the DSVM, see Tutorial: Get started with a Python script in Azure Machine Learning.

To learn more about common secure workspace configurations and input/output requirements, see Azure Machine Learning secure workspace traffic flow.