Skip to content

Commit

Permalink
feat(terraform): plan analysis on output variable change only
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiondic committed Apr 18, 2024
1 parent 8ba020d commit af2abe2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/recipes/terraform/plan_analyzer/plan_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,17 @@ func (pa *planAnalyzer) isPlanDirty(checkForDestroy bool) (bool, error) {
// in the context of terraform plans, true is here a much better default value to prevent accidental changes due to bugs in this code
var isDirty = true

// NOTE: this whole code will be refactored to the new terraform binary return values
if strings.Contains(string(contents), "Your infrastructure matches the configuration.") &&
strings.Contains(string(contents), "found no differences, so no changes are needed") {
isDirty = false
} else if strings.Contains(string(contents), "Terraform will perform the following actions") &&
strings.Contains(string(contents), "To perform exactly these actions, run the following command to apply") {
isDirty = true
} else if strings.Contains(string(contents), "You can apply this plan to save these new output values to the Terraform") &&
strings.Contains(string(contents), "without changing any real infrastructure") {
// this case handles terraform changes in output variables only
isDirty = true
} else {
return true, errors.New("[CopsHq][PlanAnalyzer] could not determine if the plan was dirty or not, because expected strings for " +
"both checks were not found in the plan text file")
Expand Down

0 comments on commit af2abe2

Please sign in to comment.