AlexNabokikh / tfsort

A CLI utility to sort Terraform variables and outputs
Apache License 2.0
138 stars 5 forks source link

Feature Request: Sort locals blocks #42

Open wernerdiers opened 10 months ago

wernerdiers commented 10 months ago

Hello AlexNabokikh!

I believe expanding this tool to also sort locals blocks, would be absolutely awesome.

For example, having the following unsorted block:

locals {
  ecr_repos = {

    pro = {

      just_a_list = [1, 23, 6]

      just_a_string = "yes"

      nginx = {
        repository = "cicd/nginx",
        account = [
          "22222222222"
        ]
      },

      sonarqube = {
        repository = "cicd/sonarqube-service",
        account = [
          "111111111111"
        ]
      },

      jenkins = {
        repository = "cicd/jenkins-docker",
        account = [
          local.account.pro.sandbox
        ]
      },

      spring = {
        repository = "cicd/spring",
        account = [
          var.account
        ]
      },

    }
  }

  pre = {}

  dev = {}

}

Having this output would be brilliant

locals {
  ecr_repos = {
    dev = {}

    pre = {}

    pro = {
      jenkins = {
        repository = "cicd/jenkins-docker",
        account = [
          local.account.pro.sandbox
        ]
      },

      just_a_list = [1, 23, 6]

      just_a_string = "yes"

      sonarqube = {
        repository = "cicd/sonarqube-service",
        account = [
          "111111111111"
        ]
      },
      spring = {
        repository = "cicd/spring",
        account = [
          var.account
        ]
      },
      nginx = {
        repository = "cicd/nginx",
        account = [
          "22222222222"
        ]
      },
    }
  }
}