1. Initializing Your Directory
Run the following command in a directory containing your OpenTofu configuration files:.tf files, tofu init will:
- Install all required provider plugins.
- Create a lock file (
.terraform.lock.hcl) to pin provider versions. - Ensure idempotent behavior: rerunning does not alter existing infrastructure.
Always commit the
.terraform.lock.hcl file to your VCS. This ensures consistent provider versions across environments..terraform/providers in your working directory.
2. Provider Types
Providers are distributed via Terraform Registry and OpenTofu Registry, and fall into three categories:
3. Plugin Naming Conventions
Each provider is referenced by a source address with this structure:- hostname (optional): Defaults to
registry.opentofu.orgif omitted. - namespace: Organization or author (e.g.,
hashicorp). - type: Provider name (e.g.,
aws,local).