Skip to content

Terraform + Tofu Plugins Bug: terraform fmt + tofu fmt erroneously run against **.tf.json filesΒ #941

Closed
@Gowiem

Description

Info

When committing / changing our backend.tf.json file (which is a standard file in both tofu + terraform), both plugins are trying to run their fmt command against those files. This results in the following error:

trunk_cli_version: 1.22.8
title: terraform exited with exit_code=2
report:
  - terraform exited with exit_code=2
  - linter:
      command: |
        /<MY_USER_PATH>/.cache/trunk/tools/terraform/1.1.0-6bc9ed0aa441bfb0bf13ee36e04a2bde/terraform fmt -no-color -
      stdin_path: |
        /private/var/folders/7l/fp_bz3gx6yzg24hw08ww9vp00000gn/T/trunk-501/GlML4Y/root-modules/kms/backend.tf.json
      run_from: /private/var/folders/7l/fp_bz3gx6yzg24hw08ww9vp00000gn/T/trunk-501/GlML4Y
      timeout: 10m
      rerun: (cd /private/var/folders/7l/fp_bz3gx6yzg24hw08ww9vp00000gn/T/trunk-501/GlML4Y; cat /private/var/folders/7l/fp_bz3gx6yzg24hw08ww9vp00000gn/T/trunk-501/GlML4Y/root-modules/kms/backend.tf.json | env -i PATH=/<MY_USER_PATH>/.cache/trunk/tools/terraform/1.1.0-6bc9ed0aa441bfb0bf13ee36e04a2bde:/<MY_USER_PATH>/.cache/trunk/tools/terraform/1.1.0-6bc9ed0aa441bfb0bf13ee36e04a2bde HOME=/<MY_USER_PATH> /<MY_USER_PATH>/.cache/trunk/tools/terraform/1.1.0-6bc9ed0aa441bfb0bf13ee36e04a2bde/terraform fmt -no-color -)
      affects_cache:
        []
      direct_configs:
        []
      exit_status: exited
      exit_code: 2
      stdout: (none)
      stderr: |

        Error: Argument or block definition required

          on <stdin> line 1:
           1: {

        An argument or block definition is required here.


    parser: |
      (none)

If you run terraform fmt against that file directly via terraform fmt -no-color backend.tf.json then you get the following:

Error: Only .tf, .tfvars, and .tftest.hcl files can be processed with terraform fmt

This goes to say that trunk should not be trying to run fmt against these ****.tf.json files and this now causing a false error.

We've been using these plugins for a while and this is the first that we're running into this. So we believe something must have changed upstream in trunk check itself?

trunk.yaml

version: 0.1
cli:
  version: 1.22.8
plugins:
  sources:
    - id: trunk
      ref: v1.6.6
      uri: https://github.com/trunk-io/plugins
lint:
  disabled:
    # TODO: Re-enable checkov once the below issue is fixed:
    # https://github.com/bridgecrewio/checkov/issues/6915
    # This is fixed in https://github.com/bridgecrewio/checkov/pull/6918, but that is not released yet.
    - checkov
  enabled:
    - tofu@1.8.7
    - terraform@1.1.0
    - actionlint@1.7.4
    - tfsec@1.28.11
    - trivy@0.58.1
    - trufflehog@3.88.0
    - markdownlint@0.43.0
    - git-diff-check
    - gitleaks@8.21.2
    - prettier@3.4.2
    - tflint@0.54.0
    - yamllint@1.35.1
runtimes:
  enabled:
    - go@1.21.0
    - node@18.20.5
    - python@3.10.8
actions:
  disabled:
    - trunk-announce
  enabled:
    - trunk-cache-prune
    - trunk-check-pre-push
    - trunk-fmt-pre-commit
    - trunk-upgrade-available

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions