A label names a Terraform block or specifies its subtype. It appears after the block type and helps Terraform interpret, identify, and reference the block. section 2.2 section 2.2.2
Terraform block types use labels in several ways:
- No labels: terraform and locals blocks do not need labels because each module has only one of each. section 2.2.2
- One label: variable, provider, output, and module blocks use a single label; provider labels map to required providers. section 2.2.2
- Two labels: data and resource blocks use a subtype followed by a unique identifier. section 2.2.2
Referencing a labeled resource
In `resource "aws_instance" "hello_world"`, `aws_instance` is the resource subtype and `hello_world` is its identifier. The resulting reference, `resource.aws_instance.hello_world`, lets other blocks use its attributes. Likewise, `data "aws_vpc" "default"` becomes `data.aws_vpc.default`. section 2.2.2 section 2.2
Listing 2.7 HCL block components
type "label" { #1
parameter1 = "value" #2
parameter2 = "value" #3
parameter3 = true #4
parameter4 = 12 #5
parameter5 = { #6
key = "value"
}
parameter6 = null #7
subblock { #8
sub_parameter1 = "value"
sub_parameter2 = "value"
sub_parameter3 = "value"
}
subblock { #9
sub_parameter1 = "value"
sub_parameter2 = "value"
sub_parameter3 = "value"
}
}
Use the annotated HCL listing to locate the block type, label, arguments, and subblocks in a complete block structure. section 2.2
