liveBook · Manning

Resource type

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

A Terraform resource type identifies the kind of infrastructure object represented by a resource and determines its supported arguments.

When defining infrastructure, a resource type identifies what Terraform should create or manage. It maps through a provider to a specific infrastructure object, such as an AWS instance, DNS record, repository, or pull request. section 2.5

In a resource block, the first label is the resource type and the second is the resource identifier. The type determines the resource’s meaning and its available arguments; together, type and identifier form a unique reference within a module or workspace. section 2.2.2 section 2.5.1

An AWS instance resource type

The type aws_instance selects the provider’s AWS instance resource. The identifier hello_world makes the block addressable as resource.aws_instance.hello_world, while ami, subnet_id, and instance_type provide arguments for that type. section 2.5.1

Listing 2.23 resource block structure
resource "resource_type" "unique_resource_name" {
  string_argument  = "value"                      #1
  integer_argument = 134
  boolean_argument = true
  object_argument = {                             #2
    "key" = "value"
  }
  
  lifecyle {                                      #3
    create_before_destroy = true                  #4
  }
}

Use the resource block structure to see where the resource type appears and how type-specific arguments and lifecycle settings are arranged. section 2.5.1

Use resource types to:

  • Choose an infrastructure object exposed by a configured provider. section 2.5
  • Select arguments appropriate to that object rather than treating all resources alike. section 2.5.1
  • Construct references that other blocks can use to share resource attributes. section 2.2.2
  • Narrow the available resource catalog by first identifying the vendors and systems the architecture requires. section 2.5

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

How deep it goes
Defines subtype, provider mapping, arguments, and references, then demonstrates an AWS instance without covering provider implementation internals.
Examples
Uses aws_instance with ami, subnet_id, and instance_type arguments, referenced as resource.aws_instance.hello_world.
What you can do after
Build it from scratch by selecting a provider resource type, assigning a unique name, and supplying its type-specific arguments.
How it connects
Connects resource types with providers, resource blocks, data sources, arguments, identifiers, and Terraform references.

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.