Creating core Azure resources

In the previous recipe, you created and used the basic Azure management environment by downloading the key modules, logging in to Azure, and having a brief look around. In this recipe, you create certain key Azure assets, including a resource group, a storage account, and tags.

With Azure, all Azure resources are created within a resource group. A resource group is a grouping of Azure resources. Any storage you create within Azure resides in a storage account, a fundamental building block within Azure.

All storage you use with any Azure feature always exists within a storage account. You create a storage account within one of the Azure regions you saw in the Using PowerShell with Azure recipe. When you create your storage account, you also specify the level of resiliency and durability that's provided. There are several levels of replication provided within Azure, which provide for multiple copies of the data that are replicated automatically in both the local Azure data center but also in other data centers. The extra resilience, which does come at a price, provides greater levels of recovery should the unthinkable happen and an entire data center somehow fails in a catastrophic way.

You can provision a storage account as either standard or premium. A standard storage account allows you to store any kind of data (as you see in the Exploring your storage account recipe). A premium storage account provides extra features, but at a cost.

Tags are name/value pairs that allow you to organize your resources within your subscription. For more details on how you can use tags to organize your Azure resources, see https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-using-tags/.

Getting ready

This recipe requires you to have an Azure account and that you have your system configured with the Az module, which was done in the Using PowerShell with Azure recipe.

How to do it...

  1. Set values for key variables:
    $Locname    = 'uksouth'     # location name
    $RgName     = 'packt_rg'    # resource group we are using
    $SAName     = 'packt42sa'   # Storage account name
  2. Log in to your Azure account:
    $CredAZ = Get-Credential
    Login-AzAccount -Credential $CredAZ
  3. Create a resource group and tag it:
    $RGTag  = [Ordered] @{Publisher='Packt'}
    $RGTag +=           @{Author='Thomas Lee'}
    $RGHT = @{
      Name     = $RgName
      Location = $Locname
      Tag      = $RGTag
    }
    $RG = New-AzResourceGroup @RGHT
    $RG
  4. View the Resource Group details:
    Get-AzResourceGroup -Name $RGName |
      Format-List -Property *
  5. Test to see if a Storage Account name is available:
    Get-AzStorageAccountNameAvailability $SAName
  6. Create a new Storage Account within our newly created resource group:
    $SAHT = @{
      Name              = $SAName
      SkuName           = 'Standard_LRS'
      ResourceGroupName = $RgName
      Tag               = $RGTag
      Location          = $Locname
    
    }
    New-AzStorageAccount @SAHT
  7. Get an overview of the Storage Account in this Resource Group:
    $SA = Get-AzStorageAccount -ResourceGroupName $RgName
    $SA |
      Format-List -Property *
  8. Get primary endpoints for the Storage Account:
    $SA.PrimaryEndpoints
  9. Review SKU for this Storage Account:
    $SA.Sku
  10. View the value of the C property of your Storage Account:
    $SA.Context

How it works…

In step 1, you set the value of a number of key variables that are used in this recipe. In step 2, you logged in to your Azure account. Neither of these steps produce output.

In step 3, you created a new Azure Resource Group and gave it some nice tags. This step produces output like this:

How it works…

In step 4, you got the Resource Group and viewed its properties, as follows:

How it works…

To create a Storage Account, you needed to check that the name was available, as shown in step 5:

How it works…

In step 6, you created a new Storage Account:

How it works…

In step 7, you used the Get-AzStorageAccount cmdlet to view details of the Storage Account, which looks like this:

How it works…

In step 8, you examined the key endpoints for your newly created Storage Account, which looks like this:

How it works…

In step 9, you viewed the SKU for your Storage Account, like this:

How it works…

In step 10, you viewed the details of the Storage Account's Context property, which looks like this:

How it works…

There's more...

With step 1, you created some variables and gave them the appropriate values. When you go to replicate these recipes, you may find that some of the names that are used here are already in use by other Azure customers. To run this and other recipes in this chapter, you may need to adjust these values. For example, the Storage Account name that was used in the previous edition of this book has been taken by someone so it cannot be used!

In step 2, you used Login-AzAccount to log in to Azure. In earlier versions of the Azure cmdlets, this cmdlet was somewhat restricted and did not support Microsoft accounts (for example, accounts that end in @MSN.Com). That shortcoming is eliminated in the Az cmdlets.

In step 6, you created a new Storage Account, but only after you determined the storage account name was valid. With Azure, the Storage Name (an important part of the URIs that PowerShell uses to connect to Azure) must be globally unique. Thus, no two Azure customers in the world can use the same storage account names. To ensure that your account is valid, in step 5, you used the cmdlet Get-AzStorageAccountNameAvailability to test that the name was indeed allowed. If the name was not valid, you would have to choose another storage account name and amend the recipe accordingly.

See also

Resource groups are a fundamental part of the Azure Resource Management API. For a good introduction to the Azure Resource Management API, see https://docs.microsoft.com/en-us/azure/storage/common/storage-introduction.

Storage in Azure is both complex and somewhat different to on-premise storage solutions. Take a look at https://docs.microsoft.com/en-us/azure/storage/common/storage-introduction for an introduction to Azure Storage.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.63.136