0
0
Terraformcloud~30 mins

Root module concept in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Terraform Root Module Setup
📖 Scenario: You are setting up a basic Terraform project to manage cloud infrastructure. The root module is the main folder where Terraform configuration files live. It defines resources and variables for your infrastructure.
🎯 Goal: Build a simple Terraform root module that defines a provider and a resource with variables.
📋 What You'll Learn
Create a Terraform configuration file named main.tf.
Define the aws provider with a region variable.
Create a resource of type aws_s3_bucket with a bucket name variable.
Use variables for region and bucket name with default values.
💡 Why This Matters
🌍 Real World
Terraform root modules are the starting point for managing cloud infrastructure as code. They organize resources and variables in one place.
💼 Career
Understanding root modules is essential for cloud engineers and DevOps professionals to build and maintain infrastructure reliably and repeatably.
Progress0 / 4 steps
1
Create the Terraform provider block
In the main.tf file, write a Terraform provider block for aws using the variable region for the region setting.
Terraform
Need a hint?

The provider block tells Terraform which cloud provider to use. Use var.region to get the region from a variable.

2
Add variables for region and bucket name
Below the provider block in main.tf, add two variable blocks named region and bucket_name. Set their default values to "us-east-1" and "my-terraform-bucket" respectively.
Terraform
Need a hint?

Variables let you customize your Terraform configuration. Use variable "name" { default = "value" } syntax.

3
Create an S3 bucket resource using the bucket_name variable
Add a resource block of type aws_s3_bucket named my_bucket in main.tf. Set the bucket attribute to use the variable bucket_name.
Terraform
Need a hint?

Resources define infrastructure components. Use resource "type" "name" { attribute = value } syntax.

4
Add output to show the bucket name
Add an output block named bucket_name_output in main.tf that outputs the value of the aws_s3_bucket.my_bucket.bucket attribute.
Terraform
Need a hint?

Outputs let you see important information after Terraform applies changes. Use output "name" { value = ... } syntax.