DEV Community

Cover image for Update and maintain azure resources
Samuel Ojo
Samuel Ojo

Posted on • Edited on

Update and maintain azure resources

Lab overview
In this guided lab, you perform a series of tasks and actions to manage Microsoft Azure resources. You have the opportunity to modify a network, move a virtual machine between subnets, manage access to storage containers and file shares, and work with resource locks and resource tags.

During the setup, you create a virtual network, a virtual machine, a storage account, and associated resources.

Learning objectives
In this module, you'll practice how to:

  • Update a virtual network and subnet.
  • Manage virtual machines.
  • Control storage access.
  • Manage resource tags and locks.
  • Clean up

First, we prepare the environment:

Login to Microsoft Azure

Login to Microsoft Azure

Create a resource group
In order to make clean-up easy at the end, start with creating a new resource group to hold the resources for this guided project.
Using resource groups to organize things is a quick way to ensure you can manage resources when a project is over.

1.From the Azure portal home page, in the search box, enter resource groups.
2.Select Resource groups under services.

Search Resource groups

3.Select Create

Select Create resource

4.Enter guided-project-rg in the Resource group name field.
5.The Region field will automatically populate. Leave the default value.

Resource group name

6.Select Review + create.
7.Select Create.

Create resource group

8.Return to the home page of the Azure portal by selecting Home.

Select Home

Create a virtual network with one subnet
1.From the Azure portal home page, in the search box, enter virtual networks.
2.Select virtual networks under services.

Search virtual networks

3.Select Create.

4.Scroll down to the Instance details section and enter guided-project-vnet for the Virtual network name.

5.Select Review + create.

Review + create

6.Select Create.
7.Wait for the screen to refresh and show Your deployment is complete.

Your deployment is complete

8.Select Home to return to the Azure portal home page.

Create a virtual machine
1.From the Azure portal home page, in the search box, enter virtual machines.
2.Select virtual machines under services.

Select virtual machines

3.Select Create and then select Virtual machine.

Create and then select Virtual machine

4.Select guided-project-rg for the Resource group.
5.Enter guided-project-vm for the Virtual machine name.
6.For the Image, select one of the Ubuntu Server options. (For example, Ubuntu Server 24.04 LTS - x64 Gen2)
7.Continue further on the Basics page to the Administrator account section.
8.Select Password for authentication type.
9.Enter guided-project-admin for the admin Username.
10.Enter a password for the admin account.
11.Confirm the password for the admin account.
12.Leave the rest of the settings as default settings. You can review the settings if you like, but shouldn’t change any.

  1. Select Review + create. 14.Select Create to confirm the resource cost and create the virtual machine. 15.Select Home to return to the Azure portal home page.

Create a Storage account
1.From the Azure portal home page, in the search box, enter storage accounts.
2.Select Storage accounts under services.

Select Storage accounts

3.Select Create.
4.Scroll down to the Instance details section and enter a name for the storage account. Storage accounts must be globally unique, so you may have to try a few different times to get a storage account name.
5.Select Review + create.

Select Review + create

6.Select Create.
7.Wait for the screen to refresh and show Your deployment is complete.
8.Select Home to return to the Azure portal home page.

Exercise – Update the virtual network
Scenario
You’re helping an Azure Admin maintain resources. While you won’t be responsible for maintaining the entire infrastructure, the Admin will ask you to help out by completing certain tasks. Currently, there’s a Linux virtual machine (VM) that’s underutilized, and a need for a new Linux machine to serve as an FTP server. However, the Azure admin wants to be able to track network flow and resource utilization for the needed FTP server, so has asked you to start out by provisioning a new subnet. The current subnet should be left alone, as there are future plans for using it for additional VMs.

Create a new subnet on an existing virtual network (vNet)
1.Login to Microsoft Azure at https://portal.azure.com
2.From the Azure portal home page, in the search box, enter virtual networks.
3.Select virtual networks under services.
4.Select the guided-project-vnet virtual network.

guided-project-vnet

5.From the guided-project-vnet blade, under settings, select Subnets.

Under settings select Subnets

6.To add a subnet, select + Subnet.

7.For Subnet purpose leave it as Default.
8.For Name enter: `ftpSubnet`.
9.Leave the rest of the settings alone and select Add.

Enter Subnet name as ftpSubnet

10.Select Home to return to the Azure portal home page.

Create a network security group
1.From the Azure portal home page, in the search box, enter virtual networks.
2.Select virtual networks under services.
3.Select Network security groups.

Network security groups

4.Select + Create.

Select Create Network security groups

5.Verify the subscription is correct.
6.Select the guided-project-rg resource group.
7.Enter ftpNSG for the network security group name.
8.Select Review + create.

1.Once the validation is complete, select Create.
2.Wait for the screen to refresh and display Your deployment is complete.
3.Select Go to resource.

Go to resource

Create an inbound security rule
1.Under settings, select Inbound security rules.
2.Select + Add.
3.Change the Destination port ranges from 8080 to 22.
4.Select TCP for the protocol.
5.Set the name to ftpInbound.
6.Select Add.
7.Select Home to return to the Azure portal home page.

Move the virtual machine network to the new subnet
1.Login to Microsoft Azure at https://portal.azure.com
2.From the Azure portal home page, in the search box, enter virtual machines.
3.Select virtual machines under services.
4.Select the guided-project-vm virtual machine.

Select the guided-project-vm

5.If the virtual machine is running, select Stop.
6.Wait for the Status field to update and show Stopped (deallocated).
7.Within the Networking subsection of the menu, select Network settings.
8.Select the Network interface / IP configuration hyperlink for the VM.

Select the Network interface/IP configuration

9.On the IP Configurations page, update the Subnet to ftpSubnet.
10.Select Apply.

Apply ftpSubnet

11.Select Home to return to the Azure portal home page.

Vertically scale the virtual machine
1.From the Azure portal home page, in the search box, enter virtual machines.
2.Select virtual machines under services.
3.Select the guided-project-vm virtual machine.
4.Locate the Availability + scale submenu and select Size.

Availability + scale

5.Select a new VM size D2s_v5 for example. (Note: If you don’t see the same size as shown in this exercise, select something similar.)
6.Select Resize.

New VM size

7.Select Home to return to the Azure portal home page.

Attach data disks to a virtual machine
1.From the Azure portal home page, in the search box, enter virtual machines.
2.Select virtual machines under services.
3.Select the guided-project-vm virtual machine.
4.Locate the settings submenu and select Disks.

Select Disks

5.Select Create and attach a new disk.
6.Leave LUN as default.
7.Enter ftp-data-disk for the Disk name.
8.Leave the Storage type as default.
9.Enter 20 for the Size.
10.Select Apply to create the new storage disk and attach the disk to the machine.

Create and attach a new disk

11.Select Home to return to the Azure portal home page.

Nice! Now the VM has enough storage to handle some uploads.

Configure automatic shutdown on a virtual machine
1.From the Azure portal home page, in the search box, enter virtual machines.
2.Select virtual machines under services.
3.Select the guided-project-vm virtual machine.
4.Under the Operations submenu, select Auto-shutdown.

Auto-shutdown

5.In order to let late uploads finish, set the Scheduled shutdown to 7:15:00 PM.
6.Select Save.

Scheduled shutdown

7.Select Home to return to the Azure portal home page.

Congratulations! You’ve successfully completed all of the management tasks the Azure admin needed a hand with for the virtual machine.

Exercise – Control storage access
In this lab, you’ll complete several tasks related to managing a storage account and components of the storage account.

Scenario
The Azure admin wants you to get more familiar with storage accounts, containers, and file shares. They anticipate needing to share an increasing number of files and need someone who is skilled using these services. They’ve given you a task of creating a storage container and a file share and uploading files to both locations.

Create a storage container
1.Login to Microsoft Azure at https://portal.azure.com
2.From the Azure portal home page, in the search box, enter storage accounts.
3.Select storage accounts under services.

  1. Select the storage account you created in the Prepare exercise. The storage account name is the hyperlink to the storage account. (Note: it should be associated with the resource group guided-project-rg.)

Select storage accounts

5.On the storage account blade, under the Data storage submenu, select Containers.
6.Select + Add container.

Add storage accounts

7.In the Name field, enter storage-container.
5.Select Create.

Create storage-container

Great! With a storage container created, you can upload a blob to the container. Locate a picture that you can upload, either on your computer or from the internet, and save it locally to make uploading easier.

Upload a file to the storage container
1.Select the storage container you just created.

Select the new storage container

2.Select Upload and upload the file you prepared.

Upload File

3.Once the file is ready for upload, select Upload.

With the file uploaded, notice that the Access tier is displayed. For something we uploaded just for testing, it doesn’t need to be assigned to the Hot access tier. In the next few steps, you’ll change the access tier for the file.

Change the access tier
1.Select the file you just uploaded (the file name is a hyperlink).
2.Select Change tier.

3.Select Cold.
4.Select Save.

5.Select Home to return to the Azure portal home page.

Good job! You’ve successfully uploaded a storage blob and changed the access tier from Hot to Cold. Next, you’ll work with file shares.

Create a file share
1.From the Azure portal home page, in the search box, enter storage accounts.
2.Select storage accounts under services.
3.Select the storage account you created in the Prepare exercise. The storage account name is the hyperlink to the storage account. (Note: it should be associated with the resource group guided-project-rg.)
4.On the storage account blade, under the Data storage submenu, select File shares.
5.Select + File share.

Select File share

6.On the Basics tab, in the name field enter file-share.

file-share

7.On the Backup tab, uncheck Enable backup.

Enable backup

8.Select Review + create.
9.Select Create.

Create file share

10.Once the file share is created, select Upload.
11.Upload the same file you uploaded to the blob storage or a different file, it’s up to you.

Upload file

12.Select Home to return to the Azure portal home page.

The next piece of the puzzle is figuring one way to control access to the files that have been uploaded. Azure has many ways to control files, including things like role-based access control. In this scenario, the Azure admin wants you to use shared access tokens or keys.

Create a shared access signature token
1.From the Azure portal home page, in the search box, enter storage accounts.
2.Select storage accounts under services.
3.Select the storage account you created in the Prepare exercise.
4.On the storage account blade, select Storage browser.
5.Expand Blob containers.

Note: Blob container is another name for the storage containers. Items uploaded to a storage container are called blobs.

6.Select the storage container you created earlier, storage-container.

7.Select the ellipses (three dots) on the end of the line for the image you uploaded.

Image upload

8.Select Generate SAS.
9.Set Signing method to Account key.
10.Set Signing key to Key 1
11.Set Stored access policy to None.
12.Set Permissions to Read.
13.Enter a custom start and expiry time or leave the defaults.

Generate SAS

14.Set Allowed protocols to HTTPS only.
15.Select Generate SAS token and URI.
16.Copy the Blob SAS URL and paste it in another window or tab of your browser. It should display the image you uploaded. Keep this tab or window open.

17.Select Home to return to the Azure portal home page.

With the SAS token created, anyone with that link can access the file for the duration that was set when you created the SAS token. However, controlling access to a resource or file is about more than just granting access. It’s also about being able to revoke access. To revoke access with a SAS token, you need to invalidate the token. You invalidate the token by rotating the key that was used.

Rotate access keys
1.From the Azure portal home page, in the search box, enter storage accounts.
2.Select storage accounts under services.
3.Select the storage account you created in the Prepare exercise.
4.Expand the Security + networking submenu.
5.Select Access keys.

Security + networking

6.For Key 1, select Rotate key.
7.Read and then acknowledge the warning about regenerating the access key by selecting Yes.

Rotate key

8.Once you see the success message for rotating the access key, go back to the window or tab you used to check the SAS token and refresh the page. You should receive an authentication failed error.

Before:

SAS token

*After: *

Refresh SAS token

Exercise – Manage tags and locks
If you’ve completed the previous exercises, you’ve managed added a subnet to a virtual network, made changes to a virtual machine, and worked with an Azure storage account. The final set of tasks for this guided project focus around working with tags and resource locks to help manage and monitor your environment. During this exercise you’ll go back into each of the areas you’ve already worked to add tags, locks, or a combination of both.

Scenario
Pleased with your progress so far, the Azure admin hopes that you can wrap a few things up to help with monitoring and protecting resources. They want to know that someone can’t accidentally get rid of the virtual machine that’s running as an FTP server, and they want a quick way to see what department is using resources and the resource’s purpose.

Manage tags and locks on VMs
Adding tags to resources is a quick way to be able to group and organize resources. Tags can be added at different levels, giving you the ability to organize and group resources at a level that makes sense for you.

Add tags to a virtual machine
You’ll start by adding a pair of tags to the virtual machine. One tag will be to identify the purpose of the virtual machine and the other will be to indicate the department the machine supports.

1.Login to Microsoft Azure at https://portal.azure.com
2.From the Azure portal home page, in the search box, enter virtual machines.
3.Select virtual machines under services.
4.Select the guided-project-vm virtual machine.
5.From the menu pane, select Tags.

Tags

6.On one line for Name enter Department and for Value enter Customer Service
7.On the next line, for Name enter Purpose and for Value enter FTP Server.
8.Select Apply.

Apply Tag

While you’re working on the virtual machine, it’s a great time to add a resource lock.

Add a resource lock to a VM
1.If necessary, expand the Settings submenu.
2.Select Locks.

Select Locks

3.Select + Add.
4.For the name, enter VM-delete-lock.
5.For the Lock type, select Delete.
6.You may enter a note to help remind you why you created the lock.
7.Select OK.

Add lock

That’s it. Now the VM is protected from deletion and has tags assigned to help track use. Time to move onto the network.

1.Select Home to return to the Azure portal home page.

Add tags to network resources

1.From the Azure portal home page, in the search box, enter virtual networks.
2.Select virtual networks under services.
3.Select the `guided-project-vnet` network.
4.From the menu pane, select Tags.

Note: Notice that now you can select an existing tag to apply or add a new tag. You can also select just the name or value and apply create something new in the other field.

5.For the Name select Department.
6.For the Value enter IT.
7.Select Apply.

Add tags to network resources

Now both the VNet and VM have are organized.

Congratulations! You’ve completed this exercise.

Exercise – Clean up

Warning: Failure to complete this Clean up task could result in unexpected Azure costs. This task will remove resources created during this guided project.

Remove delete locks
If you attempt to delete a resource with a delete lock, you’ll receive a warning that the operation failed due to a delete lock being in place. To avoid that, it’s important to clear delete locks from resources you intend to delete before issuing the delete command.

1.Login to Microsoft Azure at https://portal.azure.com
2.From the Azure portal home page, in the search box, enter virtual machines.
3.Select virtual machines under services.
4.Select the `guided-project-vm` virtual machine.
5.If necessary, expand the Settings submenu.
6.Select Locks.
7.Select Delete on the line for the VM-delete-lock.

Delete Locks

8.On the pop-up window, select Delete to confirm deletion of the lock.

Once the delete lock is removed, you’ll be able to delete the VM. While this was the only delete lock required by the exercise, if you applied other delete locks during the exercise, remove them now. When you’re done, select Home to return to the Azure portal home page.

Delete the project resource group

A key benefit of using resource groups is the ability to rapidly delete all of the resources assigned to a resource group at once.

1.From the Azure portal home page, in the search box, enter Resource groups.
2.Select resource groups under services.
3.Select the guided-project-rg resource group.
4.Select Delete resource group.

Selectresource group

5.Select Apply force delete…
6.Enter guided-project-rg in the confirmation box.
7.Select Delete.

Delete resource group

8.On the Delete confirmation pop-up, select Delete.

Select Delete

It will approximately 5 minutes before the resource group is fully deleted. You’ll need to refresh the resource group page every few minutes until the guided-project-rg is gone to confirm complete deletion.

Important: Recall at the beginning of the Guided Project you checked for a **NetworkWatcherRG **resource group. If there WAS a NetworkWatcherRG when you started, then you’re finished. However, if the NetworkWatcherRG was created for the guided project, you’ll need to delete the NetworkWatcherRG as well following a nearly identical process.

Delete the NetworkWatcherRG

1.From the Azure portal home page, in the search box, enter Resource groups.
2.Select resource groups under services.
3.Select the NetworkWatcherRG **resource group.
4.Select **Delete resource group
.
5.Enter NetworkWatcherRG in the confirmation box.
6.Select Delete.
7.On the Delete confirmation pop-up, select Delete.

Delete NetworkWatcherRG resource group

It will approximately 5 minutes before the resource group is fully deleted. You’ll need to refresh the resource group page every few minutes until the NetworkWatcherRG is gone to confirm complete deletion.

Congratulations – you’ve finished the Guided Project and the clean up task at the end. Now head back to Learn to finish the rest of the module.

Thanks for reading — see you in the next one

Top comments (0)