Skip to content

Commit

Permalink
fix(tf): disable global fatal setting temporary in terraform plan
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianGottinger committed May 17, 2024
1 parent 3cf8b61 commit c4dfc21
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/recipes/terraform/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/conplementag/cops-hq/v2/internal/file_handling"
"github.com/conplementag/cops-hq/v2/internal/slice_helpers"
"github.com/conplementag/cops-hq/v2/pkg/commands"
"github.com/conplementag/cops-hq/v2/pkg/error_handling"
"github.com/conplementag/cops-hq/v2/pkg/recipes/terraform/file_paths"
"github.com/sirupsen/logrus"
"os"
Expand Down Expand Up @@ -436,6 +437,14 @@ func (tf *terraformWrapper) plan(isDestroy bool) (string, error) {
return "", internal.ReturnErrorOrPanic(err)
}

// disable global setting panic on error to allow terraform plan with
// detailed-exitcode for plan analyzing
panicOnError := error_handling.PanicOnAnyError
error_handling.PanicOnAnyError = false
defer func(panicOnError bool) {
error_handling.PanicOnAnyError = panicOnError
}(panicOnError)

plaintextPlanOutput, err := tf.executor.Execute(tfCommand)
// terraform plan with -detailed-exitcode results in the following exit codes
// 0 = Succeeded with empty diff (no changes)
Expand Down

0 comments on commit c4dfc21

Please sign in to comment.