In HCL, comments can start with # or // for single-line comments, and /* */ for multi-line comments. The syntax <!-- --> is used in HTML, not HCL.
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" // }
Only the first resource block is active. The other two resource blocks are commented out and ignored, so only one resource will be created.
/* resource "aws_s3_bucket" "bucket" { bucket = "my-bucket" acl = "private" } */ resource "aws_s3_bucket" "bucket2" { bucket = "my-bucket-2" acl = "private" }
The multi-line comment correctly comments out the first resource block, so only the second resource block is active and created.
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.
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"] // } // }
Commented resource blocks are ignored by Terraform, so only the active resource (sg1) will appear in the plan output.
