Terraform
required_providers block reference
Terraform relies on plugins called providers to interact with cloud providers, SaaS providers, and other APIs. Use the required_providers block in your component configuration to declare which providers your Stack requires.
If you are declaring a required_providers block in a traditional Terraform configuration file, ending in .tf, refer to the Terraform configuration terraform block reference instead.
Background
In component configurations, you must define the required_providers block at the top level of your tfcomponent.hcl file.
The required_providers block declares which providers your Stack requires, so Terraform can install and use them. Whenever you define a provider, you must also add that provider to required_providers to ensure the Terraform CLI knows where to source the provider and which version to download.
The Terraform CLI uses the required_providers block to download the listed providers and compute provider lock hashes. To learn more and view examples, refer to Declare providers.
Configuration model
The required_providers block supports the following arguments:
required_providersblock<PROVIDER_NAME>block
Complete configuration
All available arguments are defined in the following required_providers block:
required_providers {
<PROVIDER_NAME> = {
source = "<PROVIDER_SOURCE>"
version = "<VERSION_CONSTRAINT>"
}
}
Specification
A required_providers block supports the following configuration.
required_providers
The required_providers block contains one or more provider requirement declarations. Each declaration specifies a provider name and its requirements.
required_providers {
<PROVIDER_NAME> = {
source = "<PROVIDER_SOURCE>"
version = "<VERSION_CONSTRAINT>"
}
<PROVIDER_TWO_NAME> = {
source = "<PROVIDER_SOURCE>"
version = "<VERSION_CONSTRAINT>"
}
}
<PROVIDER_NAME>
Each provider declaration uses the provider name as a key that maps to a block with the provider's requirements. You can reference the same provider name in provider blocks to further configure that provider.
The following arguments are supported for each provider:
| Argument | Description | Type | Required? |
|---|---|---|---|
source | The global source address for the provider. | String | Required |
version | A version constraint specifying which versions of the provider are acceptable. | String | Required |
source
The source argument specifies the global source address for the provider, telling Terraform where to find the provider.
required_providers {
aws = {
source = "hashicorp/aws"
}
}
Refer to each Terraform provider’s documentation in the public Terraform registry, or your private HCP Terraform registry, for instructions on how to configure attributes in the required_providers block.
Summary
- Data type: String
- Default: None
- Required: Yes
version
The version argument specifies a version constraint that determines which versions of the provider are acceptable.
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.7.0"
}
}
Refer to Version constraints for details on how to specify version constraints.
Summary
- Data type: String
- Default: None
- Required: Yes
Examples
In the following example, the required_providers block declares the AWS and random providers with specific version constraints:
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.7.0"
}
random = {
source = "hashicorp/random"
version = "~> 3.5.1"
}
}
To learn more about using the provider block to further configure your Stack's providers, refer to Declare providers.