Terraform as you all know by now is an automation tool developed by Hashicorp for creating infrastructure as code. Terraform comprises of various components out of which Terraform Provider is the most important one that we need to understand.
In this post we will understand more about Terraform providers, where can you get them from, and how you can use these providers in your Terraform scripts.
Terraform Providers are essentially plugins that Terraform installs to interact with the remote systems i.e. Azure/AWS/Google Cloud/ VMware and a lot of other vendors devices.
Each Terraform Provider that is used in your Terraform script will allow for the creation of certain set of resources. Once a provider has been defined in your code, terraform will automatically go to Terraform public registry and install the required provider during initialization. If you haven’t used any Terraform provider within your script you won’t be able to manage or create any infrastructure. You can define more than one provider in your Terraform code.
If you are working with Terraform modules, then you need to declare the Terraform providers in your root module while the child modules inherit the provider configuration from the root module.
Terraform providers follow their own release cadence and version number.
Terraform Providers: Registry
The complete Terraform Provider registry can be accessed at the following link
A terraform registry page would look like below:
On the top left-hand corner, you can see Tier selected is Official, Verified & Community.
- Official: These consists of the providers that are owned and maintained by Hashicorp itself. You can see them marked with yellow badge
- Verified: These consists of the providers that are owned and created by a third party technology partner i.e. Cisco, Juniper, Akamai and many more as nowadays most of the vendor companies have created their own providers that help them integrate their products with Terraform for automation.
- Community: These providers are created and maintained by individuals who are members of the Terraform community.
There are a lot of Terraform modules that have been created already and posted on the website for reference. You could simply copy the reference code make the required changes and use it then in your environments. You could also filter based on the provider as to where you are deploying your infrastructure. In example below we selected AWS and you can see below we got reference scripts to create VCP, Network Security Groups etc.
You can also access the provider documentation that could be of massive help while creating your Terraform scripts for IAC (Infrastructure as code).
Click on Provider (AWS Example) > Click on Documentation on Top Right (as Highlighted)
Starting from Terraform version 0.13 onwards we must define a resource_provider source block in our root module. If you want to get a resource_provider code block for the provider you are using simply select your provider on repository & click on use provider as highlighted > Copy the Provider Block > Paste it on Terraform configuration file in root module.
Terraform providers are plug-ins that are written in Go language. Anyone well versed with Go programming skills can write their own set of providers that they would like to use in their environment.
You can find a lot more information about the provider by clicking at the source-code link at the bottom of your selected provider definition and it will redirect you to the provider repository on GitHUB which contains myriads of information to help you create your Terraform scripts.
Terraform supports around 130 providers officially!