svg
Post Image
By Daniel Tanque17 de Novembro, 2023In Sem categoria

Terraform: HCL

Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp, designed to automate the provisioning and management of infrastructure across various cloud providers and on-premises environments. Terraform uses its own domain-specific language called HashiCorp Configuration Language (HCL) to define and describe infrastructure configurations.

In this article you will learn more about HCL, how to use inside Terraform and get examples on how to setup Terraform.

Structure

<blocks> <paramete> {
key1 = value1
key2 = value2
}

resource “local_file” “pet” {
filename = “/root/pets.txt”
content = “We love pets”
}

resource type: local_file
provider: local
resource: file

Examples:

resource “aws_instance” “web server” {
ami = “ami-dja09sdja0djd0a9sdj”
instance_type = “t2.micro”
}

resource “aws_s3_bucket” “data” {
bucket = ” … “
acl = “private”
}

Terraform workflow

  1. You have to write the configuration file
  2. Run terraform init to compile
  3. Run terraform plan to check what will be done or if there are errors
  4. Run terraform apply to execute the configuration file

To update you simply make the changes and run again terraform apply. That will destroy and recreate a new element.

To destroy you just need to run: “terraform destroy”.

Note: local_sensitive_file masks the contents of the file from the execution plan.

svgMicroservices
svg
svgTerraform Basics: Resources

Leave a reply