scottwinkler / terraform-provider-shell

Terraform provider for executing shell commands and saving output to state file
Mozilla Public License 2.0
279 stars 60 forks source link

throw error on delete #41

Closed scottwinkler closed 4 years ago

scottwinkler commented 4 years ago

Closes issue #40

Originally the delete() method did not throw errors because runCommand() did not return anything sensible as far as errors were concerned (it would throw errors if no state was found, which doesn't really impact the result of the delete, because the resource is being deleted anyways). Now that runCommand() throws errors only when the scripts returns a non zero error condition, it makes sense for delete() to throw that error, like create(), update(), and read() do. Yes, this could cause an awkward condition where you have an error in the delete() script and cannot update it because the delete() keeps failing, but that is a small inconvenience. Generally, users will want to know if a script is returning non-zero error condition and if this means the resource must be manually removed from the state file to proceed, that is an acceptable outcome.

For the following resource:

resource "shell_script" "ex" {
  lifecycle_commands {
    create = ""
    delete = "exit 1"
  }
}

The following error will be thrown:

w10jbiglx1:tmp swinkler$ terraform destroy -force
shell_script.ex: Refreshing state... [id=bqao2mtgrkrksr291p0g]
shell_script.ex: Destroying... [id=bqao2mtgrkrksr291p0g]

Error: Error occured in Command: 'exit 1' Error: 'exit status 1'
 StdOut:

 StdErr: