Meet Jake, an operations engineer at TechFusion Corp. Jake is tasked with automating the process of provisioning virtual machines (VMs) on Microsoft Azure. The goal is to eliminate manual steps, ensure consistency, and reduce deployment times.
Jake’s manager emphasizes the importance of following best practices, including modularizing Terraform scripts and ensuring they are reusable. With determination and a clear plan, Jake embarks on this task.

Jake’s task is to:
Create a well-structured project with modular Terraform scripts to manage various components like resource groups, networks, and VMs.
Follow best practices for organizing Terraform projects and maintaining code clarity.
Before Jake can start automating Azure VM provisioning, he needs to ensure that Terraform is installed on his workstation. Here are the steps to check if Terraform is installed and how to install it if it’s not already available.
Jake can open a terminal and run the following command to check if Terraform is installed:
terraform --version
If Terraform is installed, this command will display the installed version. If not, Jake will need to install it.
terraform --version. brew tap hashicorp/tap
brew install hashicorp/tap/terraform
terraform --version. unzip terraform_<VERSION>_linux_amd64.zip
sudo mv terraform /usr/local/bin/
terraform --version.With Terraform installed, Jake is ready to proceed with automating Azure VM provisioning.
Jake starts by organizing the project directory for modularization and scalability.
🚨 Question
Can you help Jake build the following folder structure in the workspace to get started?
vm-provisioning/
├── modules/
│ ├── resource_group/
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ ├── outputs.tf
│ ├── network/
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ ├── outputs.tf
│ ├── vm/
│ ├── main.tf
│ ├── variables.tf
│ ├── outputs.tf
├── main.tf
├── provider.tf
├── variables.tf
├── outputs.tf
This structure would allow Jake to create reusable modules for different infrastructure components.
🚨 Question
Jake, can you create a provider.tf file in the root directory to configure Azure as the cloud provider?
provider "azurerm" {
features {}
}
This enables Terraform to interact with Azure resources.
🚨 Question
Jake, can you create the necessary Terraform modules for resource groups, networks, and virtual machines? Each module should have its own directory with main.tf, variables.tf, and outputs.tf files. Ensure that the modules are reusable and follow best practices for Terraform configurations. Here’s a breakdown of what each module should include:
Make sure to output relevant information from each module, such as the resource group name, subnet ID, and VM ID, to be used in the root configuration.
Can you proceed with creating these modules?
🚨 Question
Jake, could you help us integrate the modules into the root configuration? We need to use the modules in main.tf to define the infrastructure. Here’s how you can do it:
This will help us define the infrastructure using the modules you created in previous step.
Jake performs the following steps to build and test the Terraform scripts:
terraform init
This command downloads the necessary provider plugins and prepares the working directory for other Terraform commands.
terraform plan
This command shows the changes that will be made to the infrastructure without actually applying them. Review the output to ensure that the planned changes match your expectations.
terraform apply
Terraform will prompt for confirmation before applying the changes. Type yes to proceed. This command creates the resources defined in the configuration files.
ssh azureuser@<public_ip_address>
terraform destroy
Terraform will prompt for confirmation before destroying the resources. Type yes to proceed. This command removes all the resources defined in the configuration files.
By following these steps, Jake can build, test, and verify the Terraform scripts to automate Azure VM provisioning effectively.
Outcome
Jake successfully automated Azure VM provisioning by:
Jake’s efforts streamlined operations and reduced deployment times, showcasing the power of Terraform in modern DevOps workflows.
If you want to verify the solution to this challenge, you can access it at 📕devops-challenges-1-solution. Feel free to review it, get enlightened, and enjoy the process!