AlexNabokikh / tfsort

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

`tfsort outputs.tf` deletes output that is not in order. #32

Closed benniemosher closed 1 year ago

benniemosher commented 1 year ago

If I have an outputs.tf file that looks like the below:

output "network" {
  description = "The network module."
  value       = module.account.network
}

output "hardened-image-id" {
  description = "The AMI ID of the hardened image."
  value       = data.aws_ami.hardened.id
}

output "private_key_name" {
  description = "The name of the private key made to share."
  value       = module.account.private_key_name
}

and I run tfsort outputs.tf, it deletes the output that is out of place. It then makes my outputs.tf file look like the following:

output "network" {
  description = "The network module."
  value       = module.account.network
}

output "private_key_name" {
  description = "The name of the private key made to share."
  value       = module.account.private_key_name
}

Also, is there anyway to recursively look for variables.tf files in subdirectories and sort them with one command run? Something like tfsort --recursive variables.tf?

Can this be fixed to work properly? Thank you in advance for any help you can provide!

AlexNabokikh commented 1 year ago

Hi @benniemosher, Thanks a lot for reporting the problem. I am at a limited capacity right now, but I will have a look and fix the problem in the upcoming weeks.