From 71ad81a76dbf6cffb946c90110ae23ee57f73945 Mon Sep 17 00:00:00 2001 From: Chad Crawford Date: Tue, 3 Dec 2024 12:47:05 -0500 Subject: [PATCH] add option to customize command with `terraform-command` OpenTofu uses a custom command `tofu` rather than the usual `terraform` command. This adds a `terraform-command` variable to override the default command and enable `tofu` support. --- terraform-mode.el | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/terraform-mode.el b/terraform-mode.el index ac62dea..9476361 100644 --- a/terraform-mode.el +++ b/terraform-mode.el @@ -51,6 +51,11 @@ :type 'boolean :group 'terraform-mode) +(defcustom terraform-command "terraform" + "Command used to invoke terraform" + :type 'string + :group 'terraform-mode) + (defface terraform-resource-type-face '((t :inherit font-lock-type-face)) "Face for resource names." @@ -165,7 +170,7 @@ (interactive) (let ((buf (get-buffer-create "*terraform-fmt*"))) (if (zerop (call-process-region (point-min) (point-max) - "terraform" nil buf nil "fmt" "-no-color" "-")) + terraform-command nil buf nil "fmt" "-no-color" "-")) (let ((point (point)) (window-start (window-start))) (erase-buffer) @@ -183,7 +188,7 @@ (let ((buf (get-buffer-create "*terraform-fmt*"))) (when (use-region-p) (if (zerop (call-process-region (region-beginning) (region-end) - "terraform" nil buf nil "fmt" "-")) + terraform-command nil buf nil "fmt" "-")) (let ((point (region-end)) (window-start (region-beginning))) (delete-region window-start point) @@ -249,7 +254,7 @@ (defun terraform--get-resource-provider-namespace (provider) "Return provider namespace for PROVIDER." - (let ((provider-info (shell-command-to-string "terraform providers"))) + (let ((provider-info (shell-command-to-string (concat terraform-command "providers")))) (with-temp-buffer (insert provider-info) (goto-char (point-min))