Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Why patterns solve common problems
📖 Scenario: You are working as a cloud engineer. Your team wants to create a reusable way to deploy a simple web server on a cloud virtual machine. This pattern will help everyone avoid repeating the same setup steps and reduce mistakes.
🎯 Goal: Build a Terraform configuration that uses a pattern to deploy a virtual machine with a web server installed. This pattern will be easy to reuse for future projects.
📋 What You'll Learn
Create a Terraform resource for a virtual machine with a fixed name
Add a variable to configure the machine size
Use a provisioner to install a web server
Add a tag to identify the machine as part of the web server pattern
💡 Why This Matters
🌍 Real World
Cloud engineers often create reusable Terraform patterns to speed up deployment and reduce errors when setting up infrastructure.
💼 Career
Understanding how to build and use patterns in Terraform is essential for roles like Cloud Engineer, DevOps Engineer, and Infrastructure Developer.
Progress0 / 4 steps
1
Create a virtual machine resource
Create a Terraform resource called aws_instance named web_server with the ami set to "ami-12345678" and instance_type set to "t2.micro".
Terraform
Hint
Use the resource block with type aws_instance and name web_server.
2
Add a variable for instance size
Create a Terraform variable called instance_size with default value "t2.micro". Then update the instance_type in aws_instance.web_server to use this variable.
Terraform
Hint
Define a variable block and use var.instance_size in the resource.
3
Add a provisioner to install a web server
Add a provisioner "remote-exec" block inside aws_instance.web_server that runs the command sudo yum install -y httpd.
Terraform
Hint
Use the provisioner "remote-exec" block with inline commands.
4
Add a tag to identify the pattern
Add a tags block inside aws_instance.web_server with the key "Name" and value "web-server-pattern".
Terraform
Hint
Add a tags map with the Name key inside the resource.
Practice
(1/5)
1. Why do Terraform patterns help when building cloud infrastructure?
easy
A. They automatically fix errors in the code.
B. They make the cloud infrastructure run faster.
C. They save time and reduce mistakes by reusing code.
D. They replace the need for any manual setup.
Solution
Step 1: Understand what patterns do
Patterns are reusable ways to solve common problems, so they save time and reduce errors.
Step 2: Compare options
Only They save time and reduce mistakes by reusing code. correctly states that patterns save time and reduce mistakes by reusing code.
Final Answer:
They save time and reduce mistakes by reusing code. -> Option C
Quick Check:
Patterns save time and reduce mistakes = A [OK]
Hint: Patterns reuse code to save time and avoid errors [OK]
Common Mistakes:
Thinking patterns make infrastructure faster
Believing patterns fix code automatically
Assuming patterns remove all manual work
2. Which of the following is the correct way to use a module pattern in Terraform?
easy
A. module "example" { source = "./module_path" }
B. module example { source = "./module_path" }
C. module "example" (source = "./module_path")
D. module example: source = "./module_path"
Solution
Step 1: Recall Terraform module syntax
Terraform modules require the keyword module, a quoted name, and a block with source inside curly braces.
Step 2: Check each option
Only module "example" { source = "./module_path" } uses correct syntax with quotes and braces.
Final Answer:
module "example" { source = "./module_path" } -> Option A
Quick Check:
Correct module syntax uses quotes and braces = D [OK]
Hint: Modules need quotes around name and braces for block [OK]
Common Mistakes:
Omitting quotes around module name
Using parentheses instead of braces
Using colon instead of equals sign
3. Given this Terraform snippet using a module pattern: