Skip to content

terraform validate does not check for valid JSON in actions #181

@asaba-hashi

Description

@asaba-hashi

#180 removed validations for JSON in the actions block of rules. The purpose of those validation methods is to be enable checking that those strings are valid JSON as required by the API at the lighter weight terraform validate, rather than relying on a plan or a failed apply. The map version was meant for scope_filters, so not being referenced was a bug.

With an example:

resource "jupiterone_rule" "test" {
  <snip>

  operations = [
    {
      when = jsonencode({
        "type" : "FILTER",
        "specVersion" : 1,
        "condition" : [
          "AND",
          [
            "queries.query0.total",
            "<",
            1000
          ]
        ]
      }),
      actions = [
        jsonencode({
          "targetValue" : "INFO",
          "type" : "SET_PROPERTY",
          "targetProperty" : "alertLevel"
        }),
        jsonencode({
          "type" : "CREATE_ALERT"
        }),
        "{not-a-valid-json:}"
      ]
    }
  ]
}

Prior to this change, terraform validate would fail with:
``
│ Attribute operations[0].actions string value must be valid JSON, got:
│ ["{"targetProperty":"alertLevel","targetValue":"INFO","type":"SET_PROPERTY"}","{"type":"CREATE_ALERT"}","{not-a-valid-json:}"]


After this change, `terraform validate` will pass, and may not fail until an `apply`, which is not a user-friendly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions