0
0
Terraformcloud~30 mins

Module structure and conventions in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Terraform Module Structure and Conventions
📖 Scenario: You are creating a reusable Terraform module to deploy a simple AWS S3 bucket. This module will be used by other teams to quickly create buckets with standard settings.
🎯 Goal: Build a Terraform module with proper structure and naming conventions that defines an AWS S3 bucket resource with input variables and outputs.
📋 What You'll Learn
Create a Terraform module folder structure with main.tf, variables.tf, and outputs.tf files
Define an AWS S3 bucket resource in main.tf
Add input variables for bucket name and versioning in variables.tf
Add an output for the bucket ARN in outputs.tf
💡 Why This Matters
🌍 Real World
Terraform modules help teams reuse infrastructure code safely and consistently across projects.
💼 Career
Knowing how to build and structure Terraform modules is essential for cloud engineers and DevOps professionals managing infrastructure as code.
Progress0 / 4 steps
1
Create the Terraform module main configuration
In the main.tf file, write the Terraform code to create an AWS S3 bucket resource named my_bucket using the variable bucket_name for the bucket's name.
Terraform
Need a hint?

Use resource "aws_s3_bucket" "my_bucket" {} and set bucket = var.bucket_name.

2
Add input variables for bucket name and versioning
In the variables.tf file, define two input variables: bucket_name of type string without a default, and enable_versioning of type bool with a default value of false.
Terraform
Need a hint?

Use variable "bucket_name" { type = string } and variable "enable_versioning" { type = bool default = false }.

3
Add versioning configuration to the S3 bucket
In the main.tf file, add a versioning block inside the aws_s3_bucket.my_bucket resource. Set enabled to the variable enable_versioning.
Terraform
Need a hint?

Add a versioning block with enabled = var.enable_versioning inside the bucket resource.

4
Add output for the bucket ARN
In the outputs.tf file, create an output named bucket_arn that returns the ARN of the aws_s3_bucket.my_bucket resource.
Terraform
Need a hint?

Use output "bucket_arn" { value = aws_s3_bucket.my_bucket.arn }.