terraform,

required_providers vs provider in Terraform

May 20, 2022 · 1 min read · Post a comment

Terraform providers are TF plugins that abstract external APIs, mostly cloud provider APIs. These providers enable the user to easily manage their cloud environments by exposing resources. Basically, they sit between the Terraform engine and the supported cloud platform. Now, supposedly you need to deploy a cloud resource, first and foremost you must install and configure a resource that’s defined by required_providers and provider blocks. There’s difference obviously between them thus I’ll try to explain it plainly.

Prerequisites

  • Terraform

required_providers

required_providers defines the list or providers necessary for deploying resources. This can be a single one, or multiple including aws, azurerm, google, kubernetes, alicloud and a dozen others. Example code block:

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "= 3.5.0"
    }

    random = {
      source  = "hashicorp/random"
      version = "3.1.3"
    }
  }
}

Generally, this block is saved under versions.tf file. Not going to go deep into it as the consisting elements – source and version are self-explanatory and there’s already a good official HashiCorp docs out there.

provider

The provider block relates to a provider’s configuration. For instance:

provider "azurerm" {
  features {}

  subscription_id = "<some_sub_id_>"
}

Overall, this block is saved under provider.tf file. Every provider has its own arguments and features.

Conclusion

If you have any questions, thoughts or opinions, feel free to leave a comment below. On a side note, follow our official channel on Telegram.