Terraform Modules Tutorial Flashcards

1
Q

Modules help organize configuration

A

Modules make it easier to navigate, understand, and update your configuration by keeping related parts of your configuration together.

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

Modules help encapsulate configuration

A

Encapsulation can help prevent unintended consequences, such as a change to one part of your configuration accidentally causing changes to other infrastructure, and reduce the chances of simple errors like using the same name for two different resources.

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

Modules help you reuse configuration

A

Using modules can save time and reduce costly errors by re-using configuration written either by yourself, other members of your team, or other Terraform practitioners who have published modules for you to use.

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

What is a Terraform module

A

a set of Terraform configuration files in a single directory.

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
5
Q

what is a root module

A

When you run Terraform commands directly from a directory, it is considered the root module

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

calling modules

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.

sometimes referred to as a “child module” of that configuration.

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

Module best practices - naming

A

Name your provider terraform-PROVIDER-NAME

You must follow this convention in order to publish to the Terraform Cloud or Terraform Enterprise module registries.

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

Modules Best Practice - always think modules

A

Start writing your configuration with modules in mind.

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

Modules best practice - encapsulation and organization

A

organizing your configuration in terms of modules from the beginning will significantly reduce the burden of maintaining and updating your configuration as your infrastructure grows in complexity.

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

When building a module consider 3 things (best practices)

A

Encapsulation: Group infra that is always deployed together

Privileges: Restrict modules to privilege boundaries. Infra in module should belong to one group.

Volatility: Separate long-lived infrastructure from short-lived.

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

Guidelines for MVP (Minimum Viable Product)

A

Target 80% of use cases.

Forget the edge cases.

Avoid conditional expressions. An MVP should have a narrow focus

Minimize the number of variables.

Maximize the number of outputs.

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

Nesting Modules

A

A nested module is a reference to invoke another module from the current module.

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

Where do you find and explore terraform Modules?

A

The Terraform Registry makes it simple to find and use modules.

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

What is the syntax for referencing a registry module?

A
NAMESPACE/NAME/PROVIDER
// 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
15
Q

What is the syntax for referencing a private registry module?

A
HOSTNAME/NAMESPACE/NAME/PROVIDER
// 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
16
Q

Required argument in module blocks

A
source and version
// example
module "consul" {
  source = "hashicorp/consul/aws"
}
17
Q

How do you access output variables from a module?

A

module.MODULE_NAME.OUTPUT_NAME

18
Q

When installing the modules and where does 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-2417f60
19
Q

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

A
version - string, specifies version constraints for the referenced module
providers - map, keys are provider configuration names that are expected by child module and whose values are corresponding provider names in the calling module.