Skip to main content

Terraform Resource

A Terraform resource is a configuration block that declares one infrastructure object, such as an EC2 instance, an S3 bucket, or a DNS record. Terraform creates, updates, and deletes the real object to match the declaration.

What Is a Resource?

A resource has a type, a local name, and arguments. Together the type and name form its address, such as aws_s3_bucket.order_images.

HCL
resource "aws_s3_bucket" "order_images" {
bucket = "zerodha-order-images-prod"
}
resource "aws_s3_bucket_versioning" "order_images" {
bucket = aws_s3_bucket.order_images.id # reference creates a dependency
versioning_configuration {
status = "Enabled"
}
}

Meta-arguments count, for_each, depends_on, provider, and lifecycle work on any resource. A data source (data block) only reads existing objects and never manages them.

Tip

Deleting a resource block and applying destroys the real object. terraform state rm only stops tracking it.

Frequently Asked Questions

Why did my change recreate a resource instead of updating it?

Some attributes force replacement because the provider cannot change them in place. The plan marks these with -/+ and names the attribute.

How do I stop managing a resource without deleting it?

Run terraform state rm on its address and remove the block from code. The real object keeps running.

Found a mistake, an outdated step or a broken link?