terraform-linters / tflint

A Pluggable Terraform Linter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Alphanumeric sort of lists / object keys

wyardley opened this issue · comments

Introduction

Similar to #783, but for list values / object keys

Proposal

When a data structure like a list or object is used, we often like to have the elements sorted alphanumerically. It would be nice to have an optional (and not enabled by default) linter rule to enforce this. Open to suggestions about, for example, if all unquoted values are first or last, but overall, should work like a naïve alphnumeric sort that factors in numeric values

For example:

passes

  bar = {
    groups = [
      var.bar.email,
      var.foo.email,
      "xyz",
    ]
    service_accounts = [data.terraform_remote_state.foo.outputs.xyz, "foo"]
  }
  foo = [0, 1, 2, 3, 100, "foo", "bar"]

generates errors

  bar = {
    groups = [
      var.foo.email,
      "xyz",
      var.bar.email,
    ]
    service_accounts = ["foo", data.terraform_remote_state.foo.outputs.xyz]
  }
  foo = [0, 3, 1, 100, 2, "bar", "foo"]

References