nerdexam
HashiCorp

TA-002-P · Question #253

Which one is the right way to import a local module names consul?

The correct answer is B. module "consul" { source = "./consul"} C. module "consul" { source = "../consul"}. Local modules must be referenced using relative file paths that start with ./ (same directory) or ../ (parent directory). Option B (./consul) sources the module from a subdirectory called consul in the current directory. Option C (../consul) sources it from a sibling directory…

Interact with Terraform modules

Question

Which one is the right way to import a local module names consul?

Options

  • Amodule "consul" { source = "consul"}
  • Bmodule "consul" { source = "./consul"}
  • Cmodule "consul" { source = "../consul"}
  • Dmodule "consul" { source = "module/consul"}

How the community answered

(32 responses)
  • A
    16% (5)
  • B
    75% (24)
  • D
    9% (3)

Explanation

Local modules must be referenced using relative file paths that start with ./ (same directory) or ../ (parent directory). Option B (./consul) sources the module from a subdirectory called consul in the current directory. Option C (../consul) sources it from a sibling directory one level up. Option A (consul with no path prefix) would be interpreted as a Terraform Registry module, not a local path. Option D (module/consul) is also not a valid local path format - local paths must start with ./ or ../.

Topics

#Terraform Modules#Local Modules#Module Source#Relative Paths

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice