Skip encrypted files when running terraform fmt

I am trying to make a CI in GitHub Actions that runs terraform fmt on changed files.

However, since I am using git-crypt to encrypt some files when committed to git, the process fails with:

 Error: Invalid character
│   on line 1:
│    1: GITCRYPT]
│ This character is not used within the language.

Is there a way to overcome this limitation?

$ terraform fmt --help
Usage: terraform [global options] fmt [options] [target...]

  Rewrites all Terraform configuration files to a canonical format. Both
  configuration files (.tf) and variables files (.tfvars) are updated.
  JSON files (.tf.json or .tfvars.json) are not modified.

  By default, fmt scans the current directory for configuration files. If you
  provide a directory for the target argument, then fmt will scan that
  directory instead. If you provide a file, then fmt will process just that
  file. If you provide a single dash ("-"), then fmt will read from standard
  input (STDIN).

Calculate a list of non-encrypted .tf files, and tell terraform fmt to only format those.

1 Like