boltops-tools / terraspace

Terraspace: The Terraform Framework
https://terraspace.cloud
Apache License 2.0
674 stars 46 forks source link

feat: add support for exit code in terraspace validate command #354

Open to-bar opened 1 month ago

to-bar commented 1 month ago

This is a 🙋‍♂️ feature or enhancement.

Summary

terraform validate sets exit code 1 on failed validation, e.g.:

Error: Reference to undeclared input variable

$ echo $?
1

But terraspace not:

$ terraspace validate epi_cluster
=> terraform validate

│ Error: Reference to undeclared input variable

$ echo $?
0

Context

How to Test

  1. Create a project
  2. Break Terraform code, for example by making a typo in a variable name
  3. Run terraspace validate <stack>
  4. Run echo $? to check exit code
  5. Add to config/app.rb:
    Terraspace.configure do |config|
    config.all.exit_on_fail.validate = true
    end
  6. Run terraspace all validate
  7. Run echo $? to check exit code

Version Changes