A configuration has been working for weeks with a single provider. A practitioner adds a new 'required_providers' entry for the random provider and a 'random_pet' resource, then runs 'terraform plan'. Terraform reports that it requires the random provider but it is not installed. What is the correct next step?
terraform {
required_providers {
aws = { source = "hashicorp/aws", version = "~> 5.0" }
random = { source = "hashicorp/random", version = "~> 3.6" }
}
}
resource "random_pet" "name" {
length = 2
}- ARun 'terraform apply -auto-approve', which will pull the random provider automatically as part of applying the new resource.
- BRe-run 'terraform init' so Terraform installs the newly added random provider into the working directory. Correct
- CRun 'terraform get -update' to fetch the random provider, since it retrieves both modules and providers.
- DDelete the .terraform.lock.hcl file so Terraform re-resolves and installs all providers on the next plan.
Why A is wrong: This is tempting because apply follows plan, but apply also depends on installed plugins and will fail for the same reason until the provider is installed by init.
Why B is correct: Correct: adding a provider changes the directory's requirements, and 'terraform init' is re-run to install the new provider and update the lock file.
Why C is wrong: This looks plausible, but 'terraform get' only downloads modules referenced by the configuration and does not install provider plugins.
Why D is wrong: Removing the lock file changes version selection but does not itself install anything, and plan still does not install providers, so the error persists until init runs.