Function: terraform--get-resource-provider-source

terraform--get-resource-provider-source is a natively compiled function defined in terraform-mode.el.

Signature

(terraform--get-resource-provider-source PROVIDER &optional DIR)

Documentation

Return Terraform provider source for PROVIDER located in DIR.

Terraform provider source is searched in required_provider declaration in current buffer or in other Terraform files located in the same directory of the file of current buffer. If still not found, the provider source is searched by running command terraform providers. The DIR parameter is optional and used only for tests.

Source Code

;; Defined in /nix/store/2sgzhgfr3sxpjh5dpyjjiqacrm3016bl-emacs-packages-deps/share/emacs/site-lisp/elpa/terraform-mode-20251115.2210/terraform-mode.el
(defun terraform--get-resource-provider-source (provider &optional dir)
  "Return Terraform provider source for PROVIDER located in DIR.
Terraform provider source is searched in `required_provider' declaration
in current buffer or in other Terraform files located in the same directory
of the file of current buffer.  If still not found, the provider source is
searched by running command `terraform providers'.
The DIR parameter is optional and used only for tests."
  (goto-char (point-min))
  ;; find current directory if it's not specified in arguments
  (if (and (not dir) buffer-file-name) (setq dir (file-name-directory buffer-file-name)))
  (let (tf-files
        ;; try to find provider source in current buffer
        (provider-source (terraform--get-resource-provider-source-in-buffer provider)))
    ;; check if terraform provider-source was found
    (when (and (= (length provider-source) 0) dir)
      ;; find all terraform files of this project. One of them
      ;; should contain required_provider declaration
      (setq tf-files (directory-files dir nil "^[[:alnum:][:blank:]_.-]+\\.tf$")))
    ;; iterate on terraform files until a provider source is found
    (while (and (= (length provider-source) 0) tf-files)
      (with-temp-buffer
        (let* ((file (pop tf-files))
               (file-path (if dir (concat dir "/" file) file)))
          (insert-file-contents file-path)
          ;; look for provider source in a terraform file
          (setq provider-source (terraform--get-resource-provider-source-in-buffer provider)))))
    provider-source))