TechyPilots Info
TechyPilots.INFO
Home/Tutorials/Terraform/Providers and Resources
Terraform Fundamentals

Terraform Providers and Resources

Learn how Terraform providers connect to infrastructure platforms and how resources define the cloud and infrastructure components you want Terraform to manage.

Level: Beginner
Topic: Providers & Resources

Terraform Architecture

Provider → Resource → Infrastructure

Configure Provider

Define Resources

Reference Dependencies

Create Execution Plan

Apply Infrastructure Changes

Introduction

Understanding providers and resources

Providers and resources are two of the most important concepts in Terraform. Providers allow Terraform to communicate with external infrastructure platforms and services.

Resources describe the actual infrastructure objects that Terraform should create, update, or manage. These can include virtual machines, networks, storage, databases, identity resources, and many other supported services.

Together, providers and resources allow you to define infrastructure using configuration files and manage that infrastructure through Infrastructure as Code.

Core Concepts

The building blocks of Terraform infrastructure

Understanding these concepts will help you create Terraform configurations and manage relationships between infrastructure components.

01

Terraform Providers

Providers are plugins that allow Terraform to interact with cloud platforms, infrastructure services, SaaS platforms, and other APIs.

Key Topics

  • AWS
  • Microsoft Azure
  • Google Cloud
  • Kubernetes
02

Terraform Resources

Resources represent infrastructure objects that Terraform can create, update, and manage through a configured provider.

Key Topics

  • Virtual machines
  • Networks
  • Storage
  • Databases
03

Resource Arguments

Arguments define the configuration and properties of a resource, such as region, instance type, names, network settings, and tags.

Key Topics

  • Required arguments
  • Optional arguments
  • Resource configuration
  • Attributes
04

Resource Dependencies

Terraform automatically analyzes references between resources to determine the correct order for creating and updating infrastructure.

Key Topics

  • Implicit dependencies
  • Explicit dependencies
  • Resource references
  • Dependency graph

Terraform Providers

Connect Terraform to infrastructure platforms

Terraform uses providers to interact with APIs from cloud platforms, infrastructure services, container platforms, SaaS tools, and other supported technologies.

Before Terraform can manage a resource, the appropriate provider must be installed and configured for the infrastructure platform you want to use.

Provider Configuration Example

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
    }
  }
}

provider "aws" {
  region = "us-east-1"
}

Provider Types

Different ways Terraform connects to technology platforms

Cloud Providers

Cloud providers allow Terraform to manage infrastructure on cloud platforms such as AWS, Azure, and Google Cloud.

Infrastructure Providers

Infrastructure providers can manage systems, platforms, networking components, containers, and other infrastructure services.

SaaS Providers

Some providers allow Terraform to manage software services and configuration through supported APIs.

Community Providers

Terraform also supports providers developed by technology vendors and the wider Terraform community.

Resource Configuration Example

resource "aws_instance" "web_server" {
  ami           = "ami-example"
  instance_type = "t2.micro"

  tags = {
    Name = "web-server"
    Environment = "development"
  }
}

Terraform Resources

Define the infrastructure you want to manage

A resource block describes an infrastructure object managed by Terraform. Each resource belongs to a provider and has a resource type supported by that provider.

Resource configurations can include arguments that define the desired properties of the infrastructure object.

Resource Examples

Infrastructure you can manage with resources

The exact resources available depend on the provider you are using, but Terraform can manage many different types of infrastructure components.

Compute Resource

A resource can define a virtual machine or cloud compute instance with the required configuration.

Network Resource

Terraform resources can define virtual networks, subnets, routing components, firewalls, and other networking infrastructure.

Storage Resource

Resources can manage object storage, block storage, databases, backups, and other data services.

Kubernetes Resource

Terraform can also manage supported Kubernetes infrastructure and resources through appropriate providers.

Identity Resource

Infrastructure identity components such as users, roles, policies, and permissions can be managed through Terraform providers.

Application Resource

Providers can expose resources for managing supported application services and platform configurations.

Multiple Resources

Build complete infrastructure environments

Terraform configurations usually contain multiple resources that work together to create an infrastructure environment.

For example, a cloud application may require a virtual network, subnets, security rules, compute resources, storage, and other services.

Multiple Resource Example

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"
}

Resource Dependency Example

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"
}

resource "aws_instance" "web" {
  ami           = "ami-example"
  instance_type = "t2.micro"

  subnet_id = aws_subnet.public.id
}

Dependencies

Connect infrastructure resources together

Resources often depend on other resources. Terraform analyzes references between resources and uses those relationships to determine the correct order for infrastructure operations.

In the example, the subnet references the VPC ID, and the instance references the subnet. Terraform can use these relationships when building the execution plan.

Learning Roadmap

How to master providers and resources

Start by understanding how providers connect Terraform to external platforms, then practice defining resources and building relationships between infrastructure components.

Step 1

Understand Providers

Learn how providers connect Terraform to cloud platforms and infrastructure APIs.

Step 2

Configure a Provider

Define the provider requirements and configuration needed for your infrastructure environment.

Step 3

Create Resources

Write resource blocks that describe the infrastructure objects Terraform should manage.

Step 4

Use Resource References

Connect resources by referencing attributes from one resource inside another configuration.

Step 5

Review Dependencies

Understand how Terraform determines resource relationships and the order of infrastructure changes.

Step 6

Build Real Projects

Combine providers and multiple resources to build complete Infrastructure as Code projects.

Best Practices

Working with Terraform providers and resources

Pin Provider Versions

Use controlled provider version requirements to help maintain predictable Terraform environments.

Use Meaningful Names

Choose clear resource names that make your Terraform configuration easier to understand and maintain.

Organize Configuration

Separate infrastructure configuration logically as projects grow and become more complex.

Review Dependencies

Understand how resources reference each other and verify that infrastructure relationships are correctly defined.

Review Execution Plans

Always inspect the Terraform plan before applying infrastructure changes.

Build Reusable Modules

Convert repeated infrastructure patterns into reusable modules as your Terraform projects grow.

Next Step

Start building infrastructure with Terraform

Practice configuring providers, creating resources, connecting infrastructure components, and reviewing Terraform execution plans.