0
0
Terraformcloud~15 mins

Comments in HCL in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Comments in HCL
📖 Scenario: You are writing a Terraform configuration file to manage cloud infrastructure. To keep your code clear and easy to understand, you want to add comments explaining what each part does.
🎯 Goal: Learn how to add single-line and multi-line comments in a Terraform configuration file using HCL syntax.
📋 What You'll Learn
Create a Terraform variable block with a description comment
Add a single-line comment above a resource block
Use a multi-line comment inside the resource block
Add a trailing comment on a resource attribute
💡 Why This Matters
🌍 Real World
Comments in Terraform files help teams understand infrastructure code, making collaboration and maintenance easier.
💼 Career
Cloud engineers and DevOps professionals use comments to document infrastructure as code, improving clarity and reducing errors.
Progress0 / 4 steps
1
Create a variable block with a description comment
Create a Terraform variable block named region with type string and default value "us-west-1". Add a single-line comment above it that says # This variable sets the AWS region.
Terraform
Need a hint?

Use # for single-line comments in HCL.

2
Add a single-line comment above a resource block
Add a single-line comment # Create an AWS S3 bucket above a resource block named aws_s3_bucket with resource name my_bucket. The resource block should have an attribute bucket set to "my-terraform-bucket".
Terraform
Need a hint?

Use # for single-line comments above blocks.

3
Use a multi-line comment inside the resource block
Inside the aws_s3_bucket resource block, add a multi-line comment that says This bucket stores terraform state files. Use the /* ... */ syntax for the multi-line comment.
Terraform
Need a hint?

Use /* to start and */ to end multi-line comments.

4
Add a trailing comment on a resource attribute
Add a trailing comment # Bucket name on the same line as the bucket attribute inside the aws_s3_bucket resource block.
Terraform
Need a hint?

Trailing comments start with # after the code on the same line.