In this tutorial I have executed all the below mentioned commands in Azure CLI.
This must be the very first line in your bash script.
User can comment and uncomment any line as per the requirement.
This must be the very first line in your bash script.
#!/bin/bash
In the first step you have to login to your Azure subscription account using
below mentioned command. User can skip this command if already logged-in.
#Login to Azure subscription account
az login
After executing the command user will see similar message on console.
"to sign in, use a web browser to open the page https://aka.ms/devicelogin
and enter the code #h98mdtxxk to authenticate."
In the second step declare all the required variables at one place.
#Declare all variables at one place
export location="southeastasia"
export resourceGroup="azurecertifications-resource-group"
export storageAccountName="azstorageaccount02"
#Available options are [ Standard_LRS, Standard_ZRS, #Standard_GRS, Standard_RAGRS, Premium_LRS ]
export skuName = "Standard_LRS"
#Available options are [ Storage, BlobStorage ]
export kind="Storage"
#enables Storage Service encryption on the Storage Service. Only Azure Blob and #Azure File Services are supported.
export enableEncryptionService="Blob"
#Boolean Type. Accept True or False only.
export enableHttpsTrafficOnly="False"
We can skip below step if we already know the region name where we want to create resource group.
#Get Azure Resource Locations
az account list-locations --query "[].{Region:name}"
--out table
Below command will create a resource group in the given region. Resource group is a container that holds related resources for an Azure solution. The
resource group can include all the resources for the solution, or only
those resources that you want to manage as a group.
If you already have a resource group created and want to create Azure storage account in that group only then you can skip this step.
# Create a resource group
az group create --name $resourceGroup --location $location
Note: When
creating a resource group, you need to provide a location for that resource
group. You may be wondering, "Why does a resource group need a location?
And, if the resources can have different locations than the resource group,
why does the resource group location matter at all?" The resource group
stores metadata about the resources. Therefore, when you specify a location
for the resource group, you are specifying where that metadata is stored. For
compliance reasons, you may need to ensure that your data is stored in a
particular region.
|
#Create Azure Storage Account
az storage account create --name $storageAccountName --resource-group $resourceGroup
--location $location --sku $skuName --kind $kind --encryption
$enableEncryptionService --https-only $enableHttpsTrafficOnly
#Get Connection String for Storage Account
az storage account show-connection-string --resource-group
$resourceGroup --name $storageAccountName
You will get similar output. One thing to note here is do not share your Storage Account key with anyone. To show the output of the command I have changed the Account key here.
{
"connectionString": "DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=azstorageaccount02;AccountKey=JspnOj3McxwpZupnAHx/IduP/oSiRw25r/zdFSzHE+2beesGfumEUiQTCx0OLt/TI+9iwtTPNGOPnk6r1y0ueeQ=="
}
# Delete Storage Account
#Method 1
az storage account delete --ids /subscriptions/{SubscriptionID}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}
Replace the placeholder text with actual value and then delete storage account if you do not it any more.
#Method 2
az storage account delete --name $storageAccountName --resource-group $resourceGroup
All the steps which we have done here using Azure CLI you can do the same and manage Azure blob storage resources using Azure Storage Explorer.
No comments:
Post a Comment