HashiCorp Terraform Associate (004) Question 35
Single answer2b Describe how Terraform uses providersYour team maintains Terraform code that creates resources in AWS and also configures DNS records in Cloudflare. A new engineer adds both aws_instance and cloudflare_record resources to the same root module but does not declare any required_providers block. When they run terraform init, Terraform still attempts to identify and install the needed plugins based on the configuration. Which statement best explains how Terraform uses providers in this situation?
- A
Terraform analyzes the resource type prefixes in the configuration, determines which providers are needed, and installs provider plugins during terraform init.
- B
Terraform can create aws_instance and cloudflare_record resources without providers because providers are only needed for authentication, not for resource management.
- C
Terraform automatically converts all third-party resources into built-in Terraform resources, so provider installation is optional.
- D
Terraform waits until terraform apply to detect which providers are needed because provider selection is part of the execution phase, not initialization.
Show answer and explanation
Correct answer: A
Explanation
Providers are a core Terraform concept: they act as plugins that let Terraform interact with external APIs and expose resource types and data sources. In this scenario, Terraform identifies needed providers from the configuration, such as the aws provider for aws_instance and the cloudflare provider for cloudflare_record, and installs them during terraform init. Although Terraform can infer provider requirements from resource prefixes in some cases, HashiCorp documentation recommends declaring required_providers explicitly in the terraform block so the source address and version constraints are clear and reproducible. This is especially important for dependency lock files, consistent team workflows, and avoiding ambiguity with non-HashiCorp providers. Relevant references include the Terraform documentation on providers, provider requirements, and the terraform init command.
- A. Correct.
Correct. Terraform uses providers as the plugins that define resource types and data sources and that handle API interactions with external platforms. During terraform init, Terraform inspects the configuration, including resource type names such as aws_instance and cloudflare_record, to determine which providers are required and then installs them. In modern Terraform configurations, explicitly declaring required_providers is a best practice because it records the source address and version constraints, but Terraform still uses providers to understand and manage those resource types.
- B. Incorrect.
Incorrect. Providers are not just for authentication. They are the components Terraform uses to define, validate, read, create, update, and delete resources through external APIs. Without the relevant provider, Terraform does not know how to manage an aws_instance or a cloudflare_record resource at all.
- C. Incorrect.
Incorrect. Terraform does not convert external resource types into built-in Terraform resources. Most infrastructure object types are implemented by providers, which are separate plugins. Built-in functionality in Terraform is limited and does not replace provider plugins for platform-specific resources such as AWS EC2 instances or Cloudflare DNS records.
- D. Incorrect.
Incorrect. Provider discovery and installation happen during terraform init, not only during terraform apply. Terraform initializes the working directory, downloads required providers, and prepares the configuration before planning or applying changes. Apply uses the already initialized providers to perform operations.