HashiCorp Configuration language(HCL)
Aashish R.
????System Engineer at Tata Consultancy Services | DevOps | Terraform | Kubernetes | Ansible | Jenkins | CI/CD | ??AWS | Docker | Grafana | GitHub | Linux |
#TerraWeekChallenge DAY 2 Terraform Syntax , Block parameter and arguments ,variable , data types , expressions , .tf files , terraform configuration
HCL - HashiCorp Configuration language
What is HCL HashiCorp Configuration language?
Comments are available as single line or multi-line:
Single Line: # or //.
Multi-Line: /* */ (no nesting of block comments).
type "label_1" "label_2" {
argument_1 = value_1
argument_2 = value_2
}
Here we have block type of resource.
resource "aws_instance" "app_server" {
ami = "ami-830c94e3"
instance_type = "t2.micro"
tags = {
Name = "PathToTerraformCertInstance"
}
}
aws_instance is the first label that points to the type of AWS resource and app_server is the second label that represents the name of the resource.
AWS Provider documentation here.
Terraform blocks types here.
Here’s an example of a simple HCL block with parameters and arguments:
resource "aws_instance" "myec2" {
ami = " ami-04a0ae173da5807d3"
instance_type = "t2.micro"
tags = {
Name = "terraform-instance"
}
}
In the above example, we have a block of type aws_instance, representing an EC2 instance in Amazon Web Services (AWS).
Terraform Data Sources here.
create a variable.tf file and define a variable.
variable "filename" {
type = string
}
Here is an example of how to use the filename variable in a main.tf file:
领英推荐
resource "local_file" "example" {
filename = "${var.filename}"
content = "Hello, World!"
}
we are creating a local_file resource and using the filename variable as the name of the file.
sudo su
mkdir terraform
cd terraform/
main.tf file
terraform init
terraform validate
terraform plan
terraform apply
We learned HCL blocks, parameters, and arguments, which help structure our configurations. we also go through various resource types and data sources available in Terraform. we practiced writing Terraform configurations using HCL syntax and tested them with the Terraform.
Happy Learning!!