Terraform fmt

Terraform fmt

Share Everywhere

Table of contents

Command: fmt

The terraform fmt command is used to rewrite Terraform configuration files to a canonical format and style. This command applies a subset of the Terraform language style conventions, along with other minor adjustments for readability.

Usage

Command:

terraform fmt [options] [DIR]

By default, fmt scans the current directory for configuration files. If the dir argument is provided then it will scan that given directory instead. If dir is a single dash (-) then fmt will read from standard input (STDIN).

The command-line flags are all optional.

1/ Check if your code folder has been formatted:

/usr/local/src/terraform/terraform_0.12 fmt -check terraform/

Terraform will list all the files that fmt command make changes. Note that -check flag is optional

Note:

If your folder contain subfolder, you need to use -recursive option:

/usr/local/src/terraform/terraform_0.12 fmt -recursive terraform/

2/ Compare changes to the original file:

/usr/local/src/terraform/terraform_0.12 fmt -diff terraform/

Your changes will be listed in the console

3/ What if your folder has been formatted?

Exit status will be 0 if all input is properly formatted

In addition to diff by fmt with -diff option, you can use git diff command to see the changes compared to previous version in GitLab

Bạn thấy bài viết này như thế nào?
15 reactions

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Bài viết liên quan

Khám phá FinOps

Khám phá FinOps - công nghệ đám mây

Nhiều doanh nghiệp ngày nay lựa chọn chuyển sang công nghệ đám mây với hi vọng đạt được lợi thế cạnh tranh so với đối thủ nhờ tiềm năng về hiệu quả cao và tiết kiệm chi phí hơn của công nghệ này.
Microservices Roadmap

Microservices Roadmap

- Kafka, RabbitMQ, Amazon SQS: Efficient and reliable message brokers for seamless communication between microservices.
The Data Analyst Roadmap

The Data Analyst Roadmap

**Database Knowledge**: Gain proficiency in working with databases like MySQL, PostgreSQL, or MongoDB.
Architectural patterns in software design

Architectural patterns in software design

Choose the architecture that aligns with your application's unique needs and goals. Each pattern offers a tailored approach to elevate your software system!
Exploring the Technological Marvel Behind Netflix

Exploring the Technological Marvel Behind Netflix

Ever wondered about the tech wizardry that powers your binge-watching adventures on Netflix?