Terraform · Infrastructure as code

What is a Terraform resource?

Easyresourcesdependency graphhclUpdated Oct 2026
Quiz this track

Short answer

A resource block declares one infrastructure object, such as a bucket or subnet. Terraform creates, updates or deletes it to match configuration and infers dependencies from references between resources.

A resource has a type and a local name. The type is defined by the provider, and the local name is how other expressions refer to it. Arguments describe the desired object; attributes expose values after creation, such as an ARN or ID.

hcl
resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_subnet" "public" {
  vpc_id     = aws_vpc.main.id
  cidr_block = "10.0.1.0/24"
}
The subnet references the VPC id, so Terraform creates the VPC first.

What a resource block contains

  • Provider-specific arguments such as size, CIDR or image
  • Meta-arguments such as count, for_each, depends_on and lifecycle
  • References that create implicit dependency edges
  • Computed attributes that become available after apply

The address aws_subnet.public is the identity Terraform uses in state and in plans. If you rename the block without a moved block, Terraform sees a destroy and a create rather than a rename.

Prefer implicit references over depends_on. A real value reference documents the dependency and cannot drift out of date as easily.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1How does Terraform know to create the VPC before the subnet?
  2. 2What is the difference between an argument and an attribute?
  3. 3What happens if you rename a resource block?
  4. 4When would you use depends_on instead of a reference?

Say it in the interview

A resource block declares one object that Terraform should manage, with a provider type and a local name. Arguments describe the desired state, and references to other resources create dependency edges automatically. That is why a subnet referencing a VPC id is created after the VPC. The address is also what state tracks, so renaming it needs a moved block to avoid a replacement.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Terraform mock interview and get scored feedback on depth, clarity and confidence.