60 Terraform questions and answers

Last Updated: Feb 17, 2022

Ryan Fang
14 min readJun 7, 2021

Disclaimer:

These questions are completely brainstormed on my own and are not from the terraform associate exam. These questions may or may not be relevant to topics tested on the terraform associate exam, and they may or may not be 100% up to date. They are aimed to be an additional data point for you to test your knowledge with terraform rather than to test your exam readiness. The questions will be listed first, and the answers will be listed at the end of the page.

For a comprehensive and official list of exam topics, please visit:

Question 1. Which of the complex types below are collection types in Terraform? (2 correct answers)

a) lists
b) numbers
c) tuple
d) maps
e) objects

Question 2. Which commands below runs terraform refresh as a part of their functions? (3 correct answers)

a) terraform plan
b) terraform import
c) terraform login
d) terraform destroy
e) terraform apply

Question 3. What is state locking?

a) State locking prevents write operations on your state file
b) State locking prevents read operations on your state file
c) State locking locks in your terraform resources so they cannot be deleted from the managed environment
d) State locking prevents terraform from unauthorized access to your state

Question 4. Fill in the blank, what is the difference between a provisioner and a provider?

A _______ is a plugin that adds a set of resource types and data sources that terraform can manage, while a _______ is used to model specific actions on a _______ machine in order to prepare servers or other infrastructure for service

a) provisioner, provider, local
b) provider, provisioner, local or remote
c) provisioner, provider, local or remote
d) provider, provisioner, local
e) provisioner, provider, remote

Question 5. Can you specify a provider for a module to use?

a) Yes
b) No

Question 6. What are locals block?

a) locals block is a block which adds additional functionalities to a terraform module
b) locals block assigns expressions to variables that can be used repeatedly across a module
c) locals block provision resources that are to be used on the local machine
d) locals block stores a list of resources that are provisioned by the current module

Question 7. Where can locals be referred from?

a) It's global to all modules in terraform
b) From within the specific file which they are written in
c) From within the specific workspace they're in
d) From within the directory which they exist
e) From within the module in which they exist

Question 8. Which files make up a module composition? (2 correct answers)

a) main.tf 
b) terraform.tfstate
c) terraform.d
d) modules
e) variables.tf

Question 9. What is the function to translate a given value to a string into json or yaml?

a) jsonify or yamlify
b) convjson or convyaml
c) jsonencode or yamlencode
d) tojson or toyaml

Question 10. What is the symbol for whitespace stripping?

a) ~
b) @
c) #
d) $
e) %

Question 11. What does terraform refresh do?

a) The terraform refresh command updates terraform to the latest version
b) The terraform refresh command updates terraform modules to the latest version
c) The terraform refresh command updates terraform modules to the latest version
d) The terraform refresh command reads the current settings in the terraform.rc file and refreshes your terraform behaviour
e) The terraform refresh command reads the current settings from all managed remote objects and updates the terraform state to match.

Question 12. What are 3 benefits of having a remote backend? (3 correct answers)

a) Version Control
b) Better Security
c) Faster loading speed
d) Easier to access
e) Multiple read operations

Question 13. What is terraform private module registry?

a) Terraform Cloud’s private module registry acts as a repository which only you can access that offers provider versioning, module versioning and remote state file storage. It allows you to store your current terraform configuration to feel as if you are working on a local machine. 
b) Terraform Cloud’s private module registry acts as a repository which you can store modules across your organization. It offers module versioning that includes both the root module as well as the child module so you may download the entire package at once to bootstrap your terraform workspace.
c) Terraform Cloud’s private module registry helps you share Terraform modules across your organization. It includes support for module versioning, a searchable and filterable list of available modules, and a configuration designer to help you build new workspaces faster.

Question 14. What is an orphaned resource in terraform?

a) An orphaned resource is a resource that was created by the user but is not associated with any state
b) An orphaned resource is a resource that had its configuration file deleted
c) An orphaned resource is a resource that was provisioned by the user but not from the root module
d) An orphaned resource is a resource that was provisioned by terraform but is not associated with any state

Question 15. What is a terraform run?

a) Terraform runs are managed remote operations in terraform cloud
b) Terraform run is an other version of terraform apply
c) Terraform run is a terraform cloud specific command that runs your local configuration
d) Terraform run runs additional plugins you specify and adds additional functionality to your terraform
e) Terraform run causes your terraform to run away from your system

Question 16. What is Hashicorp sentinel?

a) Sentinel is a policy-as-code framework thats built into terraform
b) Sentinel is the name given to a specific terraform module
c) Sentinel is an embedded policy-as-code framework integrated with the HashiCorp Enterprise products.
d) Sentinel allows secure storage of your terraform secrets

Question 17. How is terraform workspace different in local and in terraform cloud?

a) Workspace in local allows different state files with the same configuration whereas workspace in terraform cloud hosts different configurations
b) They are the same
c) Workspace in local hosts different configuration files whereas workspace in terraform cloud hosts different state files
d) Workspace in local are a representation of workspaces in terraform cloud

Question 18. How do you disable a remote operation in terraform ?

a) Remote operations cannot be disabled
b) Remote operations can be disabled by going into the terraform cloud command line and type in terraform remote disable
c) Remote operations can be disabled by logging into terraform cloud via terraform login and type in terraform remote disable
d) Remote operations can be disabled for any workspace by changing its “Execution Mode” setting to “Local”

Question 19. What is the command for upgrading terraform providers?

a) terraform apply -upgrade
b) terraform plan -upgrade
c) terraform init -upgrade
d) terraform refresh -upgrade
e) terraform upgrade

Question 20. Which of the following is terraform v0.12 provider syntax?

a) terraform {
required_providers {
mycloud = {
source = "hashicorp/aws"
version = ">= 1.0"
}
}
}
b) terraform {
required_providers {
aws = "~> 1.0"
}
}
c) terraform {
required_providers "aws" {
source = "hashicorp/aws"
version = ">= 1.0"
}
}
}
d) terraform {
required_providers "aws" {
source = "hashicorp/aws ~> 1.0"
}
}
}

Question 21. What is the underlying language terraform is written in?

a) Python
b) Java
c) Javascript
d) Go
e) C++

Question 22. What is terraform cloud’s pricing structure?

a) Basic $5/user/month, Team $20/user/month, Business $50/user/month
b) Free, Team $20/user/month, Business $50/user/month
c) Basic $5/user/month, Team $20/user/month, Business Contact Sales
d) Free, Team $20/user/month, Business Contact Sales
e) Flat $20/user/month across platform

Question 23. Do you need Go as pre-requisite for terraform installation?

a) Yes
b) No
c) Maybe

Question 24. What are the two connection types supported by a remote-exec provisioner? (2 correct answers)

a) git
b) ssh
c) winrm
d) https
e) http

Question 25. Do provisioners only work in resource blocks?

a) Yes, they only work within resource blocks that specify a valid resource
b) No, they can work outside of resource blocks
c) Yes, they can work within resource blocks that do or do not specify a valid resource
d) No, they can work outside of resource blocks but only if referenced in a provider block elsewhere in the root module

Question 26. What is the difference between the provider block and the required_providers block? (2 correct answers)

a) Required providers block specify providers that must be installed, provider block specify providers that are only installed when they are called upon in a module
b) They are the same
c) Required providers block must be nested inside a terraform block
d) provider block are "instances" of the required provider block and can specify different configurations of the required provider block
e) Provider blocks are nested in terraform block and are the "instances" of the required provider block

Question 27. What is the difference between terraform apply -replace and terraform taint?

a) They are the same
b) terraform apply -replace replaces the underlying resource with a new resource of the same configuration where as terraform taint taints the resource to be replaced on the next apply
c) terraform apply -replace is not a valid command
d) terraform apply -replace replaces the entire configuration with newly provided resources
e) terraform taint makes the underlying resource un-interactable

Question 28. What does TF_IN_AUTOMATION environment variable do?

a) If set to true, it causes Terraform to automate your terraform plan, and apply sequence as soon as you terraform init
b) If set to any non-empty value, Terraform adjusts its output to avoid suggesting specific commands to run next
c) If set to false, Terraform disables its output
d) If set to any non-empty value, Terraform adjusts its automated CLI commands such as plan or apply to run in stages

Question 29. Which takes precedence? Terraform.auto.tfvars or terraform.tfvars?

a) Terraform.auto.tfvars > Terraform.tfvars
b) Terraform.tfvars < Terraform.auto.tfvars
c) They take the same precedence

Question 30. Can multiple local values be present in a terraform configuration?

a) True
b) False

Question 31. What is the difference between dynamic block and a locals block? (2 correct answers)

a) Locals block allows us to construct nested blocks within another block, whereas dynamic block allows us to provide values to existing blocks which will be used over and over again
b) Dynamic block exists only within top-level block constructs whereas locals block can exist on its own
c) Dynamic block allows us to construct nested blocks within another block, whereas locals block allows us to provide values to existing blocks which will be used over and over again
d) You can have multiple locals block in a configuration but not multiple dynamic blocks
e) You can have multiple dynamic blocks in a configuration but not multiple locals blocks

Question 32. Does a module require a provider?

a) True
b) False

Question 33. Which of the below is a valid string in terraform?

a) "hello"
b) 'hello'
c) hello

Question 34. What are are structural types in terraform? What are collection types?

a) They are the same
b) Collection types must have the same typed values whereas structural types can have different typed values
c) Structural types must have the same typed values whereas collection types can have different typed values

Question 35. Can locals block refer to other locals blocks?

a) Yes
b) No
c) Only under certain circumstances

Question 36. If you want to display a list of every managed resources, which command do you use? terraform state list, terraform show, or terraform state show?

a) terraform state list
b) terraform show
c) terraform state show
d) terraform state show or terraform state list
e) terraform show or terraform state list

Question 37. Does terraform force every state modification command to write a backup file?

a) Yes
b) No

Question 38. What command does terraform use to print information about the provider used in the current configuration?

a) Terraform providers
b) Terraform providers show
c) Terraform providers list
d) Terraform providers
e) Terraform version

Question 39. What does terraform state mv command do?

a) It moves a single resource into a terraform state file
b) It detects all the unmanaged resources in the cloud and move them into the terraform state file
c) It moves the state file from one workspace to another
d) It moves the state file from the current workspace to terraform cloud

Question 40. What happens when you use terraform apply after you change the resource label of an existing resource?

a) The underlying resource is destroyed and recreated on the next apply
b) The underlying resource is updated on the next apply
c) The existing resource is preserved, terraform creates a new resource with the new name
d) The existing resource is preserved, only the state file is updated to reflect this change
e) The existing resource is preserved, the state file does not change since the change is only for configuration

Question 41. What happens when you use terraform apply after you change the resource configuration of an existing resource?

a) The underlying resource is destroyed and recreated on the next apply
b) The underlying resource is updated on the next apply
c) The existing resource is preserved, terraform creates a new resource with the new name
d) The existing resource is preserved, only the state file is updated to reflect this change
e) The existing resource is preserved, the state file does not change since the change is only for configuration

Question 42. What happens when you use terraform apply after you change the value of an existing resource?

a) The underlying resource is destroyed and recreated on the next apply
b) The underlying resource is updated on the next apply
c) The existing resource is preserved, terraform creates a new resource with the new name
d) The existing resource is preserved, only the state file is updated to reflect this change
e) The existing resource is preserved, the state file does not change since the change is only for configuration

Question 43. How do you rename resources? (2 correct answers)

a) You change the resource label
b) You change the variable "name" in the resource configuration
c) You use terraform state mv to move the resource with the new name from one state to another
d) You manually change the resource name in the console and use terraform apply -refresh to reflect this change
e) You delete the existing state and recreate it

Question 44. Can another process unlock local state files?

a) Yes
b) No

Question 45. Where is the state file stored when it is created in another workspace on a local machine?

a) It is stored as as another state file in the same directory, you can get to it by using terraform workspace select
b) It is stored in the terraform.tfstate.d folder
c) It is stored in the .terraform/terraform.tfstate.d folder
d) It is stored in the .terraform/ folder
e) It is stored in the terraform.d folder

Question 46. Implicit Dependency in terraform is when terraform _____ in a terraform configuration. Explicit dependency is when when terraform _____ in a terraform configuration.

a) automatically recognize a dependency, uses depends_on to specify a dependency 
b) uses depends_on to specify a dependency, automatically recognize a dependency
c) uses for_each to specify a list of resources, uses depends_on to specify a dependency
d) uses depends_on to specify a dependency, uses for_each to specify a list of resources

Question 47. What is the command for supplying a plan file to terraform apply?

a) -target=<plan-file>
b) -var=<plan-file>
c) -plan=<plan-file>
d) -input=<plan-file>
e) -file=<plan-file>

Question 48. What is the difference between locals and input variable?

a) Input variables can be used across modules whereas locals block only apply to the current module
b) They have the same function, they both supply values to terraform modules.
c) Input variables serve as parameters for a Terraform module. Local values assign a name to an expression.
d) local value serve as parameters for a Terraform module. Input variables assigns a name to an expression.
e) local values are a subset of input variables which only apply to the current module

Question 49. Can input variable and providers be inherited to child modules?

a) Yes
b) No
c) Input variables can be inherited but only in a specific way, providers cannot
d) Providers can be inherited but only in a specific way, input variables cannot

Question 50. If you have a large terraform configuration file with over 100+ resource configurations, applying them to the cloud takes over 3 hours to complete. What can you do to speed up the process?

a) Break the configuration up into smaller modules to speed up the process
b) Disable refresh when you use terraform
c) Use multiple service accounts to deploy resources concurrently
d) Since most resource provisioning make API calls prior to provisioning, contact the cloud vendor to increase your limit to help speed up the process

Question 51. What happens if you have both the credential_helper and credential block in a terraform config file?

a) The credential helper block and credential block merge their credentials together and attempt logins twice
b) The credential block overrides the credential helper block
c) The credential helper block overrides the credential block
d) Whichever comes last wins
e) Whichever comes first wins

Question 52. Which of the following are valid remote backends for terraform? (2 correct answers)

a) github
b) bitbucket
c) GCS
d) S3
e) Terraform registry

Question 53. What types of provisioners exist in terraform? (3 correct answers)

a) file
b) system
c) local-exec
d) remote-exec
e) ssh

Question 54. Will terraform update stored cache on its own?

a) yes
b) no

Question 55. Which of the following is a valid module source? (2 correct answers)

a) source = "app.terraform.com/example-corp/k8s-cluster/azurerm"
b) source = "git::ssh://username@example.com/storage.git"
c) source = "git::https://example.com/vpc.git#ref=v1.2.0"
d) source = "./consul"

Question 56. Which of the following are valid references to named resources in terraform? (2 correct answers)

a) resource.aws_instance.instance_one
b) aws_instance.instance_one
c) aws_instance.instance_one.[*]
d) aws_instance.example["a"].id
e) aws_instance.count.[1].id

Question 57. If an output is marked as sensitive, where will you ever see its value?

a) When you supply the -sensitive=false flag to terraform apply
b) In the state file
c) In another module's output when you reference the sensitive output
d) Nowhere except the configuration where it's written
e) In the metadata of the deployed resource

Question 58. Which of the following are valid lists in terraform? (2 correct answers)

a) ["a", "b", "c"]
b) ['a', 'b', 'c']
c) [true, 12, "c"]
d) ["a",{},"c"]

Question 59. Which file does terraform create when you use terraform login?

a) credentials.json
b) terraform.d
c) terraform.rc
d) credentials.tfrc.json

Question 60. If you want to enable logging in terraform with the most verbose option, what do you do?

a) set TF_LOG=Trace
b) set TF_LOG=DEBUG
c) set TF_TRACE=LOG
d) set TF_LOG=true
e) set TF_TRACE=true

Bonus Question:

Question 61. How confident do you feel about the terraform associate exam after doing this mock test?

a) I'm ready to take on the actual exam
b) I still have some studying to do, maybe a couple more days could help
c) I'm boned man.... time to get back to studying
d) Terraform associate exam? What's that?
e) Let's go! My exam is within the hour, this is nothing to me
f) I'm just doing this for fun, I already passed my exam

Coffee Break :)

Photo by Clem Onojeghuo on Unsplash

Answers:

1. a,d
2. a,d,e
3. a
4. b
5. b
6. b
7. d
8. a,e
9. c
10. a
11. e
12. a,b,e
13. c
14. b
15. a
16. c
17. a
18. d
19. c
20. b
21. d
22. d
23. b
24. b,c
25. c
26. c,d
27. b
28. b
29. a
30. a
31. b,c
32. b
33. a
34. b
35. a
36. d
37. a
38. a
39. a
40. a
41. b
42. b
43. b,c
44. b
45. b
46. a
47. c
48. c
49. d
50. b
51. b
52. c,d
53. a,c,d
54. b
55. a,c
56. b,d
57. b
58. a,c
59. a,d
60. a

Good luck on your terraform associate exam :)

--

--

Ryan Fang

DevOps Engineer, 3X GCP, CK${A,D}, CJE, TA, Next, Express, Firebase