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.
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
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.
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.
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.
╵
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.
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}"
}
}
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
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.
quixo
Highly Voted 1 year, 9 months agokiran15789
Highly Voted 11 months, 2 weeks agoravk2321
Most Recent 1 month, 1 week agosamimshaikh
3 months, 3 weeks agogold4otas
3 months, 3 weeks agoRamdi1
4 months, 3 weeks agoNi33
11 months, 3 weeks agoBluemoon22
12 months agoSaadKhamis
1 year agohalfway
11 months agoPower123
1 year agovyhak
1 year, 2 months agokartikjena31
1 year, 3 months agoBere
1 year, 4 months agochimons
1 year, 4 months agodv00thay
1 year, 4 months agoVincentMenzel
1 year, 4 months agoziancom
1 year, 2 months agofaltu1985
1 year, 6 months agoRVivek
1 year, 7 months ago