Skip to content

Instantly share code, notes, and snippets.

View chilledornaments's full-sized avatar

Mitchell chilledornaments

View GitHub Profile
@yermulnik
yermulnik / tf_vars_sort.awk
Last active February 5, 2025 05:35
Sort Terraform (HCL) file by Resource Block Names using GNU `awk`
#!/usr/bin/env -S awk -f
# https://gist.github.com/yermulnik/7e0cf991962680d406692e1db1b551e6
# Tested with GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.1.0, GNU MP 6.2.1)
# Usage: /path/to/tf_vars_sort.awk < variables.tf | tee sorted_variables.tf
# Note: "chmod +x /path/to/tf_vars_sort.awk" before use
# No licensing; [email protected], 2021-2024
{
# skip blank lines at the beginning of file
if (!resource_type && length($0) == 0) next