Providers are the plugins that connect Terraform to external services, talking to APIs throughout the plan and apply stages. For the Associate exam, it's essential to nail down the basics of declaration, installation, version management, aliases, and authentication.
This article walks through the design behind the Terraform Core / Provider split, then distills the configuration patterns you'll rely on in practice and the points the exam likes to test.
A provider is a plugin separate from Terraform Core that connects to a cloud or SaaS API and implements resource and data source types. Providers handle resource create/update/delete operations and read-only data lookups, while Terraform Core focuses on plan generation and state management.
Each provider is uniquely identified by a source address (for example, registry.terraform.io/hashicorp/aws). You declare the source and version constraints in required_providers, and terraform init resolves and downloads them.
At runtime, Terraform Core launches provider plugins as separate processes and communicates with them over a stable plugin protocol. Core computes plan diffs against state, while the provider executes individual resource operations against the API.
This separation lets each provider be developed, distributed, and upgraded independently, contains failures, and makes it easy to roll out new features. Because network access is handled by the provider, Core never has to hold external API credentials directly.
The relationship between Terraform Core and provider plugins
Declare required_providers inside the terraform block of your project, specifying source and version constraints. terraform init resolves providers from the registry, verifies signatures and checksums, then installs them locally. The .terraform.lock.hcl file pins the resolved versions and checksums, ensuring reproducibility across the team.
To upgrade, revise the version constraints and run terraform init -upgrade. Offline use and mirror configuration are controlled through provider_installation in the CLI configuration file. The exam frequently tests the basic rule that the .terraform directory should not be committed, but .terraform.lock.hcl should be.
A typical required_providers block and provider configuration
terraform {
required_version = ">= 1.5.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.0, < 4.0"
}
}
}
provider "aws" {
region = var.aws_region
}
provider "azurerm" {
features {}
}
variable "aws_region" {
type = string
default = "us-east-1"
description = "AWS region"
}Credentials for a provider are typically resolved through a mix of explicit arguments in the provider block, environment variables, shared credential files, and the SDK's default discovery chain. Precedence depends on the provider implementation, but the general pattern is: values explicitly set in the provider block take top priority, and environment variables or shared files are consulted when those values are absent.
The cardinal rule is to keep secrets out of version control. Use the sensitive flag on variables, environment variables, or the variable store in Terraform Cloud/Enterprise, and never embed credentials in plain text.
Example: keeping credentials out of code using variables (AWS)
variable "aws_profile" {
type = string
default = null
description = "AWS named profile (optional)"
}
provider "aws" {
region = var.aws_region
profile = var.aws_profile # If unset, defer to the SDK's default discovery chain
}
# Either set AWS_PROFILE at runtime, or pass a value to var.aws_profile
# Example: AWS_PROFILE=dev terraform applyWhen you need multiple configurations of the same provider, use alias. Specify provider = aws.east on the resource and it will be created with that configuration. If you don't specify, the default configuration for that provider type is used.
Modules do not carry their own provider configurations. The caller assigns concrete configurations to the module's provider references through the providers map. This is how you safely deploy the same module across different accounts or regions.
Aliases and passing providers into a module
provider "aws" {
region = "us-west-2"
}
provider "aws" {
alias = "east"
region = "us-east-1"
}
resource "aws_s3_bucket" "west" {
bucket = "nlab-west-bucket"
provider = aws
}
resource "aws_s3_bucket" "east" {
bucket = "nlab-east-bucket"
provider = aws.east
}
module "network" {
source = "./modules/vpc"
# Assumes the module references the aws provider internally
providers = {
aws = aws.east
}
}
# Example declaration inside modules/vpc (excerpt)
# terraform {
# required_providers {
# aws = {
# source = "hashicorp/aws"
# }
# }
# }
# resource "aws_vpc" "this" { ... }Update versions by revising your version constraints, running terraform init -upgrade, and reviewing the diff on .terraform.lock.hcl. The terraform providers command visualizes your current dependencies. Signature and checksum verification happen automatically during init.
When mismatches or apply failures occur, use the plan output to identify which provider or resource is failing, and check for missing environment variables or authentication settings. Turn on TF_LOG when you need deeper visibility, and consult the provider's documentation for its authentication chain. Switching the provider for an existing resource usually requires recreation or import — a plain provider swap won't work.
| Aspect | Provider | Provisioner | Module |
|---|---|---|---|
| Primary role | Talks to external APIs and implements resources | Runs auxiliary scripts after creation | Reuses and encapsulates configuration |
| Lifecycle | Central to every plan and apply | Transient; recommended to minimize future use | Expanded when referenced and interpreted by Core |
| Unit of reuse | Per plugin; affects every workspace | Per resource, individually | Flexible per-caller configuration |
| Upgrade procedure | Adjust version constraints, run init -upgrade, update the lock file | Code changes only | Revise source/version and run init |
| Exam focus | Understanding required_providers and the lock file is essential | Avoid overuse; prefer external configuration management tools | Understand how to assign providers via the providers map |
Commands you'll use to inspect things
# Providers in use and their versions
terraform providers
# Upgrade providers
terraform init -upgrade
# Verbose logging (temporary)
TF_LOG=TRACE terraform plan
Associate
問題 1
You want to use the same provider type across multiple regions. Which is the most appropriate implementation?
正解: A
To use multiple instances of the same provider, declare an alias and explicitly select it via the provider meta-argument on the resource. Dynamic switching via count/for_each is not supported. Modules do not embed provider configurations — the caller must supply them through the providers map. Distributing the .terraform directory is not recommended.
Should I commit .terraform.lock.hcl?
Yes. The lock file pins resolved provider versions and checksums, guaranteeing reproducibility across environments. The .terraform directory itself should not be committed.
Can I switch an existing resource's provider to a different account or region?
In most cases a simple swap is not possible. You'll either need to recreate the resource under the new provider configuration, or import the existing instance and adjust addresses with state mv as needed. Always check the plan output to see whether replacement is required.
How do I fetch providers in an offline environment or from an internal mirror?
Use provider_installation in the CLI configuration file to specify a filesystem_mirror or network_mirror. Registry signature and checksum verification still apply, and terraform init will fetch providers from the mirror.
Practice with certification-focused question sets
無料で問題を解いてみるNicheeLab Editorial Team
NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.
HCL Syntax: Terraform's Configuration Language (2026)
HCL2 fundamentals for Terraform — blocks, attributes, expres...
Terraform Authoring & Operations Pro: Complete Guide (2026)
Tactics for the Terraform Pro exam — module authoring, works...
Terraform Providers: Plugin Management Fundamentals (2026)
Provider mechanics — required_providers, versions, mirrors, ...
Terraform Resource Blocks: Declarative Infra Units (2026)
Resource block fundamentals — addresses, references, common ...
Terraform Data Sources: Read-Only External Data (2026)
Data source basics — declaration, refresh behavior, dependen...