Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

fmt subcommand includes recursive flag even on older versions #90

Closed
FacetGraph opened this issue Nov 1, 2019 · 6 comments · Fixed by #91
Closed

fmt subcommand includes recursive flag even on older versions #90

FacetGraph opened this issue Nov 1, 2019 · 6 comments · Fixed by #91

Comments

@FacetGraph
Copy link

FacetGraph commented Nov 1, 2019

I am trying to run fmt with terraform 0.11.7 but keep getting the usage method and the fmt command fails. I added the TF_LOG: 'trace' option to the env vars and found this.

2019/11/01 15:55:11 [INFO] CLI command args: []string{"fmt", "-check=true", "-list=true", "-check", "-write=false", "-list", "-recursive"}
flag provided but not defined: -recursive
Usage: terraform fmt [options] [DIR]

	Rewrites all Terraform configuration files to a canonical format.

	If DIR is not specified then the current working directory will be used.
	If DIR is "-" then content will be read from STDIN.

Options:

  -list=true       List files whose formatting differs (always false if using STDIN)

  -write=true      Write result to source file instead of STDOUT (always false if using STDIN or -check)

  -diff=false      Display diffs of formatting changes

  -check=false     Check if the input is formatted. Exit status will be 0 if all input is properly formatted and non-zero otherwise.
2019/11/01 15:55:11 [DEBUG] plugin: waiting for all plugin processes to complete...

##[error]Docker run failed with exit code 1

This is my code block

      - name: 'Terraform Format'                                            
        uses: hashicorp/terraform-github-actions@master                     
        with:                                                               
          tf_actions_version: 0.11.7                                        
          tf_actions_subcommand: 'fmt'                                      
          tf_actions_working_dir: 'infrastructure'                          
          tf_actions_comment: false                                         
        env:                                                                                                   
          TF_CLI_ARGS: '-check=true -list=true'                             
          TF_LOG: 'TRACE'
@sudomateo
Copy link
Contributor

I see here that the -recursive flag was introduced in commit b966ff2.

It seems that Terraform 0.11.x automatically recurses into directories. In Terraform 0.12.x that behavior was placed behind the -recursive flag.

I'll see what can be done about this.

@sudomateo
Copy link
Contributor

Should be fixed in v0.5.1.

@FacetGraph
Copy link
Author

Thanks @sudomateo that did fix part of my problem, but I am still getting a bunch of errors. It seems a bunch of arguments are being used as parameters to the fmt command
One example:

2019-11-01T17:33:54.5184743Z 2019/11/01 17:33:54 [INFO] TF_CLI_ARGS value: "-check=true -list=true"
2019-11-01T17:33:54.5185475Z 2019/11/01 17:33:54 [INFO] CLI command args: []string{"fmt", "-check=true", "-list=true", "-check", "-write=false", "-diff", "2019/11/01"}
2019-11-01T17:33:54.5190348Z 2019/11/01 17:33:54 [DEBUG] plugin: waiting for all plugin processes to complete...
2019-11-01T17:33:54.5194608Z �[31mError running fmt: stat 2019/11/01: no such file or directory�[0m�[0m

I also see multiple outputs of the command help listed, the first few show the -check option but then the last time even complains about that argument

2019-11-01T17:33:57.7049723Z Options:
2019-11-01T17:33:57.7049851Z 
2019-11-01T17:33:57.7050268Z   -list=true       List files whose formatting differs (always false if using STDIN)
2019-11-01T17:33:57.7050490Z 
2019-11-01T17:33:57.7059927Z   -write=true      Write result to source file instead of STDOUT (always false if using STDIN or -check)
2019-11-01T17:33:57.7060494Z 
2019-11-01T17:33:57.7061086Z   -diff=false      Display diffs of formatting changes
2019-11-01T17:33:57.7061603Z 
2019-11-01T17:33:57.7062236Z flag provided but not defined: -check)

I have a 1400 line log file of all the failed fmt commands, a bunch running fmt on stat commands of timestamps and other pieces of the log like
2019-11-01T17:33:54.6901932Z �[31mError running fmt: stat [INFO]: no such file or directory�[0m�[0m

Even though it succeeds one time without the -recursive flag, it seems to try the command later on with the flag again

write=false", "-diff", "-recursive"}
2019-11-01T17:33:55.9734881Z flag provided but not defined: -recursive

Another issue I'm having is about the actual fmt command that does succeed and shows a diff of a file. I only see this diff (related to whitespace of a comment) when run from github actions, but running terraform fmt on my local machine shows no fixes needed.

@sudomateo
Copy link
Contributor

@FacetGraph Issue is due to STDERR redirecting into STDOUT by 2>&1. I'll take another crack at this.

@sudomateo
Copy link
Contributor

@FacetGraph This should be resolved in v0.5.2.

@FacetGraph
Copy link
Author

@FacetGraph This should be resolved in v0.5.2.

Thanks this is working for me now in v0.5.2 using terraform 0.11.7

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants