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
