Typorithm · easy

Resource Block

terraform-resourceterraformresourcereferenceaddress
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Resource Block

0%

HCL Basics

A resource block has a type and a local name (its address); arguments configure it, and other blocks reference its attributes via type.name.attribute, like aws_s3_bucket.this.arn.

A resource block is the core building block of Terraform — it declares one piece of real infrastructure to create and manage.

Its two labels are the resource type (aws_s3_bucket) and a local name (this); combined they form the resource address aws_s3_bucket.this used everywhere else.

Other expressions reference a resource's exported attributes with type.name.attribute, e.g. aws_s3_bucket.this.arn, and Terraform infers the dependency order from those references.

01

resource "type" "name" sets the address.

02

Arguments inside the block configure it.

03

Reference attributes via type.name.attribute.

resource "aws_s3_bucket" "this" {
  bucket = "my-bucket"

  tags = {
    Env = "prod"
  }
}

output "bucket_arn" {
  value = aws_s3_bucket.this.arn
}

Read the implementation

Connect each part of the code to the concept before you type.

1. Resource address

A resource block names a type (aws_s3_bucket) and a local name (this); together they form its address aws_s3_bucket.this.

resource "aws_s3_bucket" "this" {

2. Required argument

Arguments inside the block configure the resource; bucket sets the S3 bucket's name.

bucket = "my-bucket"

3. Tag map

tags is a map of key/value labels applied to the bucket for cost and ownership tracking.

tags = {
    Env = "prod"
  }

4. Attribute reference

aws_s3_bucket.this.arn reads an exported attribute of the resource, creating an implicit dependency.

value = aws_s3_bucket.this.arn

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Resource Block: Lesson & Practice · Typorithm | ApplyDjinn