Modules Flashcards
(34 cards)
What is a Terraform module?
A Terraform module is a container for multiple resources that are used together in a configuration. It allows you to organize and encapsulate your infrastructure code, making it reusable and easier to manage.
What is the root module in Terraform?
The root module is the main working directory where Terraform commands are run. It consists of the resources defined in the .tf
files in that directory.
What are child modules in Terraform?
Child modules are modules that are called by another module (usually the root module). They allow you to include their resources into the configuration and can be called multiple times within the same configuration or in separate configurations.
What are some problems that modules help solve in Terraform configurations?
Modules help address issues such as difficulty in understanding and navigating complex configurations, risk of unintended consequences when updating configurations, duplication of similar configuration blocks, challenges in sharing configurations between projects and teams, and the need for engineers to have deep Terraform expertise to modify configurations.
How do modules help in organizing Terraform configurations?
Modules make it easier to navigate, understand, and update configurations by keeping related parts together, organizing your configuration into logical components.
How do modules provide encapsulation in Terraform?
Modules encapsulate configuration into distinct logical components, preventing unintended consequences and reducing the chances of errors like using the same name for different resources.
How do modules facilitate re-use of Terraform configurations?
Modules allow you to re-use configuration written by yourself or others, saving time and reducing errors by implementing common infrastructure scenarios.
What is the recommended naming convention for Terraform modules intended for public sharing?
Modules should be named following the convention terraform-<PROVIDER>-<NAME>
, especially when publishing to the Terraform Registry.
What is the typical file structure of a Terraform module?
A typical module includes files like LICENSE
, README.md
, main.tf
, variables.tf
, and outputs.tf
. None of these files are required or have special meaning to Terraform, but they serve purposes such as documentation and defining variables and outputs.
What is the purpose of the LICENSE
file in a Terraform module?
The LICENSE
file contains the license under which the module is distributed, informing users of the terms of use. Terraform itself does not use this file.
What is the purpose of the README.md
file in a Terraform module?
The README.md
file provides documentation about the module, explaining its purpose and usage. This helps users understand what the module does and how to use it.
What is the purpose of the main.tf
file in a Terraform module?
The main.tf
file contains the primary configuration for the module, defining the resources that the module will manage.
What is the purpose of the variables.tf
file in a Terraform module?
The variables.tf
file defines the input variables for the module, allowing users to customize the module’s behavior.
What is the purpose of the outputs.tf
file in a Terraform module?
The outputs.tf
file defines the output values of the module, which can be used to expose information about the resources managed by the module to the calling module.
Why is it recommended to avoid including provider
blocks within modules?
Including provider
blocks within modules can lead to unexpected behaviors. Instead, providers should be configured in the root module and passed to child modules to ensure consistent provider configurations.
How can you call a module in Terraform?
You can call a module using a module
block in your configuration, specifying the source
argument to indicate the module’s location and providing values for the module’s input variables.
What are some best practices when creating Terraform modules?
Best practices include starting with modules in mind, using local modules to organize and encapsulate code, using the public Terraform Registry to find useful modules, and publishing and sharing modules with your team.
How do modules contribute to consistency and best practices in Terraform configurations?
Modules help provide consistency by organizing configurations in a standardized way and ensuring that best practices are applied across all configurations.
How do modules enable self-service workflows in Terraform?
Modules make configurations easier for other teams to use, enabling self-service workflows where teams without deep Terraform expertise can provision infrastructure that complies with organizational standards and policies.
What is the Terraform Registry?
The Terraform Registry is a public repository that hosts a broad collection of publicly available Terraform modules for configuring many kinds of common infrastructure. These modules are free to use, and Terraform can download them automatically if specified in a module call block.
What is the benefit of publishing modules to the Terraform Registry?
Publishing modules to the Terraform Registry allows others to find and re-use your modules, promoting sharing and collaboration within the Terraform community.
What is the difference between local and remote modules in Terraform?
Local modules are stored on the local filesystem, while remote modules are stored in remote sources like the Terraform Registry, version control systems, or HTTP URLs. Terraform can load modules from both local and remote sources.
How can you specify the version of a module in Terraform?
For modules from a registry, you can use the version
argument in the module
block to specify the module version. This helps ensure that Terraform uses the correct version of the module.
Why is it important to specify the version of a module when using it in Terraform?
Specifying the module version helps avoid unexpected or unwanted changes by ensuring that Terraform uses the intended version of the module, rather than automatically using the latest version, which may have breaking changes.