Basic Syntax

Contents

Roadmap info from [roadmap website](https://roadmap.sh/terraform/basic syntax@LaD0H7XhoEEaXbcwjxAbw)

The Basic Syntax of HashiCorp Configuration Language (HCL) includes defining blocks, attributes, and expressions. Blocks are fundamental units like resource, module, and provider, identified by keywords and enclosed in curly braces. Attributes are key-value pairs within blocks, where keys are strings and values can be strings, numbers, or other data types. Expressions allow embedding variables, functions, and references to other resources, enabling dynamic configurations.

ElementDescriptionExample
BlockA basic unit of configuration. Defines a resource or module.resource "aws_instance" "example" { ... }
TypeSpecifies the type of the resource or configuration.aws_instance, aws_s3_bucket
NameAn identifier for the specific instance of the resource."example" in aws_instance "example"
ArgumentsKey-value pairs within a block that define properties of the resource.ami = "ami-0c55b159cbfafe1f0"
AttributesSpecific settings for the block.instance_type = "t2.micro"
VariablesDefine input variables to make configurations dynamic.variable "region" { default = "us-east-1" }
OutputsDefine output values that are returned after applying the configuration.output "instance_id" { value = aws_instance.example.id }
ModulesReusable configurations that can be shared across different setups.module "network" { source = "./network" }
ProvidersDefine providers (e.g., AWS, Azure) that allow interaction with specific services.provider "aws" { region = "us-east-1" }
CommentsAdd comments to the configuration for better readability.# This is a comment or /* This is a comment */
#ready #online #terraform #IaC #infrastructure