#HCL

4 posts

Terraform Basics #6 Dependencies and Repetition: depends_on, count vs for_each, and dynamic Blocks
5 min read

Terraform Basics #6 Dependencies and Repetition: depends_on, count vs for_each, and dynamic Blocks

How references double as dependencies that decide creation order, and the exceptional cases where depends_on is needed. We cover the notorious recreation trap that removing an item from the middle of a list triggers with count, the key-based safety of for_each and how to choose between the two, and dynamic blocks for repeating nested blocks.

Terraform Basics #4 Data Sources and Expressions: Reading Instead of Creating, Conditionals, and for
5 min read

Terraform Basics #4 Data Sources and Expressions: Reading Instead of Creating, Conditionals, and for

Covering the data block that reads information from existing resources Terraform did not create, using a latest-AMI lookup as the example, then building per-environment branches with conditionals and transforming lists and maps with for expressions and splat syntax. We also go through the built-in functions you will use most and terraform console, the playground for trying expressions.

Terraform Basics #3 Variables, Outputs, and Locals: Three Tools for Removing Hardcoded Values
5 min read

Terraform Basics #3 Variables, Outputs, and Locals: Three Tools for Removing Hardcoded Values

How to pull values out of your code with variable blocks, and the precedence among the four input paths — tfvars files, the -var-file and -var flags, and environment variables. We block bad values at the door with validation, expose results with output, and name internal computations with locals, laying the groundwork for building multiple environments from the same code.

Terraform Basics #2 HCL Core Syntax: Blocks, Arguments, Resource Addresses, and the Three Shapes of Change
5 min read

Terraform Basics #2 HCL Core Syntax: Blocks, Arguments, Resource Addresses, and the Three Shapes of Change

A look at the skeleton of HCL — blocks and arguments — what a resource address like aws_s3_bucket.hello actually means, and the syntax for referencing one resource from another. We read the symbols in plan output to tell apart the three shapes of change — create, update, replace — and build the habit of running fmt and validate before every commit.