Subdomain 1.1: Initialize a configuration using terraform init and its options
1.What is the primary purpose of the `-from-module` option when executing the `terraform init` command?
- A.It initializes only a specific child module within the current configuration, ignoring the root module.
- B.It copies the contents of the specified source module into the target empty working directory before initialization.
- C.It downloads the specified module and outputs its variables and outputs to the console for inspection.
- D.It bypasses the root module and executes a plan directly against the specified child module.
Show answer & explanation
Correct answer: B — It copies the contents of the specified source module into the target empty working directory before initialization.
- A. Incorrect. The `-from-module` option does not perform partial initialization of a child module within an existing configuration. Instead, it is used to populate an empty directory with a module to serve as the new root configuration.
- B. Correct. The `-from-module=SOURCE` option tells Terraform to copy the contents of the specified source module into the current (usually empty) working directory before proceeding with the initialization. This effectively promotes the module to be the root module of the current project.
- C. Incorrect. This option copies the actual source code and files of the module into the target directory; it does not simply download the module for inspection or display its variables and outputs in the console.
- D. Incorrect. The `-from-module` flag is part of the initialization phase, not the execution phase. It does not bypass the root module to run plans or applies; it creates the root module structure from a source module.