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
Creating your first resource
📖 Scenario: You are starting to learn Terraform to manage cloud resources. Terraform uses configuration files to define resources like virtual machines or storage buckets. In this project, you will create your very first resource using Terraform.
🎯 Goal: Build a Terraform configuration that creates a single AWS S3 bucket named exactly my-first-terraform-bucket. This will help you understand how to define resources in Terraform.
📋 What You'll Learn
Create a Terraform configuration file named main.tf.
Define a resource block for an AWS S3 bucket.
Set the bucket name to my-first-terraform-bucket exactly.
Use the AWS provider with region us-east-1.
💡 Why This Matters
🌍 Real World
Terraform is widely used to automate cloud infrastructure setup, making it easy to create and manage resources like storage buckets consistently.
💼 Career
Knowing how to write Terraform configurations is a key skill for cloud engineers and DevOps professionals to manage infrastructure as code.
Progress0 / 4 steps
1
Set up the AWS provider
Write a Terraform configuration that sets the AWS provider with the region set to us-east-1. Use the provider block with provider "aws" and set region = "us-east-1" inside it.
Terraform
Hint
The provider block tells Terraform which cloud and region to use. Use provider "aws" and set region = "us-east-1".
2
Define the S3 bucket resource
Add a resource block to create an AWS S3 bucket named my-first-terraform-bucket. Use resource "aws_s3_bucket" "my_bucket" and set the bucket attribute to "my-first-terraform-bucket".
Terraform
Hint
The resource block defines what you want to create. Use resource "aws_s3_bucket" "my_bucket" and inside set bucket = "my-first-terraform-bucket".
3
Add a tag to the bucket
Inside the aws_s3_bucket resource block, add a tags block with a tag named Environment set to Development. Use the syntax tags = { Environment = "Development" }.
Terraform
Hint
Tags help organize resources. Add a tags block inside the resource with Environment = "Development".
4
Add versioning to the bucket
Enable versioning on the S3 bucket by adding a versioning block inside the aws_s3_bucket resource. Set enabled = true inside the versioning block.
Terraform
Hint
Versioning keeps multiple versions of objects. Add a versioning block with enabled = true inside the resource.
Practice
(1/5)
1. What is the main purpose of a resource block in Terraform?
easy
A. To write a script to run on a server
B. To define a cloud component to create and manage
C. To store variables for reuse
D. To output values after deployment
Solution
Step 1: Understand Terraform resource blocks
A resource block tells Terraform what cloud component to create, like a server or database.
Step 2: Differentiate resource from other blocks
Variables store data, outputs show results, scripts run commands. Only resource creates infrastructure.
Final Answer:
To define a cloud component to create and manage -> Option B
Quick Check:
Resource block = cloud component definition [OK]
Hint: Resource blocks create cloud parts, not scripts or variables [OK]
Common Mistakes:
Confusing resource with variable or output blocks
Thinking resource runs code on servers
Assuming resource stores data only
2. Which of the following is the correct syntax to create an AWS S3 bucket resource named my_bucket in Terraform?
easy
A. resource "my_bucket" "aws_s3_bucket" {}
B. resource aws_s3_bucket my_bucket {}
C. resource "aws_s3_bucket" {}
D. resource "aws_s3_bucket" "my_bucket" {}
Solution
Step 1: Recall Terraform resource syntax
The syntax is: resource "resource_type" "resource_name" { ... } with quotes around type and name.
Step 2: Match correct syntax
resource "aws_s3_bucket" "my_bucket" {} matches this exactly with resource type aws_s3_bucket and name my_bucket in quotes.
Final Answer:
resource "aws_s3_bucket" "my_bucket" {} -> Option D
Quick Check:
Correct resource syntax uses quotes for type and name [OK]
Hint: Resource type and name must be in quotes inside resource block [OK]