Skip to content

Add provider block reference rewrite #557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: docs/reference-rewrites-phrase-1
Choose a base branch
from

Conversation

rkoron007
Copy link
Contributor

@rkoron007 rkoron007 commented Jul 10, 2025

@rkoron007 rkoron007 self-assigned this Jul 10, 2025
@rkoron007 rkoron007 requested review from a team as code owners July 10, 2025 00:44
Copy link

github-actions bot commented Jul 10, 2025

Vercel Previews Deployed

Name Status Preview Updated (UTC)
Dev Portal ✅ Ready (Inspect) Visit Preview Thu Jul 10 23:08:23 UTC 2025
Unified Docs API ✅ Ready (Inspect) Visit Preview Thu Jul 10 23:03:16 UTC 2025

Copy link

github-actions bot commented Jul 10, 2025

Broken Link Checker

Summary

Status Count
🔍 Total 253
✅ Successful 236
⏳ Timeouts 1
🔀 Redirected 0
👻 Excluded 0
❓ Unknown 0
🚫 Errors 16

Errors per input

Errors in content/terraform/v1.12.x/docs/language/providers/requirements.mdx

Errors in content/terraform/v1.12.x/docs/language/block/data.mdx

Errors in content/terraform/v1.12.x/docs/language/v1-compatibility-promises.mdx

Errors in content/terraform/v1.12.x/docs/language/block/provider.mdx

Errors in content/terraform/v1.12.x/docs/language/block/resource.mdx

@rkoron007
Copy link
Contributor Author

I'm not going to fix the broken links yet, because they aren't related to the provider page I'm proposing here and these are all unrelated. So we'll fix these all later!

Copy link
Contributor

@robin-norwood robin-norwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more details, but looking great!

@@ -0,0 +1,419 @@
---
page_title: Provider block reference for the Terraform configuration language
description: Use the `provider` block to declare and configure Terraform plugins, called providers. Providers let Terraform manage real-world infrastructure with provider-defined resources and data sources.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debating adding "functions

Suggested change
description: Use the `provider` block to declare and configure Terraform plugins, called providers. Providers let Terraform manage real-world infrastructure with provider-defined resources and data sources.
description: Use the `provider` block to declare and configure Terraform plugins, called providers. Providers let Terraform manage real-world infrastructure with provider-defined resources, data sources, and functions.

Counterargument: We'd want to add , and actions when they're released.


Anyone can develop a Terraform provider and use it locally, or publish it to the Terraform public registry or HCP Terraform private registry. To learn more about authoring providers, refer to the [Plugin framework](/terraform/plugin/framework).

Each Terraform module must declare which providers it requires, so that Terraform can install and use them. To declare a provider in a module, perform the following three steps:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Each Terraform module must declare which providers it requires, so that Terraform can install and use them. To declare a provider in a module, perform the following three steps:
Each Terraform root module should declare which providers it requires, so that Terraform can install and use them. To declare a provider in a module, perform the following three steps:

So root module because per our module docs:

Provider configurations, unlike most other concepts in Terraform, are global to an entire Terraform configuration and can be shared across module boundaries. Provider configurations can be defined only in a root Terraform module.

We mention this below (line 30), so maybe the last sentence can be left off here.

And should instead of must because Terraform will automagically install a matching provider based on resource name even if you don't add the required_providers or provider block...we should maybe mention this somewhere?

eg, this configuration by itself will work:

main.tf:

resource "random_pet" "foo" {
  length = 2
}

output "pet_name" {
  value = random_pet.foo.id
}

$ terraform init && terraform apply -auto-approve:

Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/random...
- Installing hashicorp/random v3.7.2...
- Installed hashicorp/random v3.7.2 (signed by HashiCorp)
Terraform has created a lock file .terraform.lock.hcl to record the provider
## ...
random_pet.foo: Creation complete after 0s [id=capital-raptor]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

pet_name = "capital-raptor"

1. Define the provider's source, local name, and version in the [`required_providers` block](/terraform/language/block/terraform#required_providers) inside your top-level `terraform` block.
1. Add a top-level `provider` block to your configuration to configure a provider with authentication, a region, and other provider-specific arguments.
1. Install your provider.
- Running `terraform init` locally installs a provider and updates the [Dependency lock file](/terraform/language/files/dependency-lock) with the version you specified in your configuration.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Running `terraform init` locally installs a provider and updates the [Dependency lock file](/terraform/language/files/dependency-lock) with the version you specified in your configuration.
- Running `terraform init` locally installs a provider and updates the [Dependency lock file](/terraform/language/files/dependency-lock) with the latest version matching the version string you configured in your `required_providers` block.

1. Add a top-level `provider` block to your configuration to configure a provider with authentication, a region, and other provider-specific arguments.
1. Install your provider.
- Running `terraform init` locally installs a provider and updates the [Dependency lock file](/terraform/language/files/dependency-lock) with the version you specified in your configuration.
- HCP Terraform and Terraform Enterprise install providers as part of every run.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- HCP Terraform and Terraform Enterprise install providers as part of every run.
- HCP Terraform and Terraform Enterprise install providers as part of every run, using the versions provided in the dependency lock file, if it exists.

- Running `terraform init` locally installs a provider and updates the [Dependency lock file](/terraform/language/files/dependency-lock) with the version you specified in your configuration.
- HCP Terraform and Terraform Enterprise install providers as part of every run.

If you are running Terraform locally, your plan and apply operations use the provider versions specified in the dependency lock file. You can upgrade a provider version in your lock file by changing the value in your configuration and re-running `terraform init`. To learn more about declaring providers, refer to [Provider requirements](/terraform/language/providers/requirements).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you are running Terraform locally, your plan and apply operations use the provider versions specified in the dependency lock file. You can upgrade a provider version in your lock file by changing the value in your configuration and re-running `terraform init`. To learn more about declaring providers, refer to [Provider requirements](/terraform/language/providers/requirements).
If you are running Terraform locally, your plan and apply operations use the provider versions specified in the dependency lock file. You can upgrade a provider version in your lock file by changing the version in the `required_providers` block and re-running `terraform init`. To learn more about declaring providers, refer to [Provider requirements](/terraform/language/providers/requirements).


You can use [expressions](/terraform/language/expressions) to configure provider arguments, but you can only reference values that Terraform knows before it applies your configuration. Meaning, you can reference input variables and arguments that you specify directly in your configuration, but not any computed resource attributes, such as `google.web.public_ip`.

Many providers support shell environment variables or other alternate sources for their configuration values, which helps keep credentials out of your version-controlled Terraform code. Refer to a provider's documentation to learn more about the assignment methods each argument supports.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Many providers support shell environment variables or other alternate sources for their configuration values, which helps keep credentials out of your version-controlled Terraform code. Refer to a provider's documentation to learn more about the assignment methods each argument supports.
Many providers support shell environment variables or other alternate sources for their configuration values, which helps keep credentials out of your version-controlled Terraform configuration. Refer to a provider's documentation to learn more about the assignment methods each argument supports.


### `version`

The `version` argument in provider configurations is deprecated, and Terraform will remove it in a future version. Instead, declare provider version constraints in [the `terraform` block's `required_providers` argument](/terraform/language/providers/requirements).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `version` argument in provider configurations is deprecated, and Terraform will remove it in a future version. Instead, declare provider version constraints in [the `terraform` block's `required_providers` argument](/terraform/language/providers/requirements).
The `version` argument in provider configurations is deprecated, and Terraform will remove it in a future version. Instead, declare provider version constraints in [the `terraform` block's `required_providers` block](/terraform/language/providers/requirements).


</CodeBlockConfig>

You can further configure a provider with the `provider` block in the root module of your configuration.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can further configure a provider with the `provider` block in the root module of your configuration.
You can configure the provider with the `provider` block in the root module of your configuration.

Maybe I'm splitting hairs, but my thinking is that the required_providers block configures terraform to use the specified provider, and the provider's configuration is in the provider block?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also...should we mention somewhere that the terraform { } block being in terraform.tf and the provider "google" { } block in main.tf is our recommended convention?


### Pass provider configurations to a child module

We recommend defining providers in root modules, and passing those provider configurations from parent modules to child modules to ensure your modules all use the same provider configurations. You can pass provider configurations from a root module to child modules using the [`providers` argument](/terraform/language/meta-arguments/module-providers).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implies that we recommend explicitly passing providers to child modules rather than relying on implicit passing...I don't think we intend to do that, but I could be wrong...eg the main use modules tutorial passes the provider implicitly.

Also, I'm not sure how much is recommendation vs. requirement, eg our current docs say: Provider configurations can be defined only in a root Terraform module. - I don't think that's technically correct, but I think our intent is "Don't do this" rather than a soft recommendation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also also, assuming implicitly passing providers is ok, and the default behavior is fine, then we should introduce an example of that first, before explicit example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever the final wording is, we should add it to the main usage page and link to it from here.

Comment on lines +413 to +417
```hcl
provider "random" {

}
```
Copy link
Contributor

@robin-norwood robin-norwood Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```hcl
provider "random" {
}
```
```hcl
provider "random" { }
```

I see this style in examples more often than the line-break style for "empty" provider configuration.

Copy link
Contributor

@trujillo-adam trujillo-adam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good. There are a few sections that I think are misplaced, though. We should discuss before merging.


Use the `provider` block to declare and configure Terraform plugins, called providers. Providers let Terraform manage real-world infrastructure with provider-defined resources and data sources.

> **Hands-on:** Try the [Perform CRUD Operations with Providers](/terraform/tutorials/configuration-language/provider-use) tutorial.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> **Hands-on:** Try the [Perform CRUD Operations with Providers](/terraform/tutorials/configuration-language/provider-use) tutorial.
> **Hands-on:** Try the [Perform CRUD Operations with Providers](/terraform/tutorials/configuration-language/provider-use) tutorial.

Links to tutorials from a reference page seem out of place to me. I would expect them to appear on overview and usage pages because they are more aligned with user learning paths. Not a dealbreaker, but just something we should align on in the future.


> **Hands-on:** Try the [Perform CRUD Operations with Providers](/terraform/tutorials/configuration-language/provider-use) tutorial.

## Background
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost all of this information is misplaced. Workflow-related information, such as developing and distributing providers, should be in the overview page. We should also link to the init command instead of describing how to run it here.


### `provider "<PROVIDER_NAME>"`

The name given in the block header specifies the [local name](/terraform/language/providers/requirements#local-names) of the provider to configure.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The name given in the block header specifies the [local name](/terraform/language/providers/requirements#local-names) of the provider to configure.
You must specify the name of the provider that you want to configure as an inline argument. Refer to [Local names](/terraform/language/providers/requirements#local-names) for more information.

I had a hard time parsing this sentence, but I think this is what we mean. Ignore if I'm wrong and the only one who was having trouble understanding.


The name given in the block header specifies the [local name](/terraform/language/providers/requirements#local-names) of the provider to configure.

The following arguments are supported in a `provider` block:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The following arguments are supported in a `provider` block:
You can specify the following arguments in a `provider` block:

Active voice


If you do not explicitly define a `provider` block, Terraform assumes and creates an empty default configuration for that provider. However, if a provider has required arguments, Terraform raises an error because it can't create that provider without the required values.

You can use [expressions](/terraform/language/expressions) to configure provider arguments, but you can only reference values that Terraform knows before it applies your configuration. Meaning, you can reference input variables and arguments that you specify directly in your configuration, but not any computed resource attributes, such as `google.web.public_ip`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can use [expressions](/terraform/language/expressions) to configure provider arguments, but you can only reference values that Terraform knows before it applies your configuration. Meaning, you can reference input variables and arguments that you specify directly in your configuration, but not any computed resource attributes, such as `google.web.public_ip`.
You can use [expressions](/terraform/language/expressions) to configure provider arguments, but you can only reference values that Terraform knows before it applies your configuration. You can reference input variables and arguments that you specify directly in your configuration, but you can't reference computed resource attributes, such as `google.web.public_ip`.

I don't love the anthropomorphic language about "Terraform knowing" things, but none of the alternatives I've tried have passed mustard. I think we should consider flagging phrases such as "in other words", "meaning", and "that is" in the style guide.


### Pass provider configurations to a child module

We recommend defining providers in root modules, and passing those provider configurations from parent modules to child modules to ensure your modules all use the same provider configurations. You can pass provider configurations from a root module to child modules using the [`providers` argument](/terraform/language/meta-arguments/module-providers).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever the final wording is, we should add it to the main usage page and link to it from here.


### Using an alternate provider configuration in a child module

To use an aliased provider configurations in a child module, the child module must declare the alias using the `configuration_aliases` argument in the `required_providers` block.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To use an aliased provider configurations in a child module, the child module must declare the alias using the `configuration_aliases` argument in the `required_providers` block.
To use an aliased provider configurations in a child module, the child module must declare the alias using the `configuration_aliases` argument in the `required_providers` block.

This is the first time I've seen the configuration_aliases argument. Is this an AWS-specific argument or part of Terraform configuration language? Do we need to add it to the terraform block reference?

@@ -290,7 +290,7 @@ resource {

By default, Terraform automatically selects a provider based on the resource type, but you can create multiple provider configurations and use a non-default configuration for specific resources.

Use the `<PROVIDER>.<ALIAS>` syntax to reference a provider configuration in the `provider` argument. Refer to [Multiple Provider Configurations](/terraform/language/providers/configuration#alias-multiple-provider-configurations) for instructions on how to reference a specific provider configuration.
Use the `<PROVIDER>.<ALIAS>` syntax to reference a provider configuration in the `provider` argument. Refer to [Using an alternate provider configuration](/terraform/language/block/provider#using-an-alternate-provider-configuration) for an example of how to reference a specific provider configuration.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Use the `<PROVIDER>.<ALIAS>` syntax to reference a provider configuration in the `provider` argument. Refer to [Using an alternate provider configuration](/terraform/language/block/provider#using-an-alternate-provider-configuration) for an example of how to reference a specific provider configuration.
Use the `<PROVIDER>.<ALIAS>` syntax to reference a provider configuration in the `provider` argument.

I think we can remove this link since there is already an example on this page

@@ -9,7 +9,7 @@ description: >-

In a [module call](/terraform/language/modules/syntax) block, the
optional `providers` meta-argument specifies which
[provider configurations](/terraform/language/providers/configuration) from the parent
[provider configurations](/terraform/language/block/provider) from the parent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[provider configurations](/terraform/language/block/provider) from the parent
[provider configurations](/terraform/language/block/provider) from the parent

All of these meta-arguments pages are collapsing into a single concept page per https://hashicorp.atlassian.net/browse/IPE-1128, fyi

@@ -72,7 +72,7 @@ however, specify any of the configuration settings that determine what remote
endpoints the provider will access, such as an AWS region; configuration
settings come from provider _configurations_, and a particular overall Terraform
configuration can potentially have
[several different configurations for the same provider](/terraform/language/providers/configuration#alias-multiple-provider-configurations).
[several different configurations for the same provider](/terraform/language/block/provider#using-an-alternate-provider-configuration).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[several different configurations for the same provider](/terraform/language/block/provider#using-an-alternate-provider-configuration).
[several different configurations for the same provider](/terraform/language/block/provider#select-an-alternate-provider-configuration).

You don't have to use the heading I suggested, just something that follows the style guidance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants