Skip to content

Commit

Permalink
Document the tfstacks fmt command (#36202)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkoron007 authored Dec 13, 2024
1 parent 4484658 commit 7b2d7d0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
31 changes: 14 additions & 17 deletions website/docs/cli/commands/fmt.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,17 @@ and the generated files.

Usage: `terraform fmt [options] [target...]`

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).


The command-line flags are all optional. If no flag is given, `fmt` rewrites
the Terraform configuration files to a canonical format and style.

The following flags are available:

* `-list=false` - Don't list the files containing formatting inconsistencies.
* `-write=false` - Don't overwrite the input files. (This is implied by `-check` or when the input is STDIN.)
* `-diff` - Display diffs of formatting changes.
* `-check` - Check if the input is formatted. Exit status will be 0 if all input is properly formatted. If not, exit status will be non-zero and the command will output a list of filenames whose files are not properly formatted.
* `-recursive` - Also process files in subdirectories. By default, only the given directory (or current directory) is processed.
By default, the `terraform fmt` command scans your current directory for configuration files. You can also provide a `target` argument to tell `terraform fmt` to scan:
* A directory
* A specific file
* Standard input by supplying a single dash (`-`).

The `terraform fmt` command accepts the following arguments.

| Flag | Description | Required |
| :---- | :---- | :---- |
| `-list=false` | Prevents the command from listing the files containing formatting inconsistencies. | Optional |
| `-diff` | Displays the diffs of formatting changes. | Optional |
| `-write=false` | Prevents the command from overwriting files. This behavior is implied by the `-check` flag or if the input is from `STDIN`. | Optional |
| `-check` | Checks if the input is formatted. The exit status is `0` if the command's input is properly formatted. Otherwise, the exit status is non-zero, and the command outputs a list of improperly formatted file names. | Optional |
| `-recursive` | Processes files in subdirectories in addition to the current directory. By default, the command only processes the specified, or current, directory. | Optional |
36 changes: 32 additions & 4 deletions website/docs/language/stacks/reference/tfstacks-cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ $ sudo yum -y install terraform-stacks-cli

The `terraform-stacks-cli` supports the following four commands:

* `tfstacks init`
* `tfstacks validate`
* `tfstacks providers lock [-platform=os_arch]`
* `tfstacks plan -organization=org_name -stack=stack_id -deployment=deployment_name [-hostname=hostname]`
* [`tfstacks init`](#tfstacks-init-command)
* [`tfstacks validate`](#tfstacks-validate-command)
* [`tfstacks providers lock [-platform=os_arch]`](#tfstacks-providers-lock-command)
* [`tfstacks plan -organization=org_name -stack=stack_id -deployment=deployment_name [-hostname=hostname]`](#tfstacks-plan-command)
* [`tfstacks fmt`](#tfstacks-fmt-command)

Each Stack command supports [global options](#global-options).

Expand Down Expand Up @@ -128,6 +129,33 @@ The `tfstacks plan` accepts the following arguments.
| `-deployment=` | Set the `deployment` flag to the deployment name you want to perform this plan in. The deployment name must match one of the deployment names you specified in the `tfdeploy.hcl` file.<br/><br/>Alternatively, you can set an environment variable named `TFSTACKS_DEPLOYMENT` with the same value. | Required |
| `-hostname=` | You can set the `hostname` flag to the hostname of the HCP Terraform instance you want to perform this plan in. The default value is `app.terraform.io`.<br/><br/>Alternatively, you can set an environment variable named `TFSTACKS_HOSTNAME` with the same value. | Optional |

### `tfstacks fmt` command

-> The `tfstacks fmt` command requires v0.6.0 of the `terraform-stacks-cli` or higher. Refer to [installation](#installation) for instructions.

The `tfstacks fmt` command scans your current directory for Stack configuration files, `.tfstack.hcl` and `.tfdeploy.hcl`, and formats those files to match Terraform's canonical format and style.

```shell-session
$ tfstacks fmt [options] [target]
```

By default, the `tfstacks fmt` command scans your current directory for configuration files. You can also provide a `target` argument to tell `tfstacks fmt` to scan:
* A directory
* A specific file
* Standard input by supplying a single dash (`-`).

The `tfstacks fmt` command accepts the following arguments.

| Flag | Description | Required |
| :---- | :---- | :---- |
| `-list=false` | Prevents the command from listing the files containing formatting inconsistencies. | Optional |
| `-diff` | Displays the diffs of formatting changes. | Optional |
| `-write=false` | Prevents the command from overwriting files. This behavior is implied by the `-check` flag or if the input is from `STDIN`. | Optional |
| `-check` | Checks if the input is formatted. The exit status is `0` if the command's input is properly formatted. Otherwise, the exit status is non-zero, and the command outputs a list of improperly formatted file names. | Optional |
| `-recursive` | Processes files in subdirectories in addition to the current directory. By default, only the specified directory is processed. | Optional |

The `tfstacks fmt` command uses the same formatting rules as the Terraform CLI's `terraform fmt` command. Refer to [`terraform fmt`](/terraform/cli/commands/fmt) for more information on formatting rules.

## Global options

You can apply the following global options to any `tfstacks` command:
Expand Down

0 comments on commit 7b2d7d0

Please sign in to comment.