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.

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

}
```
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
```hcl
provider "random" {
}
```
```hcl
provider "random" { }

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

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.

2 participants