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
