Terraform provides comments that are ignored during infrastructure deployment changes. It is useful for developers to understand the code better.

Single Line comments

Single-line comments always start with #, followed by comments.

Another way can be written using a double slash (//)

// aws instance details 
resources "aws_instance"{
  ami=local.ami # ami details
  type=local.type  # data type
}

Multi-line comments

Multi-line comments span in multiple lines enclosed in /** and */

These are also called block level comments

/** aws instance details
* main.tf
*/
resources "aws_instance"{
  ami=local.ami # ami details
  type=local.type  # data type
}

Terraform comments example

Let’s create variables and comment on some variables as given below

variable "access_key"{
    type = "string"
    description = "aws access_key"
}




variable "secret_key"{
    type = "string"
    description = "aws secret_key"
}


#variable "region"{
#    type = "string"
#    description = "aws region"
#}

The above code creates access_key and secret_key variable, region variable is ignored by commenting the code.