How to set selected public networks for an Azure Batch Account using CLI?

163 views Asked by At

Does anyone know how to configure the selected public network for a Batch Account?

I only found this article that explains how to do it from the Azure Portal: https://learn.microsoft.com/en-us/azure/batch/public-network-access?WT.mc_id=Portal-Microsoft_Azure_Batch

The Azure CLI documentation has a --public-network-access {Disabled, Enabled}, but how can one set an IP range as described in the link above through the command line?

2

There are 2 answers

0
RahulKumarShaw On

Likewise we do have Az CLI command for IP Network rule configuration in Azure Storage Account and Key Vault Unfortunately we don't have az cli command to configure IP network rules for Azure Batch acount. I have checked in the Azure Batch CLI commands doc. The only thing I found was batch account creation with public network access disabled/enabled command:

az batch account create --location westus2 --name testaccount --resource-group v-rXXXXXXdtree --public-network-access Enabled

enter image description here

0
jlo-gmail On

It IS possible to configure Azure Batch Network using the CLI.

View Current Configuration: This is useful for examining the configuration after setting it in the portal

az batch account network-profile show --resource-group $RESOURCE_GROUP  --name $RESOURCE_NAME

These commands can be used to configure the network: In this case I want to set Public Access to Selected Networks, and I want to allow a certain IP to pass

$IPAddress = (Invoke-WebRequest -uri "https://ifconfig.me/ip").Content
az batch account network-profile set --resource-group $RESOURCE_GROUP  --name $RESOURCE_NAME `
     --default-action Deny `
     --profile BatchAccount 
az batch account network-profile set --resource-group $RESOURCE_GROUP  --name $RESOURCE_NAME `
     --default-action Deny `
     --profile NodeManagement

az batch account network-profile network-rule add --resource-group $RESOURCE_GROUP  --name $RESOURCE_NAME `
     --ip-address $IPAddress `
     --profile  BatchAccount

az batch account network-profile network-rule add --resource-group $RESOURCE_GROUP  --name $RESOURCE_NAME `
     --ip-address $IPAddress `
     --profile  NodeManagement    

The output of az batch account network-profile show --resource-group $RESOURCE_GROUP --name $RESOURCE_NAME is:

    {
    "accountAccess": {
      "defaultAction": "Deny",
      "ipRules": [
        {
          "value": "xx.xx.xx.xx"
        }
      ]
    },
    "nodeManagementAccess": {
      "defaultAction": "Deny",
      "ipRules": [
        {
          "value": "xx.xx.xx.xx"
        }
      ]
    }
  }

Which corresponds to:

enter image description here