tofu providers lists the providers a project needs, where each one comes from and which versions it accepts. It’s the quickest answer to “why does this project download that provider?”
Syntax
tofu providers [options]
tofu providers <subcommand> [options]
- With no subcommand, it prints a tree of the providers the configuration and the state require.
<subcommand>:lockwrites dependency locks for the configured providers,mirrorsaves local copies of the provider plugins, andschemashows the providers’ schemas.[options]: for example-no-color.
The command and its subcommands are described in Command: providers (opens in a new tab) in the OpenTofu® docs.
This guide lists the providers of a small project that uses two of them.
Prerequisites
- OpenTofu installed: How to Install OpenTofu on macOS.
- A terminal and an empty folder, such as
tofu-providers.
Step 1: Write a Configuration with Two Providers
Create main.tf:
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "~> 2.9"
}
random = {
source = "hashicorp/random"
version = "~> 3.9"
}
}
}
resource "random_pet" "shop_name" {}
resource "local_file" "welcome" {
filename = "welcome.txt"
content = "Welcome to ${random_pet.shop_name.id}"
}
It names a random shop with the random provider and writes it into a file with the local provider.
Step 2: Run tofu init
tofu init
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/random versions matching "~> 3.9"...
- Finding hashicorp/local versions matching "~> 2.9"...
- Installing hashicorp/random v3.9.1...
- Installing hashicorp/local v2.9.1...
- Installed hashicorp/local v2.9.1 (signed, key ID 0C0AF313E5FD9F80)
- Installed hashicorp/random v3.9.1 (signed, key ID 0C0AF313E5FD9F80)
Providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://opentofu.org/docs/cli/plugins/signing/
OpenTofu has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that OpenTofu can guarantee to make the same selections by default when
you run "tofu init" in the future.
OpenTofu has been successfully initialized!
Step 3: List the Providers
tofu providers
Providers required by configuration:
.
├── provider[registry.opentofu.org/hashicorp/local] ~> 2.9
└── provider[registry.opentofu.org/hashicorp/random] ~> 3.9
tofu providers lists each provider and its version constraint..is the project’s own folder, the root module. Providers needed by modules it uses would appear on branches under it.- Each line shows a provider’s full address,
registry.opentofu.org/hashicorp/local, and its version constraint.
Once you’ve run tofu apply, a second list, Providers required by state, shows the providers of the resources OpenTofu manages, as in Part 3 of the OpenTofu Tutorial.
Clean Up
Delete the tofu-providers folder. Nothing was applied, so nothing else was created.
FAQ
Do I need to run tofu init first?
No. tofu providers reads the configuration and the state, so it works before the providers are downloaded.
Where do the exact versions come from?
The tree shows constraints. The exact versions in use are in the dependency lock file.
Conclusion
tofu providers shows every provider a project needs, with its address and constraint, in one short tree.
Related
- OpenTofu Tutorial — Part 3: Providers: Run the Website in Docker
- What Is .terraform.lock.hcl in OpenTofu?
- OpenTofu Version Constraints Explained
Additional Resources
OpenTofu® is a registered trademark of LF Projects, LLC. Other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by the OpenTofu project.
0 comments