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.
Element | Description | Example |
---|---|---|
Block | A basic unit of configuration. Defines a resource or module. | resource "aws_instance" "example" { ... } |
Type | Specifies the type of the resource or configuration. | aws_instance , aws_s3_bucket |
Name | An identifier for the specific instance of the resource. | "example" in aws_instance "example" |
Arguments | Key-value pairs within a block that define properties of the resource. | ami = "ami-0c55b159cbfafe1f0" |
Attributes | Specific settings for the block. | instance_type = "t2.micro" |
Variables | Define input variables to make configurations dynamic. | variable "region" { default = "us-east-1" } |
Outputs | Define output values that are returned after applying the configuration. | output "instance_id" { value = aws_instance.example.id } |
Modules | Reusable configurations that can be shared across different setups. | module "network" { source = "./network" } |
Providers | Define providers (e.g., AWS, Azure) that allow interaction with specific services. | provider "aws" { region = "us-east-1" } |
Comments | Add comments to the configuration for better readability. | # This is a comment or /* This is a comment */ |