Function: terraform-format-buffer
terraform-format-buffer is an interactive and natively compiled
function defined in terraform-mode.el.
Signature
(terraform-format-buffer)
Documentation
Rewrite current buffer in a canonical format using terraform fmt.
Key Bindings
This command is not in any keymaps.
Source Code
;; Defined in /nix/store/2sgzhgfr3sxpjh5dpyjjiqacrm3016bl-emacs-packages-deps/share/emacs/site-lisp/elpa/terraform-mode-20251115.2210/terraform-mode.el
(defun terraform-format-buffer ()
"Rewrite current buffer in a canonical format using terraform fmt."
(interactive)
(let ((buf (get-buffer-create "*terraform-fmt*")))
(if (zerop (call-process-region (point-min) (point-max)
terraform-command nil buf nil "fmt" "-no-color" "-"))
(let ((point (point))
(window-start (window-start)))
(erase-buffer)
(insert-buffer-substring buf)
(when (/= terraform-indent-level 2)
(indent-region (point-min) (point-max)))
(goto-char point)
(set-window-start nil window-start))
(message "terraform fmt: %s" (with-current-buffer buf (buffer-string))))
(kill-buffer buf)))