How to write HCL?

HCL (HashiCorp Configuration Language) is a configuration language used primarily for defining infrastructure as code with tools like Terraform. Here’s a basic example of how to write HCL:

provider "aws" {
  region = "us-west-2"
}

resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"

  tags = {
    Name = "ExampleInstance"
  }
}

Explanation:

  • provider: Specifies the cloud provider (in this case, AWS) and its configuration.
  • resource: Defines a resource to be created (an EC2 instance in this example).
  • tags: A map of key-value pairs to tag the resource.

You can save this code in a .tf file and use Terraform to apply the configuration.

0 Comments

no data
Be the first to share your comment!