Skip to content

Vitalii-devops/azure_task_10_deploy_vm_to_availability_zone

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create a Virtual Machine with Powershell

When you learn about the SLA and availability, you know that with a single VM in Azure, you are guaranteed to have only 99.9% of the VM uptime. That means your app can be unavailable for more than 40 minutes a week, and you won't get any refunds or discounts! Luckily, there are several options you can use to affect the SLA for your VM infrastructure, and today, you will explore one of them—availability zones.

You will get a 99.99% uptime SLA for two VMs deployed to two distinct availability zones. This means both VMs can be unavailable simultaneously for no longer than 4 minutes each month. In this task, you will practice deploying VMs to availability zones.

Prerequisites

Before completing any task in the module, make sure that you followed all the steps described in the Environment Setup topic, in particular:

  1. Ensure you have an Azure account and subscription.

  2. Create a resource group called "mate-resources" in the Azure subscription.

  3. In the "mate-resources" resource group, create a storage account (any name) and a "task-artifacts" container.

  4. Install PowerShell 7 on your computer. All tasks in this module use Powershell 7. To run it in the terminal, execute the following command:

    pwsh
    
  5. Install Azure module for PowerShell 7:

    Install-Module -Name Az -Repository PSGallery -Force
    

If you are a Windows user, before running this command, please also run the following: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

  1. Log in to your Azure account using PowerShell:
    Connect-AzAccount -TenantId <your Microsoft Entra ID tenant id>
    

Requirements

In this task, you will need to write and run a Powershell script, which deploys 2 Virtual Machines across 2 distinct availability zones:

  1. Write your script code to the file 'task.ps1' in this repository:

    • In the script, you should assume that you are already logged in to Azure and using the correct subscription (don't use commands 'Connect-AzAccount' and 'Set-AzContext', if needed — just run them on your computer before running the script).

    • Use any region you want, for example uksouth.

    • Script already has code that deploys a single VM with no infrastructure redundancy. Update the code to deploy two VMs into two distinct availability zones. Check the documentation of the New-AzVm comandlet to learn how to set an availability zone during VM creation.

    • Both VMs should be deployed to the default subnet of the virtual network vnet, use network security group defaultnsg, and use ssh key linuxboxsshkey (check the documentation of New-AzVm—it allows you to specify the names of those resources as comandlet parameters).

    • VMs should use images with the friendly name Ubuntu2204 and size Standard_B1s.

    • Note that in this task, you are not required to deploy a public IP resource for the VMs.

  2. When the script is ready, run it to deploy resources to your subscription.

  3. Run artifacts generation script scripts/generate-artifacts.ps1.

  4. Test yourself using the script scripts/validate-artifacts.ps1.

  5. Make sure that changes to both task.ps1 and result.json are committed to the repo, and submit the solution for review.

  6. When the solution is validated, delete the resources you deployed with the PowerShell script—you won't need them for the next tasks.

How to complete tasks in this module

Tasks in this module are relying on 2 PowerShell scripts:

  • scripts/generate-artifacts.ps1 generates the task “artifacts” and uploads them to cloud storage. An “artifact” is evidence of a task you completed. Each task will have its own script, which will gather the required artifacts. The script also adds a link to the generated artifact in the artifacts.json file in this repository—make sure to commit changes to this file after you run the script.
  • scripts/validate-artifacts.ps1 validates the artifacts generated by the first script. It loads information about the task artifacts from the artifacts.json file.

Here is how to complete tasks in this module:

  1. Clone task repository

  2. Make sure you completed the steps described in the Prerequisites section

  3. Complete the task described in the Requirements section

  4. Run scripts/generate-artifacts.ps1 to generate task artifacts. The script will update the file artifacts.json in this repo.

  5. Run scripts/validate-artifacts.ps1 to test yourself. If tests fail, follow the recommendation from the test script error message to fix or re-deploy your infrastructure. When you are ready to test yourself again — re-generate the artifacts (step 4) and re-run tests again.

  6. When all tests will pass — commit your changes and submit the solution for review.

Pro tip: If you are stuck with any of the implementation steps, run scripts/generate-artifacts.ps1 and scripts/validate-artifacts.ps1. The validation script might give you a hint on what to do.

Prerequisites

Before completing any task in the module, make sure that you followed all the steps described in the Environment Setup topic, in particular:

  1. Ensure you have an Azure account and subscription.

  2. Create a resource group called mate-resources in the Azure subscription.

  3. In the mate-resources resource group, create a storage account (any name) and a task-artifacts container.

  4. Install PowerShell 7 on your computer. All tasks in this module use Powershell 7. To run it in the terminal, execute the following command:

    pwsh
    
  5. Install Azure module for PowerShell 7:

    Install-Module -Name Az -Repository PSGallery -Force
    

If you are a Windows user, before running this command, please also run the following: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

  1. Log in to your Azure account using PowerShell:
    Connect-AzAccount -TenantId <your Microsoft Entra ID tenant id>
    

Requirements

In this task, you will need to write and run a Powershell script, which deploys 2 Virtual Machines across 2 distinct availability zones:

  1. Write your script code to the file 'task.ps1' in this repository:

    • In the script, you should assume that you are already logged in to Azure and using the correct subscription (don't use commands 'Connect-AzAccount' and 'Set-AzContext', if needed - just run them on your computer before running the script).

    • Use any region you want, for example uksouth.

    • Script already has code that deploys a single VM with no infrastructure redundancy. Update the code to deploy two VMs into two distinct availability zones. Check the documentation of the New-AzVm comandlet to learn how to set an availability zone during VM creation.

    • Both VMs should be deployed to the default subnet of the virtual network vnet, use network security group defaultnsg, and use ssh key linuxboxsshkey (check the documentation of New-AzVm—it allows you to specify the names of those resources as comandlet parameters).

    • VMs should use images with the friendly name Ubuntu2204 and size Standard_B1s.

    • Note that in this task, you are not required to deploy a public IP resource for the VMs.

  2. When the script is ready, run it to deploy resources to your subscription.

  3. Run artifacts generation script scripts/generate-artifacts.ps1.

  4. Test yourself using the script scripts/validate-artifacts.ps1.

  5. Make sure that changes to both task.ps1 and result.json are committed to the repo, and submit the solution for review.

  6. When the solution is validated, delete the resources you deployed with the PowerShell script — you won't need them for the next tasks.

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • PowerShell 100.0%