Interact with Terraform modules Flashcards

1
Q

Where do you find and explore terraform Modules?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you make sure that modules have stability and compatibility?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you download any modules?

A
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the syntax for referencing a registry module?

A
//
// for example
module "consul" {
source = "hashicorp/consul/aws"
version = "0.1.0"
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the syntax for referencing a private registry module?

A
///
// for example
module "vpc" {
source = "app.terraform.io/example_corp/vpc/aws"}
version = "0.9.3"
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The terraform recommends that all modules must follow semantic versioning. Is
this true?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a Terraform Module?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why do we use modules for?

A

Organize configuration
Encapsulate configuration
Re-use configuration
Provide consistency and ensure best practices

https://learn.hashicorp.com/terraform/modules/modules-overview

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you call modules in your configuration?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How many ways you can load modules?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the best practices for using Modules?

A
  1. 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.
  2. 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.
  3. 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.
  4. 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the different source types for calling modules?

A
Local paths
Terraform Registry
GitHub
Generic Git, Mercurial repositories
Bitbucket
HTTP URLsS3 buckets
GCS buckets
https://www.terraform.io/docs/modules/sources.html
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the arguments you need for using modules in your configuration?

A
source and version
// example
module "consul" {
source = "hashicorp/consul/aws"
version = "0.1.0"
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you set input variables for the modules?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you access output variables from the modules?

A

You can access them by referring

module..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Where do you put output variables in the configuration?

A

Module outputs are usually either passed to other parts of your
configuration, or defined as outputs in your root module. You will
see both uses in this guide.
Inside your configuration’s directory, outputs.tf will need to
contain

17
Q

How do you pass input variables in the configuration?

A
You can define variables.tf in the root folder
variable "vpc_name" {
description = "Name of VPC"
type
= string
default
= "example-vpc"
}
Then you can access these varibles in the configuration like thismodule "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.21.0"
name = var.vpc_name
cidr = var.vpc_cidr
azs
= var.vpc_azs
private_subnets = var.vpc_private_subnets
public_subnets = var.vpc_public_subnets
enable_nat_gateway = var.vpc_enable_nat_gateway
}
tags = var.vpc_tags
}
18
Q

What is the child module?

A
A module that is called by another configuration is sometimes
referred to as a "child module" of that configuration.
19
Q

When you use local modules you don’t have to do the command init or get every time there is a change in the local module. why?

A

When installing a local module, Terraform will instead refer directly
to the source directory.
Because of this, Terraform will automatically notice changes to local
modules without having to re-run terraform init or terraform get.

20
Q

When you use remote modules what should you do if there is a change in the module?

A

When installing a remote module, Terraform will download it into the
.terraform directory in your configuration’s root directory.
You should initialize with terraform init

21
Q

A simple configuration consisting of a single directory with one or more .tf files is a module. Is this true?

A

True

22
Q

When using a new module for the first time, you must run either terraform init or terraform get to install the module. Is this true?

A

True

23
Q

When installing the modules and where does the terraform save these modules?

A
.terraform/modules
// Example
.terraform/modules
├── ec2_instances
│
└── terraform-aws-modules-terraform-aws-ec2-instance-ed6dcd9
├── modules.json
└── vpc
└── terraform-aws-modules-terraform-aws-vpc-241
24
Q

What is the required argument for the module?

A

source
All modules require a source argument, which is a meta-argument
defined by Terraform CLI. Its value is either the path to a local
directory of the module’s configuration files, or a remote module
source that Terraform should download and use. This value must be a
literal string with no template sequences; arbitrary expressions are
not allowed. For more information on possible values for this
argument, see Module Sources.

25
Q

What are the other optional meta-arguments along with the source when defining modules

A
version - (Optional) A version constraint string that specifies which
versions of the referenced module are acceptable. The newest version
matching the constraint will be used. version is supported only for
modules retrieved from module registries.
providers - (Optional) A map whose keys are provider configuration
names that are expected by child module and whose values are
corresponding provider names in the calling module. This allows
provider configurations to be passed explicitly to child modules. If
not specified, the child module inherits all of the default (un-
aliased) provider configurations from the calling module.