0
0
Terraformcloud~10 mins

Comments in HCL in Terraform - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a single-line comment in HCL.

Terraform
#[1] This is a comment
Drag options to blanks, or click blank then click option'
A This is a comment
Attempts:
3 left
💡 Hint
Common Mistakes
Using // instead of # for single-line comments
Not adding a space after the comment symbol
2fill in blank
medium

Complete the code to add a multi-line comment in HCL.

Terraform
/*[1]*/
Drag options to blanks, or click blank then click option'
A This is a multi-line comment spanning multiple lines
B This is a single-line comment
C This is not a comment
D This is a wrong comment style
Attempts:
3 left
💡 Hint
Common Mistakes
Using # for multi-line comments
Not closing the multi-line comment properly
3fill in blank
hard

Fix the error in the comment syntax below by completing the blank.

Terraform
resource "aws_instance" "example" { [1] This resource creates an EC2 instance
  ami           = "ami-123456"
  instance_type = "t2.micro"
}
Drag options to blanks, or click blank then click option'
A//
B--
C/*
D#
Attempts:
3 left
💡 Hint
Common Mistakes
Using // instead of # inside resource blocks
Using SQL style comments like --
4fill in blank
hard

Fill both blanks to correctly comment out the variable declaration in HCL.

Terraform
[1] variable "region" { 
  type    = string
  default = "us-west-2"
} [2]
Drag options to blanks, or click blank then click option'
A/*
B#
C*/
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using # at the end of the block
Using // instead of /* and */ for multi-line comments
5fill in blank
hard

Fill all three blanks to add a comment inside a resource block and a multi-line comment outside.

Terraform
/*[1]*/
resource "aws_s3_bucket" "bucket" {
  [2] Bucket for storing logs
  bucket = "my-log-bucket"
  acl    = "private"
}
[3]
Drag options to blanks, or click blank then click option'
A This is a multi-line comment spanning lines
B#
C/*
D*/
Attempts:
3 left
💡 Hint
Common Mistakes
Using # for multi-line comments outside resource blocks
Using /* inside resource blocks for single-line comments