TA-002-P · Question #184
By default, provisioners that fail will also cause the Terraform apply itself to error. How can you change this default behavior within a provisioner?
The correct answer is C. provisioner "local-exec" { on_failure = "continue" }. Setting on_failure = "continue" inside a provisioner block tells Terraform to log the provisioner error and proceed with the apply rather than treating the failure as a fatal error.
Question
By default, provisioners that fail will also cause the Terraform apply itself to error. How can you change this default behavior within a provisioner?
Options
- Aprovisioner "local-exec" { on_failure = "next" }
- Bprovisioner "local-exec" { when = "failure" terraform apply }
- Cprovisioner "local-exec" { on_failure = "continue" }
- Dprovisioner "local-exec" { on_failure = continue }
How the community answered
(17 responses)- B6% (1)
- C88% (15)
- D6% (1)
Why each option
Setting on_failure = "continue" inside a provisioner block tells Terraform to log the provisioner error and proceed with the apply rather than treating the failure as a fatal error.
"next" is not a valid value for the on_failure argument; the only accepted string values are "fail" and "continue".
There is no when = "failure" construct in Terraform; the when argument accepts only "create" or "destroy" to control the lifecycle stage at which a provisioner runs.
The on_failure meta-argument accepts either "fail" (the default, which causes apply to halt and error) or "continue" (which logs the provisioner's error output and allows the apply to finish successfully), giving operators control over whether provisioner failures are blocking.
This syntax is missing the required double quotes around continue; on_failure = continue without quotes is an HCL syntax error and Terraform will reject the configuration.
Concept tested: Terraform provisioner on_failure argument for error handling
Source: https://developer.hashicorp.com/terraform/language/resources/provisioners/syntax
Topics
Community Discussion
No community discussion yet for this question.