Skip to content

Handle empty terraform plan

Matt Kasa requested to merge mattkasa/handle-empty-terraform-plan into master

What does this MR do?

Fixes a potential bug where an empty (non-op) terraform plan can output a plan cache file from which terraform show will read a null value for resource_changes and pipe it to jq, causing the current convert_report jq script in Terraform.gitlab-ci.yml to error and fail the CI job.

Before:

$ echo '{"some_other_key":[]}' | jq -r '([.resource_changes[].change.actions?]|flatten)|{"create":(map(select(.=="create"))|length),"update":(map(select(.=="update"))|length),"delete":(map(select(.=="delete"))|length)}'
jq: error (at <stdin>:1): Cannot iterate over null (null)

After:

$ echo '{"some_other_key":[]}' | jq -r '([.resource_changes[]?.change.actions?]|flatten)|{"create":(map(select(.=="create"))|length),"update":(map(select(.=="update"))|length),"delete":(map(select(.=="delete"))|length)}'
{
  "create": 0,
  "update": 0,
  "delete": 0
}

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by 🤖 GitLab Bot 🤖

Merge request reports