Terraform Associate Exam Flashcards

1
Q

What is the typical name of the configuration file in Terraform?

A

main.tf

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

What is the command to plan out your Terraform changes?

A

terraform plan

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

What is the command to apply your Terraform changes?

A

terraform apply

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

What is the command to initialize your Terraform directory?

A

terraform init

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

What is the command to destroy your Terraform resources?

A

terraform destroy

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

What is the command to check the syntax and validity of your Terraform configuration files before applying changes with them?

A

terraform validate

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

What is the command used to download modules referenced in your Terraform config files?

A

terraform get

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

What is the command used to show the current state of your infrastructure?

A

terraform show

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

What is the command used to show the current version of Terraform?

A

terraform version

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

What file describes the values you want to be displayed after Terraform changes are applied?

A

outputs.tf

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

What are lifecycle rules used for in Terraform?

A

Lifecycle rules in Terraform are used to define when and how resources should be created, updated, or deleted during the execution of Terraform operations. Ex - you can set the ‘prevent_destroy’ attribute to prevent a resource from being destroyed.

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

List the 7 common types of Terraform variables:

A

String, Number, Boolean, List, Map, Object, Tuple

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

What is the ‘data’ codeblock used for in Terraform?

A

used to retrieve and access information from data sources, external systems, or remote resources that are not directly managed by Terraform

Ex - Getting the latest AMI ID from AWS for an Ubuntu system image

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

What is the default behavior if a variable is not defined when ‘terraform’ commands are run?

A

The user running the terraform command will be asked to input a value for the variable.

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

What are dynamic blocks used for in Terraform?

A

used for generating multiple blocks of configuration with the same structure but different values

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

What is a tuple in Terraform?

A

Tuples are lists that can support multiple data types.

Ex - variable “my_tuple” {
type = tuple
default = [“apple”, 42, true]
}
^ notice the different data types all in the same variable

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

What is a map in Terraform?

A

a data structure used to store a collection of key-value pairs where each key is unique within the map

Ex - variable “my_map” {
type = map(string)
default = {
key1 = “value1”
key2 = “value2”
}

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

T/F: A Terraform local value can reference other Terraform local values?

A

True

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

Which value provides the most verbose logging to assist with troubleshooting?

A

TRACE

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

List the order of variable assignment in TF (there are 4)

A
  1. -var flag through the CLI.
  2. terraform.tfvars file (this resides near the state file)
  3. Variables set as environment variables, such as TF_VAR_<variable_name>.</variable_name>
  4. Default variables declared within the config (variables.tf)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is HashiCorp Sentinel?

A

a policy as code framework used for defining and enforcing compliance and security policies across infrastructure provisioning and deployment workflows.

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

What Terraform feature is most applicable for managing small differences between different environments, for example development and production?

A

Terraform Workspaces

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

Where are Terraform Workspace local state files stored?

A

A directory called terraform.tfstate.d

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

What command creates a new workspace for Terraform?

A

Terraform workspace new (workspace name)

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

What is an object in Terraform?

A

an object structural type is used to define a structured data type with named attributes, each having its own data type

Ex - variable “person” {
type = object({
name = string
age = number
enabled = bool
})

default = {
name = “John Doe”
age = 30
enabled = true
}

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

What are the types of dependencies used in Terraform? There are 2.

A

Implicit dependencies & Explicit Dependencies

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

Describe an implicit dependency.

A

Dependencies that do not call explicitly to a specific resource name like an explicit dependency. Rather, Terraform is smart enough to understand how resources interact with each other and should be created. For example, Terraform will know to create an EC2 instance with the name specified before attaching an elastic IP.

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

Describe an explicit dependency.

A

Uses the “depends_on” command to name a specific resource before creating

29
Q

What does the ‘depends_on’ command do?

A

You can specify order creation by adding this to the end of your resource code block. You can specify another resource to specify that you need another resource to be created before this one

Ex - resource “aws_security_group” “example” {
name = “example”
description = “Example security group”

# This resource depends on the “aws_instance” resource named “example”
depends_on = [aws_instance.example]

30
Q

What is the exact name of the Terraform state file?

A

terraform.tfstate

31
Q

What command lets you interact with the current state of your infrastructure?

A

terraform state

32
Q

What command lets you manage a resource created outside of Terraform deployment?

A

terraform import

33
Q

How can you troubleshoot Terraform using log files?

A

The TF_LOG file can be used to troubleshoot Terraform issues.

34
Q

What is Terraform Cloud?

A

Terraform Cloud allows you to run Terraform code directly in the cloud, and it can provision and manage resources on your behalf without the need for your local machine to execute the Terraform commands.

35
Q

Does Terraform manage state file locking automatically?

A

Yes - and if the state file fails to lock, Terraform will not perform the apply.

36
Q

Name 3 Terraform backend type that support state locking.

A

consul, kubernetes, s3

37
Q

If you wish to rename a resource in your Terraform configuration but don’t want Terraform to deploy this resource as new, what command can you run to ‘rename’ it in the state file?

A

terraform state mv (original name) (new name)

38
Q

What is a manual command you can run to install new modules to Terraform?

A

terraform get

39
Q

By default, when running terraform plan, what files are scanned?

A

All *.tf files in the current directory

40
Q

T/F: ​​terraform apply -destroy does the same thing as terraform destroy

A

True

41
Q

What command formats your Terraform code using HashiCorp standards?

A

terraform fmt

42
Q

What command can you run to properly format all ‘.tf’ files in your working directory?

A

terraform fmt -recursive

43
Q

How would you get the JSON output of the ‘terraform validate’ command?

A

Using the -json flag.

Ex - terraform validate -json

44
Q

Does ‘terraform validate’ interact with the provider API at all?

A

No - it validates your configuration files for any possible errors before applying changes.

45
Q

What is the file name where values for variables are stored in the backend of TF?

A

Terraform.tfvars

46
Q

What 3 things must be provided with the terraform import command for Terraform to successfully import resources?

A

Resource ID, resource type, and the resource name from the cloud provider

47
Q

What must you do before using ‘terraform import’ to import a cloud resource?

A

You must create the resource codeblock in main.tf before importing the resource.

Ex. Create an ec2 resource in main.tf before importing the unmanaged EC2 instance.

48
Q

What command will list all resources managed by Terraform?

A

terraform state list

49
Q

What command replaced ‘taint’ in the newest version of Terraform?

A

terraform apply -replace=”aws_instance.example”

50
Q

What is not changed when running a ‘terraform apply -refresh-only’?

A

Main.tf / The refresh command uses the provider’s API to check the current state of resources and reflect them in the state file

51
Q

What does a ‘terraform apply -refresh-only’ command do?

A

Compares the state file with the real infrastructure from the cloud provider, then updates the state file to reflect what is running in the cloud provider.

52
Q

Which flag would you add to terraform plan to save the execution plan to a file?

A

-out (file name)

Ex- terraform plan -out=example.tfplan

53
Q

Which flag would you use alongside ‘terraform plan’ & ‘terraform apply’ to make changes to only a specific resource?

A

‘-target’ allows you to specify a specific resource or resource instance to include in the execution plan, focusing only on changes related to that target.

Ex- terraform plan -target=aws_instance.my-instance

54
Q

Terraform performs concurrent operations to save time. By default, how many resources will Terraform provision concurrently during a terraform apply?

A

10

55
Q

How can you change the number of concurrent operations?

A

You can change it using the -parallelism=# flag to your ‘terraform apply’ command.

Ex - terraform apply -parallelism=2

56
Q

What Terraform command can be used to remove the lock on the state for the current configuration?

A

terraform force-unlock

57
Q

T/F: Github is a supported backend type of Terraform.

A

False

58
Q

To secure keys and other sensitive information, rather than storing them as plain text, where should you store the values?

A

A credentials file or in environment variables.

59
Q

What is a terraform provisioner?

A

a provisioner is a component that is used to execute scripts or commands on a resource after it has been created or updated. Provisioners are typically used for tasks such as configuring or customizing a resource once it’s provisioned.

Ex - like “user data” on an EC2 instance

60
Q

T/F: It is recommended to use provisioners when creating resources.

A

False. It is generally not recommended to use provisioners for creating resources in Terraform. Provisioners are primarily used for post-resource creation tasks, such as configuring or initializing resources after they have been created.

61
Q

Which provisioner copies files or directories from the machine running Terraform to the newly created resource?

A

The ‘file’ provisioner

62
Q

What is the syntax to correctly reference a data source?

A

data.<DATA>.<NAME></NAME></DATA>

63
Q

How do you update Terraform plugins?

A

terraform init –upgrade

64
Q

How do you update Terraform modules?

A

terraform get -update

65
Q

What are the three steps of the Core Terraform Workflow?

A

Write, plan, apply

66
Q

What are the three Terraform Cloud features?

A

Remote state management, Remote Terraform Execution, Private Module Registry

67
Q

How would you delete a resource from your state file?

A

terraform state rm “resource name”

68
Q

T/F: Any command that modifies the state file triggers an automatic backup of the current state file before changes are made.

A

True

69
Q

What is the file name of the automatic backup that Terraform performs of the state file?

A

terraform.tfstate.backup