Prerequisite: Below are the prerequisites for following this post. 1. Azure CLI. Refer below articles to install Azure CLI.
az login
pip install azure-identity
pip install azure-mgmt-storage
from azure.mgmt.storage import StorageManagementClient
from azure.identity import AzureCliCredential
from azure.mgmt.storage.models import StorageAccountCreateParameters, Sku
subscription_id = "REPLACE_WITH_SUBSCRIPTION_ID"
RESOURCE_GROUP_NAME = "REPLACE_WITH_RESOURCE_GROUP_NAME"
storage_account_name = "REPLACE_WITH_GLOBALLY_UNIQUE_STORAGE_ACCOUNT_NAME"
credential = AzureCliCredential()
storage_client = StorageManagementClient(credential, subscription_id)
response = storage_client.storage_accounts.begin_create(
resource_group_name,
storage_account_name,
StorageAccountCreateParameters(
sku=Sku(name="Standard_LRS"),
kind="Storage",
location="westus",
enable_https_traffic_only=True,
),
)
storage_account = response.result()
print(
f"Storage account {storage_account.name} provision state is {storage_account.provisioning_state}"
)
from azure.mgmt.storage import StorageManagementClient
from azure.identity import AzureCliCredential
from azure.mgmt.storage.models import StorageAccountCreateParameters, Sku
subscription_id = "REPLACE_WITH_SUBSCRIPTION_ID"
RESOURCE_GROUP_NAME = "REPLACE_WITH_RESOURCE_GROUP_NAME"
storage_account_name = "REPLACE_WITH_GLOBALLY_UNIQUE_STORAGE_ACCOUNT_NAME"
credential = AzureCliCredential()
storage_client = StorageManagementClient(credential, subscription_id)
response = storage_client.storage_accounts.begin_create(
resource_group_name,
storage_account_name,
StorageAccountCreateParameters(
sku=Sku(name="Standard_LRS"),
kind="Storage",
location="westus",
enable_https_traffic_only=True,
),
)
storage_account = response.result()
print(
f"Storage account {storage_account.name} provision state is {storage_account.provisioning_state}"
)
Category: Azure