From 3537134c23ad0337340b3e0b31baea8ef06c5981 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Tue, 16 Jul 2024 14:24:16 -0400 Subject: [PATCH] Add Terraform console functionality to Emacs. This commit adds the ability to run a Terraform console at a specified path in a comint buffer, making it easier to interactively explore and manage Terraform state. --- emacs/.emacs.d/config/init-terraform.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/emacs/.emacs.d/config/init-terraform.el b/emacs/.emacs.d/config/init-terraform.el index 2e489f8..cb8f30f 100644 --- a/emacs/.emacs.d/config/init-terraform.el +++ b/emacs/.emacs.d/config/init-terraform.el @@ -61,6 +61,23 @@ (let ((default-directory dir)) (apply oldfn args)))) + (defvar terraform-default-aws-profile "default" + "The default AWS profile to use when running terraform commands.") + + (defun terraform-console (path) + "Run a Terraform console at `path' in a comint buffer." + (interactive (list (read-directory-name "Path: " (find-terraform-root)))) + (let* ((process-environment (cons (format "AWS_PROFILE=%s" terraform-default-aws-profile) + process-environment)) + (default-directory (expand-file-name path)) + (program "terraform") + (switches (list "console")) + (expected-buf-name (apply #'make-comint program program nil switches))) + (comint-run "terraform" (list "console")) + (with-current-buffer expected-buf-name + (setq-local comint-prompt-read-only t + comint-process-echoes t)))) + (advice-add 'terraform--get-resource-provider-namespace :around #'terraform-provider-ns-advice)) (defun terraform-jump-to-plan ()