liveBook · Manning

Resource block

As explained in Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

A resource block is a Terraform configuration block that declares an infrastructure resource type, identifier, and arguments.

A resource block declares a real infrastructure component for Terraform to launch and manage. Its resource type maps through a provider to an infrastructure type, such as an AWS instance, DNS record, repository, or pull request. section 2.5 section 2.0

Resource blocks use two labels: a resource type and an identifier. Together with the block type, these labels form a unique reference such as resource.aws_instance.hello_world, which lets other blocks use its attributes as arguments. section 2.2.2

An AWS instance resource

resource "aws_instance" "hello_world" { ami = data.aws_ami.ubuntu.id subnet_id = data.aws_subnets.main.ids[0] instance_type = var.instance_type } The first label, aws_instance, identifies the provider-backed resource type. The second, hello_world, identifies this resource within the module. Its arguments consume values from data sources and a variable. section 2.2.2

Use resource blocks to:

  • Represent each infrastructure component Terraform should launch and manage. section 2.5
  • Choose a provider-specific type that matches the intended infrastructure. section 2.5
  • Give each resource a unique identifier so other blocks can reference it precisely. section 2.2.2

How Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu covers it

How deep it goes
Explains provider mapping, labels, references, and arguments, while deferring more advanced Terraform language features.
Examples
Uses an AWS instance with AMI, subnet, and instance-type arguments, alongside referenced AWS data sources.
What it assumes
Assumes an intended system architecture and vendor choice, while defining Terraform resource structure from basic concepts.
What you can do after
Build and manage provider-backed infrastructure by declaring resource types, identifiers, and arguments.
How it connects
Connects resource blocks to providers, data sources, variables, arguments, and modules.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu. The section links point to the parts of the book it draws on.