Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 5


A provider configuration block is required in every Terraform configuration.

Example:

Show Answer
Correct Answer: B

A provider configuration block is not required in every Terraform configuration. If the resources in the configuration only use a single provider's resources and do not require any specific configuration for that provider, Terraform can infer the provider and use the default settings. This means that the provider block can be omitted and Terraform will automatically download and use the necessary provider based on the resource types used.

Discussion

82 comments
Sign in to comment
softartsOption: A
May 16, 2022

vote A

foreverlearnerOption: B
Sep 24, 2024

I can see the confusion here. https://developer.hashicorp.com/terraform/language/providers/configuration says "all Terraform configurations must declare which providers they require so that Terraform can install and use them", which makes people think the answer is A/True. The question says "A provider configuration block is required" (emphasis on BLOCK). The above link also says " a provider block may be omitted if its contents would otherwise be empty. Terraform assumes an empty default configuration for any provider that is not explicitly configured.", which confirms that the answer is B/FALSE, a provider BLOCK is not required, Terraform assumes a default one for you. So a provider is required, a provider BLOCK is not

FCN
May 23, 2022

It's B, empty provider block can be omitted.

Ahmad_Terraform
Jun 22, 2022

agreed doesn't work without provider

ivanenko
Jun 26, 2022

B (false): null provider does not require initialization; one can sefely write a configuration with null_resources without any provider blocks

r1ck
Mar 1, 2023

all Terraform configurations must declare which providers they require so that Terraform can install and use them. https://developer.hashicorp.com/terraform/language/providers/configuration

petliura
May 25, 2022

B - False. You don't have to specify a provider block since Terraform is smart enough to download the right provider based on the specified resources.

amrith501Option: B
Jun 15, 2022

*Every terraform* configuration is the key here A provider is not mandatory for EVRY configuration

mifune
Jun 25, 2022

As simple as creating an empty folder and doing the Terraform flow: init-plan-appy. No error at all. Correct answer: B

denismaggior8Option: B
Nov 26, 2022

It can be omitted

biscuithammerOption: B
May 23, 2022

should be B.

CedhulkOption: B
Jun 19, 2022

vote B

Zam88
Jun 20, 2022

I have test in the lab with out terraform Provider and it works. correct answer is B

Oskar_Madin
Jul 2, 2022

ridiculous how did you tested and what lab used, you should get Error: error configuring Terraform AWS Provider: error validating provider credentials: error calling sts:GetCallerIdentity: operation error STS: GetCallerIdentity, https response error StatusCode: 403, RequestID how do you tell terraform where provision and how authenticate?

CHRIS12722222
Jul 28, 2022

AWS provider block requires you to configure it with region where you want to deploy resources so you have to specify a provider block. However, if no configuration is needed and provider block is going to be empty then you can leave out provider. B is correct !!

AnonymousOption: B
Jun 27, 2022

B is correct

flaviu888
Jul 3, 2022

should be B. Unlike many other objects in the Terraform language, a provider block may be omitted if its contents would otherwise be empty. Terraform assumes an empty default configuration for any provider that is not explicitly configured.

Arnaud92Option: B
Jul 27, 2022

You can run terraform without a provider, it depends on what you are doing, as already mentionned "null" doesn't require a provider to be configured

Raji82
Jul 29, 2022

also https://www.terraform.io/language/providers/requirements

DeeOne17Option: A
Aug 22, 2022

https://www.terraform.io/language/providers/configuration "Additionally, all Terraform configurations must declare which providers they require so that Terraform can install and use them. The Provider Requirements page documents how to declare providers so Terraform can install them.

RVivek
Aug 31, 2022

Documentation says "Terraform configurations must declare which providers they require so that Terraform can install and use them" However for many providers available in Terraform Registry, based on the resourcse bloaks we define teraafom automatically installs provider pluggins. Hence both answers are correct.

yogishrb2020
Oct 7, 2022

what if the provider not existing in the registry?

adoubanOption: B
Dec 9, 2022

Vote B, not necessary to define provide. e.g. local built-in provider

pfilourencoOption: B
Dec 11, 2022

It's B. From the official documentation: Unlike many other objects in the Terraform language, a provider block may be omitted if its contents would otherwise be empty. Terraform assumes an empty default configuration for any provider that is not explicitly configured.

Bere
Dec 19, 2022

I understand that Provider Requirements (required_providers) is mandatory: https://developer.hashicorp.com/terraform/language/providers/requirements#requiring-providers Each Terraform module must declare which providers it requires, so that Terraform can install and use them. Provider requirements are declared in a “required_providers” block. However Provider Configuration (provider) is not mandatory: https://developer.hashicorp.com/terraform/language/providers/configuration#provider-configuration-1 Unlike many other objects in the Terraform language, a “provider” block may be omitted if its contents would otherwise be empty. Terraform assumes an empty default configuration for any provider that is not explicitly configured.

kennynelconOption: B
Jan 5, 2023

Unlike many other objects in the Terraform language, a provider block may be omitted if its contents would otherwise be empty. https://developer.hashicorp.com/terraform/language/providers/configuration

SatenderRatheeOption: B
Jan 30, 2023

It is optional so correct answer is B.

campsOption: B
Mar 31, 2023

B. False A provider configuration block is only required for those resources that need to be managed by a provider. If a configuration does not reference any provider resources, then a provider configuration block is not required. However, if any resources are defined that require a provider, then a provider configuration block must be included to define which provider should be used for the resources.

dhez46Option: B
Apr 2, 2023

No need to use the provider block everytime. The providers can be declared in the Terraform block.

coord
Apr 25, 2023

Additionally, all Terraform configurations must declare which providers they require so that Terraform can install and use them. The Provider Requirements page documents how to declare providers so Terraform can install them. https://developer.hashicorp.com/terraform/language/providers/configuration#provider-configuration

bakari1991Option: A
Jun 17, 2023

https://developer.hashicorp.com/terraform/language/providers/configuration Additionally, all Terraform configurations must declare which providers they require so that Terraform can install and use them.

Busi57Option: B
Jul 23, 2023

I vote B

DANDA9989
Sep 12, 2023

No, a provider configuration block is not required in every Terraform configuration. However, it is required if you want to use a provider to create or manage resources. A provider configuration block specifies the settings that Terraform needs to use the provider. This can include things like the provider's endpoint URL, the cloud region, and the credentials that Terraform will use to authenticate with the provider. If you do not specify a provider configuration block, Terraform will use the default provider configuration. The default provider configuration is defined in the provider's documentation. In some cases, the default provider configuration may not be sufficient. For example, if you are using a provider in a region that is not supported by the default configuration, you will need to specify a provider configuration block.

ealpucheOption: B
Oct 27, 2023

A provider configuration block is not required in every Terraform configuration. However, it is essential in most practical cases where resources from any provider (e.g., AWS, Azure, GCP) are managed. Terraform uses the provider configuration block to establish the settings required to interact with a specific provider's resources.

AWSCurtOption: B
Feb 5, 2024

False. A provider configuration block is not required in every Terraform configuration. Provider configuration blocks are only required when you are using a particular provider to interact with a specific type of infrastructure resource. If your configuration does not interact with any resources provided by external providers, then you do not need to include a provider configuration block.

6957dbdOption: A
Mar 10, 2024

https://developer.hashicorp.com/terraform/language/providers/configuration Additionally, all Terraform configurations must declare which providers they require so that Terraform can install and use them. The Provider Requirements page documents how to declare providers so Terraform can install them.

liuyomzOption: B
Apr 23, 2024

B. i got it wrong but its on docs

hrajkuma
Jul 12, 2024

vote for B. False A provider configuration block is not required in every Terraform configuration. Provider configuration blocks are only required when you are using a particular provider to interact with a specific type of infrastructure resource. If your configuration does not interact with any resources provided by external providers, then you do not need to include a provider configuration block. :)

Chickooo
Jun 6, 2022

Just tested, terraform never works without provider block.

svsilence
Jul 10, 2022

correct anwser should be B.

robin1337Option: B
Jul 12, 2022

you can omit it

Raji82Option: B
Jul 29, 2022

https://www.terraform.io/language/providers/configuration

donathonOption: B
Aug 10, 2022

Yes blank file does executes simply because it does not have anything to do and hence does not need a provider

geekneek
Aug 16, 2022

Voted A

bukakeOption: A
Aug 25, 2022

A because terraform force you to always set a provider

kilowd
Aug 29, 2022

YES ..Terraform needs to know what provider we are working with e.g aws , azure e.tc

kilowd
Aug 30, 2022

Please ignore previous answer..After digging further the answer is NO. Terraform selects a provider based on the resource type name For example, the resource type google_compute_instance is associated automatically with the default configuration for the provider named google.

secdaddy
Dec 6, 2022

confirmed main.tf resource google_compute_instance "gci" { } % terraform init Initializing the backend... Initializing provider plugins... - Finding latest version of hashicorp/google...

WorkHardBeProud
Sep 21, 2022

I believe "required providers" block is required not "provider"

PBSH56Option: B
Sep 23, 2022

I go to with option B if I create a block resource "google_storage_bucket" "static-site" { name = "image-store.com" location = "EU" force_destroy = true } then run terraform init then automatically find and install the associated provider with resource block.

methamodeOption: B
Sep 28, 2022

This is B

udibieOption: B
Oct 3, 2022

has to be false

pmzoneOption: B
Oct 5, 2022

You an run a blank .tf file as well.

Bere
Oct 13, 2022

The documentation is confusing: https://www.terraform.io/language/providers/configuration ----- Additionally, all Terraform configurations must declare which providers they require so that Terraform can install and use them. The Provider Requirements page documents how to declare providers so Terraform can install them. ----- Unlike many other objects in the Terraform language, a provider block may be omitted if its contents would otherwise be empty. Terraform assumes an empty default configuration for any provider that is not explicitly configured. -----

niccsm
Oct 20, 2022

provider requirements (specified in the `terraform` block) are not the same as provider blocks

pfilourencoOption: A
Dec 4, 2022

vote A

secdaddy
Dec 6, 2022

B is correct Built-in Provider Most providers are distributed separately in the form of plug-ins, but there is currently one provider built into the main Terraform process, that is the terraform_remote_state data source. Since the Provider is built-in, it does not need to be declared in terraform when using it required_providers. The source address of this built-in Provider is terraform.io/builtin/terraform. https://blog.devgenius.io/terraform-provider-aa57ade59eec This main.tf configuration doesn't work because I haven't created anything in terraform cloud, but terraform locally is working as if I had declared a provider, but I have not : data "terraform_remote_state" "vpc" { backend = "remote" config = { organization = "hashicorp" workspaces = { name = "vpc-prod" } } }

r1ck
Feb 25, 2023

its terraform config, not module config!

mansvyOption: A
Mar 12, 2023

We need provider block if say we are using aws, given that provider has some mandatory fields, we can keep them removed. Example for AWS - we write provider like this provider "aws" { region = "us-west-2" } Here if keep this block out, terraform console expect us to provide mandatory region while running..

gargaditya
Mar 14, 2023

I dont get what is the use of using terraform if there are 0 provider blocks-you are literally not authenticating into a service,what is being deployed then?

RybitskaOption: A
Mar 16, 2023

it's A

Atila50Option: A
Mar 27, 2023

Each Terraform module must declare which providers it requires, so that Terraform can install and use them. Provider requirements are declared in a required_providers block. The required_providers block must be nested inside the top-level terraform block (which can also contain other settings).

Red10
Mar 28, 2023

Vote B, i was able to run the Init, plan, apply and destroy without the provider block, with AWS, The code i ran was to provision a VPC, IGW and Security Group.

FaaizzOption: B
Apr 4, 2023

B is correct here

FawadKOption: A
May 11, 2023

It's clearly written here. All Terraform configurations must declare which providers they require so that Terraform can install and use them. Source:- https://developer.hashicorp.com/terraform/language/providers/configuration

SIAMIANJIOption: A
Jun 2, 2023

Providers allow Terraform to interact with cloud providers, SaaS providers, and other APIs. Some providers require you to configure them with endpoint URLs, cloud regions, or other settings before Terraform can use them. This page documents how to configure settings for providers. Additionally, all Terraform configurations must declare which providers they require so that Terraform can install and use them. The Provider Requirements page documents how to declare providers so Terraform can install them. https://developer.hashicorp.com/terraform/language/providers/configuration#provider-configuration

Mandeeps468
Jun 8, 2023

Vote B

VSMu
Jul 12, 2023

Vote B. Unlike many other objects in the Terraform language, a provider block may be omitted if its contents would otherwise be empty. Terraform assumes an empty default configuration for any provider that is not explicitly configured.

praphOption: B
Jul 24, 2023

provider block may be omitted if its contents would otherwise be empty

talron
Jul 28, 2023

It's B. I just created a resource with no provider specified and it worked.

brax404Option: B
Aug 10, 2023

Chatgpt says so

ledjo
Aug 29, 2023

I would go for B. Explanation: There are scenarios where you might not need a provider configuration block. For instance: Data-Only Configuration: If you're only using Terraform to query and retrieve data from an existing infrastructure (using data sources) without making any changes, you might not need a provider configuration block. Local Resources: In some cases, you might define only local resources that don't require external providers. For example, creating a local file or generating random values. Modules: If you're using Terraform modules that already include provider configurations, you might not need to define them at the root configuration level.

maze_
Sep 23, 2023

Although I agree with the answer B, this is a bit of a problematic example, since quite often `data` sources retrieve data from sources that *require* authentication (e.g. `data.aws_vpc.existing`).

arnabsinha4uOption: B
Sep 18, 2023

B https://developer.hashicorp.com/terraform/language/providers/configuration#provider-configuration-1

otakuinside
Sep 28, 2023

https://developer.hashicorp.com/terraform/language/providers/requirements [quote]Each Terraform module must declare which providers it requires, so that Terraform can install and use them[/quote]

gofavad926Option: B
Sep 29, 2023

B for all the reasons commented

Tyler2023
Oct 16, 2023

Answer is A based on this https://developer.hashicorp.com/terraform/language/providers/configuration Providers allow Terraform to interact with cloud providers, SaaS providers, and other APIs. Some providers require you to configure them with endpoint URLs, cloud regions, or other settings before Terraform can use them. This page documents how to configure settings for providers. Additionally, all Terraform configurations must declare which providers they require so that Terraform can install and use them. The Provider Requirements page documents how to declare providers so Terraform can install them.

MiiExamT
Nov 7, 2023

A region is needed for any infrastructure before provisioning, Terraform can't select it for you However the Terraform { required_providers { }} is optional

terraformiaasOption: B
Nov 10, 2023

It's B

bryant12138Option: B
Dec 1, 2023

Local provider does not need such a block

umavaja
Dec 12, 2023

Vote B:

SpandropOption: B
Dec 16, 2023

A Terraform configuration is a complete document in the Terraform language that tells Terraform how to manage a given collection of infrastructure. A configuration can consist of multiple files and directories. https://developer.hashicorp.com/terraform/language You don't need 1 provider block to EVERY terraform configuration, you must have at least 1, but not in every like the question mention

TigerInTheCloudOption: B
Dec 19, 2023

there is a simple valid configuration without the provider BLOCK. $ cat main.tf data "aws_region" "current" {} output "region_name" { value = data.aws_region.current.name }

MukeshRattanOption: B
Jan 20, 2024

False. A provider configuration block is not required in every Terraform configuration. It depends on the specifics of your configuration and the resources you are managing. In Terraform, provider configuration blocks are used to specify the details of the infrastructure provider you want to use, such as AWS, Azure, Google Cloud, etc. If you are managing resources that don't require a specific provider, or if your configuration relies on provider-agnostic resources, you may not need a provider configuration block.

Bedmed
Apr 1, 2024

Each Terraform module must declare which providers it requires, so that Terraform can install and use them. Provider requirements are declared in a required_providers block. A provider requirement consists of a local name, a source location, and a version constraint:

Molly1994
Jun 5, 2024

the answer is false. Terraform requires provider. but it does not require specifically to define a provider block {}. Terraform could use the default providers. so the answer is B false.

brundabanmOption: B
Jun 10, 2024

Unlike many other objects in the Terraform language, a provider block may be omitted if its contents would otherwise be empty. Terraform assumes an empty default configuration for any provider that is not explicitly configured. https://developer.hashicorp.com/terraform/language/providers/configuration

samimshaikhOption: B
Sep 24, 2024

False. A provider configuration block is not required in every Terraform configuration. It is only required when you are using a Terraform provider to interact with a specific infrastructure platform or service. A provider configuration block typically includes details such as the provider's name, version, and any required authentication or connection information. If you're not using any provider in your Terraform configuration, you may not need a provider configuration block. Here's an example of a provider configuration block for AWS: provider "aws" { region = "us-west-2" access_key = "your-access-key" secret_key = "your-secret-key" } This block specifies the AWS provider, sets the region, and provides access and secret keys for authentication. If you're not working with AWS or any other provider, you can have a Terraform configuration without a provider block.

DataEngDPOption: B
Nov 29, 2024

It refers to a BLOCK so this {} that is not mandatory.