TF Series: Providers & Modules

This blog is the sub-part of "Terraform Associate 003 Series". To navigate back to the main Blog Page and know other topics in this series, click here. Here, we will be covering the concepts of Providers & Modules in Terraform Registry.

Providers

Providers are the terraform Plugins that allow you to interact with:
- CSPs: AWS, GCP, Azure, etc.
- SaaS Providers: GitHub, Angolia, Stripe.
- Other APIs: K8s, Postgress.

Provider comes in 3 types

  • Official - Published by the company that owns the provider technology or service.

  • Verified - Actively maintained, up-to-date and compatible with both TF & Provider.

  • Community - Published by a community member but no guarantee of maintenance, up-to-date or compatibility.

Note: Providers are distributed separately from TF & the plugins must be downloaded before use.

Provider Commands

  • `terraform init` will download the necessary provider plugins listed in a TF file.

  • `terraform providers` will display full list, this is used when we have lots of files & modules.

Terraform Provider Config

Setting of an alias:

provider "aws"{
    alias - "west"
    region = "us-east-2"
}

referencing an alias provider:

resource "aws_instance" "foo" {
    provider = aws.west
    # ...
}

Modules

Modules in Terraform help us in segregating the code in different files. For example: we can have multiple files like - variables.tf; outputs.tf; providers.tf and so on.. for different code blocks. Ref

Provider Vs Module

Provider

  • A provider is a plugin that is a mapping toa CSPs API.

  • Individual API action is called.

Module

  • A module is a group of configuration files that provide common config functionality.

  • Enforce best practices.

  • Reduces amount of code.

  • Reduce time to develop scripts.

Terraform Registry (Public)

Terraform Registry is a website portal to available Providers or Modules (plugins). You can find it at `registry.terraform.io`

Private Registry

Allows you to publish private modules for your Organization within the Terraform Cloud Private Registry.

When creating a module, need to connect to a VCS (GitHub) & choose a repository.