Challenge - 5 Problems
HCL Comments Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:00remaining
Identify the valid single-line comment syntax in HCL
Which of the following lines is a valid single-line comment in HashiCorp Configuration Language (HCL)?
Attempts:
2 left
💡 Hint
HCL supports single-line comments starting with # or //, and multi-line comments with /* */.
✗ Incorrect
In HCL, comments can start with # or // for single-line comments, and /* */ for multi-line comments. The syntax <!-- --> is used in HTML, not HCL.
❓ Configuration
intermediate1:30remaining
Effect of comments on resource count
Given the following Terraform configuration snippet, how many resources will be created?
Terraform
resource "aws_instance" "example1" { ami = "ami-123456" instance_type = "t2.micro" } # resource "aws_instance" "example2" { # ami = "ami-654321" # instance_type = "t2.micro" # } // resource "aws_instance" "example3" { // ami = "ami-abcdef" // instance_type = "t2.micro" // }
Attempts:
2 left
💡 Hint
Lines starting with # or // are ignored by Terraform.
✗ Incorrect
Only the first resource block is active. The other two resource blocks are commented out and ignored, so only one resource will be created.
❓ service_behavior
advanced1:30remaining
Multi-line comment effect in HCL
What will happen if you use the following multi-line comment syntax in a Terraform configuration file?
Terraform
/* resource "aws_s3_bucket" "bucket" { bucket = "my-bucket" acl = "private" } */ resource "aws_s3_bucket" "bucket2" { bucket = "my-bucket-2" acl = "private" }
Attempts:
2 left
💡 Hint
Multi-line comments in HCL start with /* and end with */.
✗ Incorrect
The multi-line comment correctly comments out the first resource block, so only the second resource block is active and created.
❓ security
advanced1:30remaining
Security risk of commented sensitive data
Why is it a bad practice to leave sensitive information like passwords or API keys in commented lines in Terraform files?
Attempts:
2 left
💡 Hint
Think about where your code files are stored and who can see them.
✗ Incorrect
Comments remain in the source files and can be seen by anyone with access to the code repository or logs, risking exposure of sensitive data.
❓ Architecture
expert2:00remaining
Impact of comments on Terraform plan output
Consider a Terraform file where a resource block is commented out using single-line comments. What will be the impact on the output of the `terraform plan` command?
Terraform
resource "aws_security_group" "sg1" { name = "sg1" description = "Allow SSH" ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } } // resource "aws_security_group" "sg2" { // name = "sg2" // description = "Allow HTTP" // ingress { // from_port = 80 // to_port = 80 // protocol = "tcp" // cidr_blocks = ["0.0.0.0/0"] // } // }
Attempts:
2 left
💡 Hint
Comments disable code from being processed by Terraform.
✗ Incorrect
Commented resource blocks are ignored by Terraform, so only the active resource (sg1) will appear in the plan output.