liveBook · Manning

Terraform provider

As explained in Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

A provider server is the running implementation of a Terraform provider that serves provider operations to Terraform.

To manage an AWS instance or a DNS record, Terraform needs a provider for the relevant system. Terraform Core determines which operations to perform and in what order; the provider exposes the system’s resources, data sources, and functions and communicates with its API. The provider is a plugin, while a provider server is its running implementation that serves operations to Terraform. section 1.2 section 1.2.3 section 12.4.4

Choose providers by the systems you need to manage, then consult their registry documentation for available components and settings. Declare the provider source and configure its connection in the root module; a project can use several providers or multiple configurations of one provider. Run `terraform init` to install required plugins. Its lock file records the selected versions so future initialization can make the same selections by default. section 2.4 section 2.4.1 section 8.4 section 1.4.2

A provider for posts and account lookups

A configuration declares `terraformindepth/mastodon` in `required_providers`, sets `host` in `provider "mastodon"`, looks up an account with `data "mastodon_account"`, and creates a post with `resource "mastodon_post"`. The data source and resource are components supplied by that provider, not built-in Terraform resource types. section 12.1 section 2.5

Most users need not write a provider. If a platform lacks one, design its public resources, data sources, and functions before implementation: incompatible changes can affect many modules. Provider development uses Go and the Terraform Plugin Framework. Tests can create a provider server through a factory and check required credential environment variables before testing resources or data sources. For ordinary infrastructure tests, focus on your configuration’s logic rather than retesting a well-tested provider. section 12.1 section 12.9 section 12.4.4 section 9.1.1

How Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu covers it

How deep it goes
Explains installation and configuration, then develops provider interfaces and server testing without requiring users to learn gRPC.
Examples
Uses an AWS provider installation and a Mastodon configuration with an account lookup and post resource.
What it assumes
Assumes no gRPC knowledge for ordinary use but requires Go knowledge to maintain a custom provider.
What you can do after
Build it from scratch with Go and the Terraform Plugin Framework, or operate/configure an existing provider through its registry documentation.
How it connects
Links providers to Terraform Core, resource blocks, data sources, registry installation, root modules, and acceptance testing.

Also explained in

Compare how 4 books explain Terraform provider →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu. The section links point to the parts of the book it draws on.