Terraform Providers and Resources

Summary: in this tutorial, you will learn learn how providers and resources work in terraform and how to model cloud infrastructure using declarative configuration.

Terraform Providers and Resources

Terraform uses providers to interact with APIs and resources to model infrastructure objects.

Providers

A provider is a plugin that manages resources for a specific platform, such as AWS, Azure, or local files.

Example provider block:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}
 
provider "aws" {
  region = "us-east-1"
}

Resources

Resources declare the infrastructure objects you want to create.

Example S3 bucket resource:

resource "aws_s3_bucket" "website" {
  bucket = "shellrag-terraform-demo"
  acl    = "private"
}

Terraform computes dependencies automatically. If a resource references another resource, Terraform builds them in the right order.

Variables and outputs

Use variables to parameterize your configuration:

variable "region" {
  type    = string
  default = "us-east-1"
}
 
provider "aws" {
  region = var.region
}

Create outputs to share values after apply:

output "bucket_name" {
  value = aws_s3_bucket.website.id
}

Plan before you apply

Run terraform plan to inspect changes before applying them:

terraform plan

This helps prevent accidental resource changes and keeps infrastructure updates safe.

Was this page helpful?
SR

Written by the ShellRAG Team

The ShellRAG editorial team writes practical, beginner-friendly Terraform tutorials with tested code examples and real-world use cases. Every article is technically reviewed for accuracy and updated regularly.

Learn more about us →