0Pricing
DevOps Bootcamp · Lesson

Providers and Resources

Understand how Terraform interacts with various cloud and service providers, and how to define individual infrastructure components as resources.

Providers and Resources is a free DevOps Bootcamp lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Terraform's Core Building Blocks

Welcome! Terraform helps you manage your cloud infrastructure using code. But how does it actually talk to cloud providers and define what you want to build?

This lesson introduces two fundamental concepts: Providers and Resources. These are the basic building blocks of every Terraform configuration and crucial for understanding how IaC works.

What are Terraform Providers?

Think of a Provider as a plugin that allows Terraform to interact with an external service or API. This could be a cloud provider like AWS, Azure, or Google Cloud, or even services like GitHub, Kubernetes, or Datadog.

  • Each provider understands the specific API calls needed for its service.
  • It translates your desired infrastructure into actions the service can perform.
  • You configure providers to tell Terraform which service to use and how to authenticate.

Declaring a Provider Block

To use a provider, you declare it in your Terraform configuration files using a provider block. This block specifies the provider's name and any configuration settings it needs, such as the region for a cloud provider.

Here's a common example for the AWS provider:

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

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

Provider Source and Version

The terraform block's required_providers section is important. It tells Terraform where to find the provider (its source) and which version to use. This ensures consistency and prevents unexpected behavior.

  • Source: Specifies the registry path for the provider (e.g., hashicorp/aws).
  • Version: Locks the provider version, preventing breaking changes from new releases.
  • The provider "aws" block then configures specific settings, like the AWS region for all resources managed by this provider.

What are Terraform Resources?

A Resource is a block that describes a single component of your infrastructure. This could be a virtual machine (VM), a network, a database, a storage bucket, or even a user account.

  • Each resource type is managed by a specific provider (e.g., aws_s3_bucket is managed by the AWS provider).
  • You declare the desired state of your resource, and Terraform works to achieve that state.
  • Resources have arguments that define their properties (e.g., size, name, location).

Declaring a Resource Block

You define a resource using a resource block. This block requires two strings:

  • The resource type (e.g., aws_s3_bucket).
  • A local name (e.g., my_first_bucket) that is unique within your configuration.

The type tells Terraform what kind of infrastructure component it is, and the name gives it a unique identifier for Terraform to track.

resource "aws_s3_bucket" "my_first_bucket" { # Arguments go here to define its properties }
resource "aws_s3_bucket" "my_first_bucket" {
  # Arguments go here to define its properties
}

Resource Arguments and Properties

Inside a resource block, you specify arguments. These are key-value pairs that define the properties and configuration of the infrastructure component. The available arguments depend on the resource type and its managing provider.

  • For an AWS S3 bucket, arguments might include bucket (the unique name), acl (access control list), or tags for labeling.
  • Terraform uses these arguments to create or update the resource to match your desired state in the cloud.

Putting it Together: Provider & Resource

Here’s a simple, complete Terraform configuration. It declares the AWS provider and then uses it to create a basic S3 bucket. This single file is all you need to start defining infrastructure!

terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } } } provider "aws" { region = "us-east-1" } resource "aws_s3_bucket" "my_unique_bucket" { bucket = "my-coddykit-demo-bucket-12345" # Must be globally unique! acl = "private" tags = { Environment = "Development" Project = "CoddyKit" } }
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

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

resource "aws_s3_bucket" "my_unique_bucket" {
  bucket = "my-coddykit-demo-bucket-12345" # Must be globally unique!
  acl    = "private"

  tags = {
    Environment = "Development"
    Project     = "CoddyKit"
  }
}

The Terraform Workflow Connection

When you execute Terraform commands, providers and resources play key roles:

  • terraform init: Downloads the necessary provider plugins.
  • terraform plan: Uses the provider to communicate with the cloud API and determine what changes are needed to achieve the desired resource state.
  • terraform apply: Instructs the provider to make those changes to your actual cloud infrastructure.

They are the core interaction points for managing your infrastructure.

Quick Check: Provider Role

You've learned about Providers and Resources. Let's see if you can identify their roles correctly.

Recap: Providers & Resources

Great job! In this lesson, you gained a foundational understanding of the two most important concepts in Terraform:

  • Providers: These are the essential plugins that enable Terraform to interact with various cloud services and APIs. You configure them to specify which service to use and how to authenticate.
  • Resources: These are the individual infrastructure components you declare in your configuration. They have types and arguments to define their desired state.

These two elements work hand-in-hand to let you define and manage your infrastructure as code efficiently!

Frequently asked questions

Is the “Providers and Resources” lesson free?

Yes — the full text of “Providers and Resources” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “Providers and Resources”?

Understand how Terraform interacts with various cloud and service providers, and how to define individual infrastructure components as resources. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Providers and Resources” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Providers and Resources
  2. Variables and Outputs
  3. State Management Fundamentals
  4. Modules and Code Reuse
← Back to DevOps Bootcamp