Terraform Modules/Workspaces Flashcards

1
Q

What to use terraform modules?

A

Aimed at reducing repetition, reduce possible changes due to provider updates, lack of standardization, difficult to manage, and difficult for devs to use.

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

How do you reference modules in Terraform?

A

module “name” {}

*The module block must contain source argument that contains location to the referenced module.

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

Are there some infrastructure resources that you can directly use a module calling code and the entire infrastructure will be created for you? If so what’s an example

A

Yes

Ex: ec2-instance

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

Whats an example of a module that requires additional input before completing?

A

module “eks” will throw an error because it requires additional details.

Ex: the EKS module requires subnet ID’s and a cluster name. Once submitted, the terraform plan will complete.

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

Can module structures be different

A

Yes, some module pages in GitHub can contain multiple sets of modules together for different features.

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

What’s the criteria on which module you should download/use?

A
  1. Check the # of downloads.
  2. Check GitHub Page of Modules for information related to contributors, recent changes, and pending issues being worked on.
  3. Avoid modules maintained/written by individual participant (changes/updates might not be fixed in timely manner)
  4. Analyze module documentation
  5. Check version history of module (indicates updates occurring/not occurring)
  6. Analyze the code (look for clean/well structured code)
  7. Community feedback (# of stars and forks)
  8. Modules maintained by hashicorp partner.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Should you try random Terraform modules that arent actively maintained and look shady (primarily by sole individual contributors)

A

Absolutely not as it could contain malicious code that sends info about your environment to a hacker.

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

What modules do orgs use?

A

They mostly have private modules, creating forks from strong modules , and modifying them to their use case.

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

Whats the structure of a module if you create your own?

A
  1. First, a base “modules” folder.
  2. a sub-folder containing name for each module.
  3. Each sub-folder contains the actual module terraform code that other projects can reference (ex. main.tf)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How is a module referenced using a local path?

A

Local parts are used to reference to modules that are available in local file system.

A local path must begin with either ./ or ../ to indicate that its a local path.

module ec2 {}
source = “../modules/ec2”

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

How is a module referenced using a git respository?

A

source = “git::https://example.com/vpc.git”

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

Can a specific module have multiple versions?

A

Yes, you can reference specific versions with the version block

module “eks” {
source = ..
version = ..
}

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

What are challenges with module code?

A
  1. Hardcoded values (if dev is calling modules, he will have to stick with same values. AVOID if possible
    * Dev can’t override values
  2. Provider improvements; avoid hardcoding region in the module code.
    Fix: use required_provider block with version constraints for module to work
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Whats the workout around for hardcoded values in modules?

A

Use variables to allow the value to be overrided.

Ex:
ami = var.ami
instance_type = var.instance_type

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

Whats the workout around hardcoded provider blocks?

A

Make use of required_providers block
*In doing so you can set a version requirement where the current code is working.

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

Module outputs, what are they?

A

They make info about your infra available on the cmd line, and can expose info for other terraform configs to use.

17
Q

If you want to create a source that has independency on an infrastructure created through a module, you won’t be able to implicitly it without what?

A

The use of output values.

Ensure to include output, values in the module code for better flexibility and integration with other resources and projects.

Format: module.module.outputnamee

18
Q

Whats the difference between root module and child module?

A

Root modules reside in the main working directory of your terraform configuration. this is the entry point for your infrastructure definition.

Child modules are modules that have been called by another module.

19
Q

What is the standard module structure?

A

The standard structure is a file and directory layout Hashicorp recommends for reusable modules.

20
Q

Whats the minimum recommended module structure?

A

$ tree minimal-module/
.
README.md
main.tf
variables.tf
outputs.tf

21
Q

Whats the best practice for writing modules for larger orgs?

A

After determining org’s requirements, split up into categories.

Ex: networking module, security, routing, web module, database, app module.