- Lab
- A Cloud Guru
Using the Virtual Machine Module
Welcome to the Using the Virtual Machine Module lab. In this lab, we will cover three objectives: 1. Use an existing subnet as a data source 1. Deploy an Azure VM using the Virtual Machine Module 1. Add a Network Security Group to the VM By the end of this lab, you'll have successfully deployed Azure VMs to an existing subnet and added security groups to the VMs to access a web page.
Path Info
Table of Contents
-
Challenge
Use an Existing Subnet as a Data Source
In this objective, you will add an existing subnet as a data source to use in the deployment of the Azure VM.
- Log into the Azure CLI using the provided credentials.
- Retrive the provided resource group and virtual network names.
- Create a new Terraform configuration using the
azurerm
. - Set
skip_provider_registration
to true for theazurerm
provider block. - Create data sources for the existing resource group and subnet named
app
. - Create the necessary input variables and
terraform.tfvars
file. - Add an output to display the subnet ID.
- Deploy the configuration and verify the correct output is displayed in the terminal.
-
Challenge
Deploy an Azure VM using the Virtual Machine Module
In this objective, you will use the Azure Virtual Machine Module to deploy an Azure VM to the existing subnet. The VM will have a public IP address and will load a web application using the
custom_data
parameter.- Add a TLS private key and Azure public IP address to the configuration
- Add a
custom_data.tpl
file with the linked contents from the course repository. - Add the virtual machine module using the following values:
image_os
: "linux"os_simple
: "UbuntuServer"size
: "Standard_F2"
- Set the
custom_data
argument to a value that uses thetemplatefile
function and the providedcustom_data.tpl
file. - Add the necessary input variables and use
80
for the application port. - Add an output for the public IP address of the virtual machine.
- Initialize the configuration to add the virtual-machine module and TLS provider.
- Validate and deploy the configuration.
-
Challenge
Add a Network Security Group to the VM
In this objective, you will add a Network Security Group (NSG) and NSG rule to allow traffic to the application port defined for the virtual machine. Then associate the NSG with the virtual machine's network interface.
- Add the
azurerm_network_security_group
andazurerm_network_security_rule
resources to your configuration. The rule should allow traffic from anywhere to reach the application port overTcp
. - Add a
azurerm_network_interface_security_group_association
resource to associate the NSG with the network interface of the virtual machine. - Validate and deploy the configuration.
- Verify that you can reach the website at the public IP address and port.
- Add the
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.