Interact with Terraform modules Flashcards
Where do you find and explore terraform Modules?
The Terraform Registry makes it simple to find and use modules.
The search query will look at module name, provider, and description
to match your search terms. On the results page, filters can be used
further refine search results.
How do you make sure that modules have stability and compatibility?
By default, only verified modules are shown in search results.
Verified modules are reviewed by HashiCorp to ensure stability and
compatibility.
By using the filters, you can view unverified modules as well.
How do you download any modules?
You need to add any module in the configuration file like below module "consul" { source = "hashicorp/consul/aws" version = "0.1.0" } terraform init command will download and cache any modules referenced by a configuration.
What is the syntax for referencing a registry module?
// // for example module "consul" { source = "hashicorp/consul/aws" version = "0.1.0" }
What is the syntax for referencing a private registry module?
/// // for example module "vpc" { source = "app.terraform.io/example_corp/vpc/aws"} version = "0.9.3" }
The terraform recommends that all modules must follow semantic versioning. Is
this true?
True
What is a Terraform Module?
A Terraform module is a set of Terraform configuration files in a
single directory. Even a simple configuration consisting of a single
directory with one or more .tf files is a module.
Why do we use modules for?
Organize configuration
Encapsulate configuration
Re-use configuration
Provide consistency and ensure best practices
https://learn.hashicorp.com/terraform/modules/modules-overview
How do you call modules in your configuration?
Your configuration can use module blocks to call modules in other
directories.
When Terraform encounters a module block, it loads and processes that
module’s configuration files.
How many ways you can load modules?
Local and remote modules
Modules can either be loaded from the local filesystem, or a remote
source.
Terraform supports a variety of remote sources, including the
Terraform Registry, most version control systems, HTTP URLs, and
Terraform Cloud or Terraform Enterprise private module registries.
What are the best practices for using Modules?
- Start writing your configuration with modules in mind. Even for
modestly complex Terraform configurations managed by a single person,
you’ll find the benefits of using modules outweigh the time it takes
to use them properly. - Use local modules to organize and encapsulate your code. Even if
you aren’t using or publishing remote modules, organizing your
configuration in terms of modules from the beginning will
significantlty reduce the burden of maintaining and updating your
configuration as your infrastructure grows in complexity. - Use the public Terraform Registry to find useful modules. This way
you can more quickly and confidently implement your configuration by
relying on the work of others to implement common infrastructure
scenarios. - Publish and share modules with your team. Most infrastructure is
managed by a team of people, and modules are important way that teams
can work together to create and maintain infrastructure. As mentioned
earlier, you can publish modules either publicly or privately. We
will see how to do this in a future guide in this series.
https://learn.hashicorp.com/terraform/modules/modules-
overview#module-best-practices
What are the different source types for calling modules?
Local paths Terraform Registry GitHub Generic Git, Mercurial repositories Bitbucket HTTP URLsS3 buckets GCS buckets https://www.terraform.io/docs/modules/sources.html
What are the arguments you need for using modules in your configuration?
source and version // example module "consul" { source = "hashicorp/consul/aws" version = "0.1.0" }
How do you set input variables for the modules?
The configuration that calls a module is responsible for setting its
input values, which are passed as arguments in the module block.
Aside from source and version, most of the arguments to a module
block will set variable values.
On the Terraform registry page for the AWS VPC module, you will see
an Inputs tab that describes all of the input variables that module
supports.
How do you access output variables from the modules?
You can access them by referring
module..