HashiCorp Terraform Associate (004) · Section 2 · 12% of the exam
Write Terraform configuration using multiple providers
One of the objectives of the HashiCorp Certified: Terraform Associate (004) exam, in the section “Terraform fundamentals”. Here is what it covers, the points to remember and a question to try.
What it covers
Providers are the plugins that let Terraform talk to platforms. This lesson covers declaring them with required_providers, source addresses and version constraints, how init and the lock file install them, mirrors and caching, and how to configure several providers or several configurations of one provider, including in modules.
Points to remember
- Providers are plugin executables; Terraform Core talks to them over RPC and never calls platform APIs itself.
- The resource type prefix before the first underscore selects the provider unless
provideris set. - Declare providers in
required_providersinside theterraformblock; a source is[hostname/]namespace/typeand defaults toregistry.terraform.ioand, when absent, tohashicorp/<local name>. ~> 3.6.0allows 3.6.x only;~> 3.6allows anything from 3.6 up to but excluding 4.0. Reusable modules set a minimum with>=only.terraform initinstalls providers into.terraform/providersand writes.terraform.lock.hcl; later inits reuse the locked version;init -upgrademoves to the newest allowed.
Try a question
A configuration declares source = "hashicorp/random" with no hostname. From which registry does terraform init download the provider?
- Aapp.terraform.io, because the namespace belongs to HashiCorp
- Bregistry.terraform.io, the public Terraform Registry
- Creleases.hashicorp.com, the Terraform binary download site
- Dgithub.com, from the repository named in the namespace
Show the answer
B. A source address is [hostname/]namespace/type. When the hostname is left out Terraform assumes registry.terraform.io, so hashicorp/random means registry.terraform.io/hashicorp/random.
Written for practice in the style of the exam: never a question from the real exam.
In the course
The lesson Terraform providers: install, version and combine teaches this objective (about 45 minutes), and 28 practice questions test it. The course has lessons, exam-style questions, timed practice exams and an AI tutor for every objective, and a pass prediction that tells you when you're ready to book.