Search code examples
azureazure-cli

How to provide Connectivity method (Public endpoint selected networks ) via Azure Cli when creating storage account


I am creating storage account where I need to use Connectivity method: Public endpoint(selected networks) where I have to provide Virtual network subscription and Virtual network.

How can I create it via Azure CLI or via Azure PowerShell module. I don't see there any parameter which I can use to provide such details.


Solution

  • One of the workarounds I did to create the storage account in the selected public networks using AZ CLI is:

    • Created the virtual network and a default subnet using AZ CLI:
    az network vnet create --name myVNet --resource-group HariTestRG --subnet-name default
    
    • Created the service endpoint of Microsoft.Storage for the above created Virtual Network using AZ CLI:
    az network vnet subnet update -g HariTestRG -n default --vnet-name myvnet --service-endpoints Microsoft.Storage
    

    Then you can create the Azure Storage Account on the selected public networks using your VNet and subnet name from the AZ CLI:

    az storage account create --name samplestorageaccount1204 --resource-group HariTestRG --vnet-name myvnet --subnet default --default-action Allow
    

    Or

    You can also add the network rule to move the storage account to the specified subnet in the virtual network:

    az storage account network-rule add -g HariTestRG --account-name samplestorageaccount1205 --vnet-name myvnet --subnet default
    

    enter image description here

    Here the Network access is enabled for the specific subnet in the Virtual Network to Azure Storage account.

    To allow or deny network access, add specific service endpoints to the specific Subnets or Virtual Networks and manage the firewall, refer this MSFT Document.