Skip to content

Commit 5bdd734

Browse files
authored
add option to customize command with terraform-command (#74)
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.
1 parent abfc10f commit 5bdd734

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

terraform-mode.el

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
:type 'boolean
5252
:group 'terraform-mode)
5353

54+
(defcustom terraform-command "terraform"
55+
"Command used to invoke terraform"
56+
:type 'string
57+
:group 'terraform-mode)
58+
5459
(defface terraform-resource-type-face
5560
'((t :inherit font-lock-type-face))
5661
"Face for resource names."
@@ -165,7 +170,7 @@
165170
(interactive)
166171
(let ((buf (get-buffer-create "*terraform-fmt*")))
167172
(if (zerop (call-process-region (point-min) (point-max)
168-
"terraform" nil buf nil "fmt" "-no-color" "-"))
173+
terraform-command nil buf nil "fmt" "-no-color" "-"))
169174
(let ((point (point))
170175
(window-start (window-start)))
171176
(erase-buffer)
@@ -183,7 +188,7 @@
183188
(let ((buf (get-buffer-create "*terraform-fmt*")))
184189
(when (use-region-p)
185190
(if (zerop (call-process-region (region-beginning) (region-end)
186-
"terraform" nil buf nil "fmt" "-"))
191+
terraform-command nil buf nil "fmt" "-"))
187192
(let ((point (region-end))
188193
(window-start (region-beginning)))
189194
(delete-region window-start point)
@@ -249,7 +254,7 @@
249254

250255
(defun terraform--get-resource-provider-namespace (provider)
251256
"Return provider namespace for PROVIDER."
252-
(let ((provider-info (shell-command-to-string "terraform providers")))
257+
(let ((provider-info (shell-command-to-string (concat terraform-command " providers"))))
253258
(with-temp-buffer
254259
(insert provider-info)
255260
(goto-char (point-min))

0 commit comments

Comments
 (0)