Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 59


Terraform provisioners can be added to any resource block.

Show Answer
Correct Answer: B

Terraform provisioners cannot be added to any resource block. They are typically added to resource blocks that support them. The use of provisioners complicates the Terraform model and is not recommended where other solutions are available. It is crucial to use provisioners only as a last resort for actions that cannot be performed through other Terraform means.

Discussion

39 comments
Sign in to comment
GopinathM
Mar 8, 2023

A is correct https://www.terraform.io/language/resources/provisioners/syntax resource "aws_instance" "web" { # ... provisioner "local-exec" { command = "echo The server's IP address is ${self.private_ip}" } }

agmesasOption: A
Aug 6, 2023

the key of this question is "could you use a local-exec provisioner in any type of resource?", yes, because the execution of this provisioner is on my local so we couldnuse local-exec in any resource type because it is independent of the type of resource. Answer is A "true"

debabrata6983Option: A
Feb 26, 2024

Please stop confusing people. Basics of Provisioner block : always bind with resource block

elnurguOption: A
Apr 18, 2023

I can add local-exec to any resource block such as aws_s3, aws_eip and etc., So, answer is A

BereOption: A
Feb 7, 2024

Since the local-exec provisioner executes on the machine running Terraform and not on the resource itself, it can indeed be added to any resource block. The actions taken by the local-exec provisioner are not dependent on the type of resource, so it's possible to use this provisioner with any resource in Terraform.

bigboi23Option: B
Nov 18, 2022

Provisioners can only be added to virtual machines and other compute resources

Jaro3000
Dec 11, 2022

Yeah, looks like B "Provisioners can be used to model specific actions on the local machine or on a remote machine in order to prepare servers or other infrastructure objects for service"

CHRIS12722222
Jan 27, 2023

This statement is wrong. Local exec provisioners can be added to resource blocks that are not virtual machines or compute instances

TanacetOption: A
Jul 28, 2023

Provisioner is an arbitrary command executed by the terraform when a resource is created/destroyed. It is not related to a resource itself. The creation/destruction of a resource is just a trigger.

NunyabiznesOption: A
Sep 21, 2023

Provisioners can be added to any resource block in Terraform configuration, but it is not recommended to use them for configuration management as it goes against the declarative approach of Terraform. Provisioners should only be used as a last resort when no other Terraform resource types are available to handle a specific task.

sylvergorillaOption: A
Oct 14, 2023

Yes, Terraform provisioners can be added to any resource block. Provisioners are used to execute scripts or commands on a resource after it has been created or updated.

LunarPhobia
Jan 26, 2024

The new exam doesn't ask about provisioners anymore

Pradh
Mar 27, 2024

answer should be "B" Can you add a provisioner to below resource block ? ============================== resource "azurerm_network_interface" "Nic-1" ==============================

ilmi70
Aug 21, 2024

resource "azurerm_network_interface" "Nic-1" { # ... provisioner "local-exec" { command = "echo 'Network interface created'" } }

pj2001
Nov 27, 2022

Can you not add "local-exec" provisioner to any resource block? I pick A

cytronOption: B
Dec 3, 2022

Its a B. You can't add a provisioned to the Terraform block in example.

Jaro3000
Dec 11, 2022

They ask about resource blocks. Terraform block is not a resource block.

mifune
Dec 25, 2022

You are right, but, within all "resource" blocks, not all of them can address a provisioner, for example, an aws_eip

mifune
Dec 25, 2022

You are right, but, within all "resource" blocks, not all of them can address a provisioner, for example, an aws_eip

Oskar_Madin
Dec 28, 2022

how we can execute scripts for example in such resource "aws_security_group" even its resource? Provisioners are used to execute scripts on a local or remote machine as part of resource creation or destruction. so answer is False.

CHRIS12722222
Jan 27, 2023

This statement is incorrect. Local exec provisioners can execute in any resource block. I think you are referrring to remote-exec provisioners which need to be in resource block of compute instances

EltoothOption: B
Dec 28, 2022

B is correct answer. False. https://www.terraform.io/language/providers/requirements#requiring-providers

tbhtp
Feb 16, 2023

B is certainly false: The question is about provisioners not providers.

lucitama
Jan 1, 2023

If you are certain that provisioners are the best way to solve your problem after considering the advice in the sections above, you can add a provisioner block inside the resource block of a compute instance. B is correct

alexik96
Apr 3, 2023

A: I can add a local-exec to any resource block

chimonsOption: A
Jun 19, 2023

True. Terraform provisioners can be added to any resource block in a Terraform configuration file. Provisioners allow you to perform additional configuration tasks on a resource after it has been created. For example, you might use a provisioner to install software on an EC2 instance or run a script on a newly created VM. To add a provisioner to a resource block, you can use the provisioner block within the resource block. You can add multiple provisioners to a single resource block if necessary. Here is an example of adding a provisioner to an EC2 instance resource: Copy code resource "aws_instance" "example" { ami = "ami-123456" instance_type = "t2.micro" provisioner "remote-exec" { inline = [ "sudo apt-get update", "sudo apt-get install -y nginx", ] } } In this example, the provisioner will run the apt-get update and apt-get install commands on the EC2 instance after it has been created. So, option A, true, is the correct answer. Option B, false, is incorrect.

azurearch
Jun 22, 2023

If you are certain that provisioners are the best way to solve your problem after considering the advice in the sections above, you can add a provisioner block inside the resource block of a compute instance.

Bluemoon22
Oct 24, 2023

The answer is A

Ni33Option: A
Nov 9, 2023

AAAAAAAA

modarov
Feb 5, 2024

The answer is False. Terraform provisioners can only be added to resource blocks that support them

samimshaikhOption: A
Jun 29, 2024

A. True Terraform provisioners can be added to any resource block. Provisioners are used to execute scripts or commands on a local or remote machine as part of resource creation or destruction. They are defined within a resource block and allow you to perform actions such as initializing, configuring, or setting up resources after they have been created.

SabgKrish
Nov 19, 2022

Answer is false (B)

Zam88
Dec 20, 2022

If you are certain that provisioners are the best way to solve your problem after considering the advice in the sections above, you can add a provisioner block inside the resource block of a compute instance. above from the doc B is correct

19kilo
Jan 13, 2023

Literally just tried it in an S3 resource. lol almost like they put out a false question list to weed people out. Error: Unsupported block type on main.tf line 20, in module "s3_bucket": 20: provisioner "local-exec" { Blocks of type "provisioner" are not expected here.

19kilo
Jan 13, 2023

Never mind, forgot that I was using a module. Seemed to validate and plan ok with an S3 resource while also having a provisioner. Has to be a trick question. The documentation states "you can add a provisioner block inside the resource block of a compute instance." They call out compute instance, but it appears to work on non-compute resource blocks. ¯\_(ツ)_/¯ I'm calling it true from my testing. However, the apply did fail due to what was in the provisioner. https://www.terraform.io/language/resources/provisioners/syntax#how-to-use-provisioners

tbhtpOption: A
Feb 16, 2023

A is right: You definitively CAN add the "local-exec" provisioner to any resource, as this executes the command on the local system where the tf runs. See the doc example with the "null_resource" for local-exec. Please note that people maybe voted B because "remote-exec" is the only provisioner they know. https://www.terraform.io/language/resources/provisioners/local-exec

Fati_2022
Mar 8, 2023

A https://www.phillipsj.net/posts/introduction-to-terraform-provisioners/ As you continue learning about Terraform, you will start hearing about provisioners. Terraform provisioners can be created on any resource and provide a way to execute actions on local or remote machines.

faltu1985Option: A
Mar 26, 2023

I think ans is A

daawwOption: A
Apr 1, 2023

A is correct

udibieOption: A
Apr 2, 2023

A is correct

Bobby1977
Apr 5, 2023

A is correct

kshdiuashduahsduasOption: A
Apr 5, 2023

definitely A

G4Exams
Apr 30, 2023

It should be A. 90%. The only problem is the word "can" because the provisioner MUST or always be inside the resource block... that disturbs a bit but I still say A.

FarziWaliMarziOption: A
Jun 23, 2023

Option A is common sense

Power123
Oct 1, 2023

A is correct

Jlee7
Dec 25, 2023

The answer is False. Terraform provisioners can only be added to resource blocks that support them. For example, the AWS provider supports the remote-exec provisioner, but the Azure provider does not.

joyboy23
Jan 6, 2024

But what about the local-exec ?

Ha_Baruh_Architect13
Jan 12, 2024

The correct answer is B. False. Terraform provisioners are not added to resource blocks directly. Instead, provisioners are added as separate blocks within a resource block. Provisioners are used to execute scripts or commands on a resource after it has been created or updated. They are defined outside of the resource block and are associated with the resource using the "provisioner" keyword followed by the specific provisioner type CHATGPT

suri_surendraOption: B
Dec 29, 2024

The correct answer is: B. False Explanation: Terraform provisioners are not automatically supported in all resource blocks. They are designed to be used with specific types of resources, primarily those that involve remote execution or configuration (such as virtual machines or instances). However, not every resource type is compatible with provisioners.