teluzia.Cloud Engineer · Day 86
CHAPTER 13 · TERRAFORM FUNDAMENTALS

HCL, providers and resources

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

HCL is the blueprint language, providers are specialist contractors, and resource blocks identify the things they manage. HCL uses blocks, arguments, and expressions. Block labels distinguish object type and name, while expressions reference values. Formatting improves readability but does not establish correctness. Learn braces, quoted strings, and references before combining complex collections or dynamic blocks. A provider implements resource behavior. required_providers identifies source and version constraints; provider configuration supplies settings such as region. The dependency lock file records selected provider versions and checksums, supporting reproducible installation across collaborators and automated runs.

Think of it this way

HCL is the blueprint language, providers are specialist contractors, and resource blocks identify the things they manage.

TOPIC 01 / 03Step by step

HCL blocks and expressions

HCL uses blocks, arguments, and expressions. Block labels distinguish object type and name, while expressions reference values. Formatting improves readability but does not establish correctness. Learn braces, quoted strings, and references before combining complex collections or dynamic blocks. For example, resource "terraform_data" "demo" { input = "hello" } has type terraform_data and local name demo.

WORKED EXAMPLE
resource "terraform_data" "demo" { input = "hello" } has type terraform_data and local name demo.

Read a resource block from outside inward. The type tells Terraform which provider behavior manages the object. The local name distinguishes this instance within the module. Arguments configure it, and expressions can refer to other values. A string containing an ID is different from a reference that obtains an ID from another resource.

A block groups related configuration. An argument assigns a value. An expression computes or retrieves that value. Formatting makes braces and nested structures easier to inspect but cannot prove the referenced object exists or the value is appropriate. Files within a module collectively form configuration; their alphabetical names are not an execution order. Start with one small object and inspect its address, then add a reference. Excessive abstraction early in learning can make ordinary type, spelling, or scope mistakes difficult to locate. Use descriptive names and understand the resulting plan before adding dynamic configuration.

Why this matters

resource "terraform_data" "demo" { input = "hello" } has type terraform_data and local name demo.

A common trap

Do not overlook this operational distinction: Learn braces, quoted strings, and references before combining complex collections or dynamic blocks.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

HCL blocks and expressions

HCL uses blocks, arguments, and expressions. Block labels distinguish object type and name, while expressions reference values. Formatting improves readability but does not establish correctness. Learn braces, quoted strings, and references before combining complex collections or dynamic blocks. For example, resource "terraform_data" "demo" { input = "hello" } has type terraform_data and local name demo.

WORKED EXAMPLE
resource "terraform_data" "demo" { input = "hello" } has type terraform_data and local name demo.

Read a resource block from outside inward. The type tells Terraform which provider behavior manages the object. The local name distinguishes this instance within the module. Arguments configure it, and expressions can refer to other values. A string containing an ID is different from a reference that obtains an ID from another resource.

A block groups related configuration. An argument assigns a value. An expression computes or retrieves that value. Formatting makes braces and nested structures easier to inspect but cannot prove the referenced object exists or the value is appropriate. Files within a module collectively form configuration; their alphabetical names are not an execution order. Start with one small object and inspect its address, then add a reference. Excessive abstraction early in learning can make ordinary type, spelling, or scope mistakes difficult to locate. Use descriptive names and understand the resulting plan before adding dynamic configuration.

Why this matters

resource "terraform_data" "demo" { input = "hello" } has type terraform_data and local name demo.

A common trap

Do not overlook this operational distinction: Learn braces, quoted strings, and references before combining complex collections or dynamic blocks.

Provider requirements and lock file

A provider implements resource behavior. required_providers identifies source and version constraints; provider configuration supplies settings such as region. The dependency lock file records selected provider versions and checksums, supporting reproducible installation across collaborators and automated runs. For example, pin a suitable AWS provider constraint and commit .terraform.lock.hcl; never commit downloaded provider binaries.

WORKED EXAMPLE
Pin a suitable AWS provider constraint and commit .terraform.lock.hcl; never commit downloaded provider binaries.

A fresh checkout declares an AWS provider source and acceptable version range. Initialization selects an available compatible version, downloads it, and records selected version and checksums in the dependency lock file. A coworker then initializes the same checkout with that lock file, making provider selection more reproducible rather than silently taking a newer implementation.

A provider requirement identifies source and compatibility constraints. Provider configuration supplies runtime settings such as region. The lock file records selected provider packages; it is not a resource-state backup or a module-version lock. Upgrades should be deliberate because changed defaults or behavior can alter plans. Commit the provider lock file while excluding downloaded binaries and state. Pinning improves control but does not remove patch-management responsibility. Verify provider support for your Terraform version and platform, then inspect a fresh plan after upgrades rather than treat a successful package download as sufficient validation.

Why this matters

Pin a suitable AWS provider constraint and commit .terraform.lock.hcl; never commit downloaded provider binaries.

A common trap

Do not overlook this operational distinction: The dependency lock file records selected provider versions and checksums, supporting reproducible installation across collaborators and automated runs.

Resource addressing and dependencies

Terraform addresses include resource type and local name. References establish dependency relationships so Terraform can order relevant operations. The local name is not automatically the remote object’s name, and renaming it without a move declaration may change Terraform’s mapping expectations. For example, aws_subnet.app references aws_vpc.main.id, making the subnet depend on the VPC.

WORKED EXAMPLE
aws_subnet.app references aws_vpc.main.id, making the subnet depend on the VPC.

Create a VPC resource, then set a subnet's vpc_id to that resource's id. Terraform recognizes the reference as a dependency, so the subnet cannot be created before the needed VPC ID is available. An output referencing the subnet obtains another dependency relationship. Putting the subnet in a file named 00-subnet.tf does not make it execute first.

A resource address names a configuration object. A reference consumes a value and often establishes a dependency. The dependency graph organizes relevant operation order, while unrelated actions may run concurrently. Use explicit depends_on only when a real dependency is not expressed through ordinary values, and understand that it can make planning more conservative. The local block name is not automatically the object's cloud name. Renaming it can affect state mapping, so use supported moved declarations when refactoring owned objects instead of unintentionally planning their replacement.

Why this matters

aws_subnet.app references aws_vpc.main.id, making the subnet depend on the VPC.

A common trap

Do not overlook this operational distinction: The local name is not automatically the remote object’s name, and renaming it without a move declaration may change Terraform’s mapping expectations.

KEEP THESE WITH YOU

Today’s takeaways

HCL blocks and expressions: HCL uses blocks, arguments, and expressions. Block labels distinguish object type and name, while expressions reference values. Formatting improves readability but does not establish correctness. Learn braces, quoted strings, and references before combining complex collections or dynamic blocks.

Provider requirements and lock file: A provider implements resource behavior. required_providers identifies source and version constraints; provider configuration supplies settings such as region. The dependency lock file records selected provider versions and checksums, supporting reproducible installation across collaborators and automated runs.

Resource addressing and dependencies: Terraform addresses include resource type and local name. References establish dependency relationships so Terraform can order relevant operations. The local name is not automatically the remote object’s name, and renaming it without a move declaration may change Terraform’s mapping expectations.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed