apps-on-azure

Resource Groups

Resource Groups (RGs) are a container for all other Azure resources - VMs, SQL databases, Kubernetes clusters all get created inside a Resource Group. You might have one Resource Group for each application, containing all the components that app needs. Management permissions can be applied at the Resource Group level, and it’s easy to remove all the resources by deleting the group.

Reference

Create a new RG in the portal

Open https://portal.azure.com and sign in if you need to.

Select Create a Resource from the Azure services section, search for Resource Groups and create a new one.

Each region is a collection of nearby data centres. Typically you put all the components for an app into the same region, for minimal network latency. You may put additional deployments in other regions for high availability.

You can’t do much with a Resource Group on its own, but we’ll always create an RG to house other resources.

Create an RG with the Azure CLI

You manage Resource Groups with the az group commands. Print the help to see what’s available:

az group --help

📋 Print the help text for creating a new RG. What parameters do you need to supply?

Not sure? Help applies for groups of commands and individual commands: ``` az group create --help ``` The only required parameters are the group name and the region - which is confusingly referred to as the _location_ in most other `az` commands.


The CLI help text shows you how to find the list of regions too.

📋 Create a new RG called labs-<your-name>-rg-2 in a different region from the first, with the same tag courselabs=azure.

Find the list of regions (this command is in the group create help text):

az account list-locations -o table

Create a group, this example uses West US 2:

az group create -n labs-<your-name>-rg-2 -l westus2 --tags courselabs=azure

When you create a resource with the CLI it waits until resource is ready and then prints the details.

Manage Resource Groups

The az command line works in a consistent way for all resources. You create, list, show and delete them using the same verbs.

📋 Print the list of all your RGs, showing the output in table form.

az group list -o table 

We added the same tag to both RGs. Tags are simple key-value pairs which you can add to all resource to help manage them. You might have an environment tag to identify resources in dev or UAT environments.

You can add a query parameter to list commands to filter the results. Complete this query to print RGs which have the matching tag:

az group list -o table --query "[?tags.courselabs ...

The query parameter uses JMESPath, a JSON query language. Results find all matching RGs across all regions.

Delete Resource Groups

The group delete command removes a Resource Group - and any resources inside that group. You can have an RG with five Hadoop clusters and hundreds of Docker containers, and deleting the group will stop and remove the services and delete the data.

Because resource deletion is dangerous, the az command doesn’t let you delete multiple groups based on a query. Try this - it will fail:

# this will produce an error saying a group name is needed:
az group delete --query "[?tags.courselabs=='azure']"

📋 Delete the first resource group labs-<your-name>-rg-1 using the command line.

az group delete -n labs-<your-name>-rg-1

You’ll be asked for confirmation and then the command will wait until the group is deleted.

Lab

Sometimes you do want to delete all the resources that match in a query. How can you delete all the RGs with the courselabs tag with a single command?

Stuck? Try hints or check the solution.