Thursday, 5 May 2022

Terraform Providers


Terraform supports hundreds of providers via their plugins (terms plugins and providers are often used interchangeably). They are distributed by Hashicorp's Terraform registry. There are 3 tiers of providers:
  • official: owned and maintained by Hashicorp. 
    • aws
    • gcp
    • azure
    • local
  • verified: owned and maintained by 3rd party company that is Hashicorp's partner
    • bigip by F5Networks
    • heroku by Heroku
    • digitalocean by DigitalOcean
    • linode by Linode
  • community: published and maintained by individual contributors
linode provider is maintained by Linode and is thus a verified provider

Here are some useful commands related to providers:

terraform providers - prints all providers used in the configuration directory


$ terraform providers

Providers required by configuration:
├── provider[]
└── provider[]

terraform providers mirror /path/to/destination/dir - to copy provider plugins needed for the current configuration directory to another directory

Version Constraints

By default TF will download the latest version of plugins required by resources specified in the configuration file (.tf file). To use some particular version of the plugin, we need to use a terraform block which is used to configure settings related to Terraform itself. Inside it, we need to use another block, called terraform_providers inside which we can list all providers and their settings:

terraform {
  required_providers {
    local = {
      source = "hashicorp/local"
      version = "2.2.2"

We can get this snippet for a given provider if we go to, select desired provider and click on USE PROVIDER button in the upper right corner:


Version constraint can be specified in multiple ways:
version = "!= 2.0.0" - get the available version before 2.0.0 but not 2.0.0
version = "< 2.0.0"
version = "> 2.0.0"
version = "> 1.5.0, < 2.0.0, != 1.7.0" 
Pessimistic constraint operator:
version = "~> 1.5" - get the version 1.5, 1.6 ...up to 1.9
version = "~> 1.5.0" - get the version 1.5.0, 1.5.1...up to 1.5.9


No comments: