Terraform Flashcards

1
Q

What is infrastructure as code?

A

Is provisioning infrastructure through software to achieve consistent and predictable environments.

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

What is the difference between declarative and imperative?

A
Imperative = step-by-step on how to do a task
Declarative = I want the state X (declaring what I want).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is idempotency?

A

If I run the same task twice I won’t have a duplicated item.

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

What is the difference between push and pull?

A

Push: a server actively pushes configs;
Pull: a client actively pulls configs;

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

Is terraform push-type-model?

A

Yes. A server pushes the configs.

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

What is workflow that terraform imposes?

A

Provisioning resources;
Planning Updates;
Using Source Control;
Reusing Templates;

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

What are the four components of terraform?

A

terraform executable, terraform files, terraform plugins and terraform state.

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

What is a terraform plugin?

A

Is an extension of terraform that allows interacting with providers (e.g: azure, aws etc.

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

What is the terraform state?

A

Keeps track of what the current state looks like

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

what is the data type?

A

a data-source

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

what a tf file contains?

A

terraform code itself.

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

what a tfvars file contain?

A

input to variables

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

how to reference a var?

A

var.my_var_name

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

What is a triplet?

A

resourceType.resourceName.property.

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

Does terraform support function? examples?

A

yes… file(path)

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

what does the output type do?

A

outputs the content of a variable

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

how to declare a var in a tfvar file?

A

variable “image_id” {
type = string
}

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

what is the caveat with backslash in a windows environment?

A

it’s escape… use double: \

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

What does terraform init do?

A

It checks the config files looking for providers (plugins) and download the necessary files.

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

What does terraform plan do?

A

Loads the config files (.tf) and variables (.tfvars) and compare against an existing state (if any) then shows what needs to be done to achieve the desired state.

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

what does terraform plan -out myplan.tfplan?

A

shows the plan and store it in the tfplan file for future usage (apply) / inspection.

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

what is “known after apply” value that shows in the plan?

A

stuff that will be known only after the resource is applied (such as IDs)

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

What does terraform apply “myplan.tfplan” do?

A

Will apply the plan (actually provision stuff)

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

Which file is created after the first time I do an apply?

A

a tfstate file will be created

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

What does the terraform destroy do?

A

destroy the resources that are stored in the state file

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

what is the format of tfstate? Should I manually change it?

A

JSON. DO NOT TOUCH IT.

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

what the tfstate file contain?

A

resource mappings and general metadata. locking, location…

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

what is a workspace in terraform?

A

each workspace has a state… so it is a separation.

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

what happens if the installed version of terraform is lower than the one that created the state file (someone else created it, for example)?

A

terraform won’t allow interactions on it (you’ll need to upgrade terraform)

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

what is the serial number of tfstate?

A

an incremental number that is increased when the state file is updated.

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

why is the serial number of tfstate necessary?

A

to match up the version I have in the plan and the one in the state (so that you can’t apply an old plan)

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

does the tfstate contain the output information that we define and see in the prompt?

A

yes.

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

What is the golden rule of terraform?

A

Only change stuff via terraform (DO NOT CHANGE RESOURCES MANUALLY).

34
Q

What in detail terraform planning do?

A

inspects the state, do the dependency graph and calculates the additions updates and deletions. Do stuff in parallel.

35
Q

When the tfplan file is the most useful?

A

on teams where stuff needs to be approved before applied… e.g: in my PR I can have the plan but on master it actually applies it.

36
Q

Can I access triplet’s property index? e.g: access the first item on an array?

A

yes… resourceType.resourceName.property[0]

37
Q

What is a provisioner in the tf file? what does it require first?

A

allows executing arbitrary scripts. requires a ssh connection

38
Q

How the Terraform syntax is called?

A

HashiCorp configuration language.

39
Q

Why using hashicorp configuration language instead of json or yaml?

A

because they wanted to introduce functions, conditionals and templates which was not available in the first two.

40
Q

What is a block in terraform? How a black inside a block is called?

A

the simplest structure we can have. It is called embedded block.

41
Q

How to declare a block?

A

block_type label_one label_two {}

42
Q

how many primitive types we had up to terraform .12? What happened after?

A

string only. it was added: number, bool, list and map (key value pairs)

43
Q

what is a local?

A

local var

44
Q

How does interpolation looks like in terraform?

A

taco_name = “The name is ${var.name}”

45
Q

how to access a list? what index it starts on ?

A

local.mylist[0]. starts on 0

46
Q

How to access a map?

A

local.mymap[“key”]

47
Q

What is a terraform provisioner and what happens if something goes wrong when deploying all your resources tied to this provisioner?

A

provisioner is a way to configure software (when you choose to not use ansible, for example). It will stop in the error one and what was created will remain created.

48
Q

what does the “&laquo_space;EOF” do?

A

it is a literal string block where crlf are kept.

49
Q

What does the remote-exec provisioner do?

A

executes command line in the remote computer.

50
Q

what does the output data type do? when to use?

A

outputs a value when the script is applied or when you do terraform output command. when values needs to be used somewhere else for convenience

51
Q

how is the syntax of a terraform function?

A

function(arg1, arg2…)

52
Q

is the terraform function args positional or named?

A

positional

53
Q

what are common functions bulitin on terraform?

A

lower, merge(map1, map2), file(path), timestamp()

54
Q

what is the command terraform console? when is it useful?

A

allows running functions independently. to test out results of summing, functions and etc

55
Q

what does the terraform fmt command does?

A

fixes formatting of the terraform files to match the canonical format

56
Q

what does the terraform taint and untaint does?

A

mark a resource to be recreated even though terraform thinks it is al good with it. untaint remove taint

57
Q

what does terraform validate does? will it ensure terraform apply will work?

A

will find syntax errors and other superficial errors. Does not guarantee a successful terraform apply.

58
Q

who writes the providers? which language?

A

usually the cloud vendors, community or hashicorp itself. needs to be written in go.

59
Q

what is a provider?

A

collection of resources and data sources (structures) that can be used in a terraform script.

60
Q

what does the alias property in a provider do? and why it exists?

A

allows specifying a specific provider. in case you have the same provider declared multiple times. needs to be referenced in the resources as well.

61
Q

What are the main terraform resource arguments?

A

depends_on, count, for_each and provider

62
Q

Will terraform figure out the dependencies between resources? When to use depends_on then?

A

Yes, when the dependency is not obvious to terraform.

63
Q

what does the count resource argument do?

A

allows you to create n resources (loop)

64
Q

what does the for_each resource argument do?

A

allows you to iterate over a map to create resources and etc

65
Q

what does the provider resource argument do?

A

allows you to define a provider to create the give resource when it is not clear to terraform which one to use.

66
Q

how to create a list based on another list’s specific property

A

my_ids = mylist[*].id

67
Q

what are the properties a variable can have in its declaration? Is it recommended to define a type?

A

name, type and default. yes, recommended.

68
Q

What are the three ways that terraform allow defining variables? Does the precedence count?

A

environment < file < command line. yes… environment the least powerful

69
Q

Is it common to split variables, resources and specific data types in different files?

A

yes.

70
Q

How to declare a variable type of a map of strings? can I define a default value for that?

A

variable “myvar” {
type = map(string)
}

yes.. just declare a map as default.

71
Q

what is the Hashicorp recommended way to deal with multiple environments (dev, test, prod)?

A

by using workspaces

72
Q

what are the four concerns we need to address in multiple environment terraform configuration?

A

state management, variables data, credentials management and complexity/overhead.

73
Q

if we couldn’t use workspaces to manage multiple environments, how could we handle it?

A

common scripts and folders holding specific environments stuff… see: https://pasteboard.co/JJY0e2G.png

74
Q

how to create a new workspace using terraform cli?

A

terraform workspace new dev

75
Q

Where does terraform workspace put the state files?

A

in a folder, states are separated.

76
Q

what does the value that terraform.workspace return? why is it useful?

A

the name of the workspace given during terraform workspace new. so that you can access map values using the workspace name as key

77
Q

which options can I use to store secrets?

A

environment variables, variables files or a secret management solution.

78
Q

What is a terraform module? What is the root module? Can it call “child” modules?

A

A terraform module is a reusable piece of configuration that is meant to be shared across different apps (mini terraform config). Root module is what terraform uses under the hood when you create terraform files. Yes.

79
Q

does modules support versioning?

A

yes.

80
Q

does module support count or do I need to list them out?

A

no, necessary to list the modules (meaning how many copies you want of that module)

81
Q

what are the three module components and how they interate?

A
variables are defined as input of the module.
resources are going to be created (based on the vars)
output are externalized so that the root module can use it.
82
Q

what is a template file?

A

is a file that support variable substitution.