Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

Exam Terraform Associate topic 1 question 32 discussion

Actual exam question from HashiCorp's Terraform Associate
Question #: 32
Topic #: 1
[All Terraform Associate Questions]

A Terraform provisioner must be nested inside a resource configuration block.

  • A. True
  • B. False
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️
Most provisioners require access to the remote resource via SSH or WinRM, and expect a nested connection block with details about how to connect.
Reference:
https://www.terraform.io/docs/language/resources/provisioners/connection.html

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
quixo
Highly Voted 1 year, 9 months ago
A: True. Example: resource "aws_instance" "web" { # ... provisioner "local-exec" { command = "echo The server's IP address is ${self.private_ip}" } }
upvoted 14 times
...
kiran15789
Highly Voted 11 months, 2 weeks ago
Selected Answer: A
To use a provisioner in Terraform, you must include it as part of a resource configuration block. This is because a provisioner operates on a resource that has been created or updated by Terraform.
upvoted 5 times
...
ravk2321
Most Recent 1 month, 1 week ago
Selected Answer: A
No Standalone Provisioners: Terraform does not support defining provisioners as standalone elements outside of resource blocks. All provisioner configurations must be part of a resource definition because their execution context is tightly coupled with resources. Alternatives to Provisioners: For scenarios where you might think about using provisioners in a more decoupled or independent manner, Terraform suggests other mechanisms. For instance, if the goal is to manage configuration or orchestration that seems beyond the scope of what should be tightly coupled to a single resource's lifecycle, tools like Ansible, Chef, Puppet, or Terraform itself (through resource dependencies and proper module design) are recommended to handle such configurations. These tools can be used in conjunction with Terraform but managed through their mechanisms for orchestration or configuration management, rather than through Terraform provisioners.
upvoted 1 times
...
samimshaikh
3 months, 3 weeks ago
Selected Answer: A
True provisioner should only placed under the resource block PS E:\Terraform> terraform.exe validate ╷ │ Error: Unsupported block type │ │ on main.tf line 34: │ 34: provisioner "local-exec" { │ │ Blocks of type "provisioner" are not expected here. ╵
upvoted 1 times
...
gold4otas
3 months, 3 weeks ago
Selected Answer: B
While it's common to place provisioners inside the resource block for clarity and organization, they can also be defined outside of the block at the same level. Both approaches are valid, and the choice depends on your preference and the organization of your Terraform code. The main point is that provisioners are associated with a specific resource and are configured within the resource block or at the same level in the code.
upvoted 3 times
...
Ramdi1
4 months, 3 weeks ago
Selected Answer: B
the question is stated provisioner must be. the key word being Must. They do not have to be so I voted B
upvoted 3 times
...
Ni33
11 months, 3 weeks ago
Selected Answer: A
A is the correct answer
upvoted 1 times
...
Bluemoon22
12 months ago
A: true. for instance, resource "aws_instance" "testInstance" { ami = "${var.instance_ami}" instance_type = "${var.instance_type}" subnet_id = "${aws_subnet.subnet_public.id}" vpc_security_group_ids = ["${aws_security_group.sg_22.id}"] key_name = "${aws_key_pair.ec2key.key_name}" tags { "Environment" = "${var.environment_tag}" } provisioner "local-exec" { command = "echo ${aws_instance.testInstance.public_ip} >> public_ip.txt" } }
upvoted 2 times
...
SaadKhamis
1 year ago
Selected Answer: B
Examples given in "https://developer.hashicorp.com/terraform/language/resources/provisioners/connection" are not inside a resource configuration block. provisioner "file" { source = "conf/myapp.conf" destination = "/etc/myapp.conf" connection { type = "ssh" user = "root" password = "${var.root_password}" host = "${var.host}" } }
upvoted 1 times
halfway
11 months ago
That's only a code snippet, not the full configuration, though.
upvoted 4 times
...
...
Power123
1 year ago
True. Ans is A
upvoted 1 times
...
vyhak
1 year, 2 months ago
A : True
upvoted 1 times
...
kartikjena31
1 year, 3 months ago
A- True
upvoted 1 times
...
Bere
1 year, 4 months ago
Selected Answer: A
https://developer.hashicorp.com/terraform/language/resources/provisioners/syntax Provisioners are used to execute scripts on a local or remote machine as part of resource creation or destruction. Provisioners can be used to bootstrap a resource, cleanup before destroy, run configuration management, etc. How to use Provisioners Note: Provisioners should only be used as a last resort. For most common situations there are better alternatives. For more information, see the sections above. 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. resource "aws_instance" "web" { # ... provisioner "local-exec" { command = "echo The server's IP address is ${self.private_ip}" } }
upvoted 3 times
...
chimons
1 year, 4 months ago
Selected Answer: A
A. If you need to run provisioners that aren't directly associated with a specific resource, you can associate them with a null_resource.
upvoted 1 times
...
dv00thay
1 year, 4 months ago
Should be B # Terraform Block terraform { required_version = ">= 1.0.0" required_providers { azurerm = { source = "hashicorp/azurerm" version = ">= 2.0" } random = { source = "hashicorp/random" version = ">= 3.0" } } } # Provider Block provider "azurerm" { features {} }
upvoted 1 times
VincentMenzel
1 year, 4 months ago
provisioner != provider
upvoted 6 times
ziancom
1 year, 2 months ago
LOL this is funny
upvoted 2 times
...
...
...
faltu1985
1 year, 6 months ago
Selected Answer: A
I think ans is A
upvoted 4 times
...
RVivek
1 year, 7 months ago
Selected Answer: A
True null_resource is resource type used when you want to run provsioner out side any resorce block provsioner block will not work if it is not included in a resource/null_resource block
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...