250 Practice Questions For Terraform Associate Certification
250 Practice Questions For Terraform Associate Certification
250 Practice Questions For Terraform Associate Certification
You have 2 free member-only stories left this month. Upgrade for unlimited access.
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 1/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
Terraform Certification
Since this exam is multiple-choice, multiple-answer, and fill in the banks' questions, we
need a lot of practice before the exam. This article helps you understand, practice, and
get you ready for the exam. All the questions and answers are taken straight from
their documentation. These are only practice questions.
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 2/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
We are not going to discuss any concepts here, rather, I just want to create a bunch of
practice questions for this exam based on the curriculum provided here.
You write and execute the code to define, deploy, update, and
destroy your infrastructure
a. Automation
We can bring up the servers with one script and scale up and down
based on our load with the same script.
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 3/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
c. Versioning
Multi-Tier Applications
Self-Service Clusters
Software Demos
Disposable Environments
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 4/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
Resource Schedulers
Multi-Cloud Deployment
https://www.terraform.io/intro/use-cases.html
Platform Agnostic
State Management
Operator Confidence
https://learn.hashicorp.com/terraform/getting-started/intro
8. Where do you describe all the components or your entire datacenter so that
Terraform provision those?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 5/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
Yes
This file contains a custom JSON format that records a mapping from
the Terraform resources in your configuration files to the
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 6/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
Metadata
Performance
When running a terraform plan, Terraform must know the current state
of resources in order to effectively determine the changes that it
needs to make to reach your desired configuration.
Syncing
When two people works on the same file and doing some changes to the
infrastructure. Its very important for everyone to be working with
the same state so that operations will be applied to the same remote
objects.
https://www.terraform.io/docs/state/purpose.html
terraform.tfstate
Explain when to use and not use provisioners and when to use local-exec or remote-
exec
// Mac OS
// Windows
https://learn.hashicorp.com/terraform/getting-started/install
20. Where do you put terraform configurations so that you can configure some
behaviors of Terraform itself?
terraform {
# ...
21. Only constants are allowed inside the terraform block. Is this correct?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 8/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
Yes
https://www.terraform.io/docs/configuration/providers.html
provider "google" {
project = "acme-app"
region = "us-central1"
The name given in the block header ("google" in this example) is the
name of the provider to configure. Terraform associates each
resource type with a provider by taking the first word of the
resource type name (separated by underscores), and so the "google"
provider is assumed to be the provider for the resource type name
google_compute_instance.
24. What are the meta-arguments that are defined by Terraform itself and available
for all provider blocks?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 9/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
27. When you run terraform init command, all the providers are installed in the
current working directory. Is this true?
terraform {
required_providers {
}
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 10/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
29. How do you upgrade to the latest acceptable version of the provider?
terraform {
required_providers {
provider {
version= "1.0"
alias
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 11/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
provider "aws" {
region = "us-east-1"
provider "aws" {
alias = "west"
region = "us-west-2"
provider = aws.west
# ...
Windows %APPDATA%\terraform.d\plugins
True
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 12/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
37. The command terraform init cannot install third-party plugins? True or false?
True
terraform-provider-<NAME>_vX.Y.Z
On all other systems, the file must be named .terraformrc (note the
leading period) and placed directly in the home directory of the
relevant user.
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 13/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
Given that provider plugins can be quite large (on the order of
hundreds of megabytes), this default behavior can be inconvenient
for those with slow or metered Internet connections.
plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"
43. When you are using plugin cache you end up growing cache directory with
different versions. Whose responsibility to clean it?
User
Terraform will never itself delete a plugin from the plugin cache
once it's been placed there. Over time, as plugins are upgraded, the
cache directory may grow to contain several unused versions which
must be manually deleted.
// Example
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 14/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
provider "aws" {
profile = "default"
region = "us-east-1"
ami = "ami-2757f631"
instance_type = "t2.micro"
terraform init
46. If different teams are working on the same configuration. How do you make files
to have consistent formatting?
terraform fmt
47. If different teams are working on the same configuration. How do you make files
to have syntactically valid and internally consistent?
terraform validate
This command will check and report errors within modules, attribute
names, and value types.
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 15/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
terraform apply
49. What is the command to show the execution plan and not apply?
terraform plan
50. How do you inspect the current state of the infrastructure applied?
terraform show
51. If your state file is too big and you want to list the resources from your state.
What is the command?
https://learn.hashicorp.com/terraform/getting-
started/build#manually-managing-state
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 16/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
ami = "ami-b374d5a5"
instance_type = "t2.micro"
provisioner "local-exec" {
https://learn.hashicorp.com/terraform/getting-started/provision
local-exec
remote-exec
58. Are provisioners runs only when the resource is created or destroyed?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 17/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
Here is an example
provider "aws" {
profile = "default"
region = "us-west-2"
key_name = "examplekey"
public_key = file("~/.ssh/terraform.pub")
key_name = aws_key_pair.example.key_name
ami = "ami-04590e7389a6e577c"
instance_type = "t2.micro"
connection {
type = "ssh"
user = "ec2-user"
private_key = file("~/.ssh/terraform")
host = self.public_ip
provisioner "remote-exec" {
inline = [
61. You applied the infrastructure with terraform apply and you have some tainted
resources. You run an execution plan now what happens to those tainted resources?
When you generate your next execution plan, Terraform will not
attempt to restart provisioning on the same resource because it
isn't guaranteed to be safe.
Instead, Terraform will remove any tainted resources and create new
resources, attempting to provision them again after creation.
https://learn.hashicorp.com/terraform/getting-started/provision
62. Terraform also does not automatically roll back and destroy the resource during
the apply when the failure happens. Why?
Terraform also does not automatically roll back and destroy the
resource during the apply when the failure happens, because that
would go against the execution plan: the execution plan would've
said a resource will be created, but does not say it will ever be
deleted. If you create an execution plan with a tainted resource,
however, the plan will clearly state that the resource will be
destroyed because it is tainted.
https://learn.hashicorp.com/terraform/getting-started/provision
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 19/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
This command will not modify infrastructure, but does modify the
state file in order to mark a resource as tainted. Once a resource
is marked as tainted, the next plan will show that the resource will
be destroyed and recreated and the next apply will implement this
change.
65. By default, provisioners that fail will also cause the Terraform apply itself to fail.
Is this true?
True
66. By default, provisioners that fail will also cause the Terraform apply itself to fail.
How do you change this?
// Example
# ...
provisioner "local-exec" {
on_failure = "continue"
provisioner "remote-exec" {
when = "destroy"
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 20/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
# <...snip...>
terraform {
required_providers {
69. What should you use to set both a lower and upper bound on versions for each
provider?
~>
terraform {
required_providers {
terraform {
experiments = [example]
71. When does the terraform does not recommend using provisions?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 21/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
https://www.terraform.io/docs/provisioners/#passing-data-into-
virtual-machines-and-other-compute-resources
https://www.terraform.io/docs/provisioners/#running-configuration-
management-software
72. Expressions in provisioner blocks cannot refer to their parent resource by name.
Is this true?
True
73. What does this symbol version = “~> 1.0” mean when defining versions?
74. Terraform supports both cloud and on-premises infrastructure platforms. Is this
true?
True
75. Terraform assumes an empty default configuration for any provider that is not
explicitly configured. A provider block can be empty. Is this true?
True
76. How do you configure the required version of Terraform CLI can be used with
your configuration?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 22/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
77. Terraform CLI versions and provider versions are independent of each other. Is
this true?
True
78. You are configuring aws provider and it is always recommended to hard code
aws credentials in *.tf files. Is this true?
False
79. You are provisioning the infrastructure with the command terraform apply and
you noticed one of the resources failed. How do you remove that resource without
affecting the whole infrastructure?
You can taint the resource ans the next apply will destroy the
resource
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 23/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
Given a scenario: choose when to use terraform taint to taint Terraform resources
Given a scenario: choose when to use terraform state to view Terraform state
Given a scenario: choose when to enable verbose logging and what the
outcome/value is
83. By default, fmt scans the current directory for configuration files. Is this true?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 24/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
True
84. You are formatting the configuration files and what is the flag you should use to
see the differences?
85. You are formatting the configuration files and what is the flag you should use to
process the subdirectories as well?
86. You are formatting configuration files in a lot of directories and you don’t want
to see the list of file changes. What is the flag that you should use?
This command will not modify infrastructure, but does modify the
state file in order to mark a resource as tainted. Once a resource
is marked as tainted, the next plan will show that the resource will
be destroyed and recreated and the next apply will implement this
change.
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 25/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
89. When you are tainting a resource terraform reads the default state file
terraform.tfstate. What is the flag you should use to read from a different path?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 26/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
default
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 27/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
102. You are working on the different workspaces and you want to use a different
number of instances based on the workspace. How do you achieve that?
103. You are working on the different workspaces and you want to use tags based on
the workspace. How do you achieve that?
tags = {
104. You want to create a parallel, distinct copy of a set of infrastructure in order to
test a set of changes before modifying the main production infrastructure. How do
you achieve that?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 28/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
Workspaces
https://www.terraform.io/docs/commands/state/index.html
107. You are working on terraform files and you want to list all the resources. What
is the command you should use?
108. How do you list the resources for the given name?
109. What is the command that shows the attributes of a single resource in the state
file?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 29/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
You can set TF_LOG to one of the log levels TRACE, DEBUG, INFO, WARN
or ERROR to change the verbosity of the logs. TRACE is the most
verbose and it is the default if TF_LOG is set to something other
than a log level name.
Note that even when TF_LOG_PATH is set, TF_LOG must be set in order
for any logging to be enabled.
https://www.terraform.io/docs/internals/debugging.html
crash.log
https://www.terraform.io/docs/internals/debugging.html
112. What is the first thing you should do when the terraform crashes?
panic message
The most interesting part of a crash log is the panic message itself
and the backtrace immediately following. So the first thing to do is
to search the file for panic
https://www.terraform.io/docs/internals/debugging.html
113. You are building infrastructure for different environments for example test
and dev. How do you maintain separate states?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 30/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
directories
workspaces
This command will download the state from its current location and
output the raw format to stdout.
https://www.terraform.io/docs/commands/state/pull.html
116. What is the command is used manually to upload a local state file to a remote
state
https://www.terraform.io/docs/commands/state/push.html
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 31/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
117. The command terraform taint modifies the state file and doesn’t modify the
infrastructure. Is this true?
True
This command will not modify infrastructure, but does modify the
state file in order to mark a resource as tainted. Once a resource
is marked as tainted, the next plan will show that the resource will
be destroyed and recreated and the next apply will implement this
change.
118. Your team has decided to use terraform in your company and you have existing
infrastructure. How do you migrate your existing resources to terraform and start
using it?
You should use terraform import and modify the infrastrcuture in the
terraform files and do the terraform workflow (init, plan, apply)
119. When you are working with the workspaces how do you access the current
workspace in the configuration files?
${terraform.workspace}
120. When you are using workspaces where does the Terraform save the state file for
the local state?
terraform.tfstate.d
121. When you are using workspaces where does the Terraform save the state file for
the remote state?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 32/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
https://www.terraform.io/docs/commands/state/rm.html
123. How do you move the state from one source to another?
https://www.terraform.io/docs/commands/state/mv.html
The search query will look at module name, provider, and description
to match your search terms. On the results page, filters can be used
further refine search results.
126. How do you make sure that modules have stability and compatibility?
You need to add any module in the configuration file like below
module "consul" {
source = "hashicorp/consul/aws"
version = "0.1.0"
<NAMESPACE>/<NAME>/<PROVIDER>
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 34/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
// for example
module "consul" {
source = "hashicorp/consul/aws"
version = "0.1.0"
<HOSTNAME>/<NAMESPACE>/<NAME>/<PROVIDER>
// for example
module "vpc" {
source = "app.terraform.io/example_corp/vpc/aws"
version = "0.9.3"
130. The terraform recommends that all modules must follow semantic versioning.
Is this true?
True
* Organize configuration
* Encapsulate configuration
* Re-use configuration
https://learn.hashicorp.com/terraform/modules/modules-overview
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 35/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
https://learn.hashicorp.com/terraform/modules/modules-
overview#module-best-practices
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 36/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
136. What are the different source types for calling modules?
Local paths
Terraform Registry
GitHub
Bitbucket
HTTP URLs
S3 buckets
GCS buckets
https://www.terraform.io/docs/modules/sources.html
137. What are the arguments you need for using modules in your configuration?
// example
module "consul" {
source = "hashicorp/consul/aws"
version = "0.1.0"
On the Terraform registry page for the AWS VPC module, you will see
an Inputs tab that describes all of the input variables that module
supports.
For example, we have defined a lot of input variables for the modules such as ads, cidr,
name, etc
1 provider "aws" {
2 region = "us-west-2"
3 }
4
5 module "vpc" {
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 37/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
6 source = "terraform-aws-modules/vpc/aws"
7 version = "2.21.0"
8
9 name = var.vpc_name
10 cidr = var.vpc_cidr
11
12 azs = var.vpc_azs
13 private_subnets = var.vpc_private_subnets
14 public_subnets = var.vpc_public_subnets
15
16 enable_nat_gateway = var.vpc_enable_nat_gateway
17
18 tags = var.vpc_tags
19 }
20
21 module "ec2_instances" {
22 source = "terraform-aws-modules/ec2-instance/aws"
23 version = "2.12.0"
24
25 name = "my-ec2-cluster"
26 instance_count = 2
27
28 ami = "ami-0c5204531f799e0c6"
29 instance_type = "t2.micro"
30 vpc_security_group_ids = [module.vpc.default_security_group_id]
31 subnet_id = module.vpc.public_subnets[0]
32
33 tags = {
34 Terraform = "true"
35 Environment = "dev"
36 }
37 }
main.tf
hosted with ❤ by GitHub view raw
main.tf
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 38/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
1 output "vpc_public_subnets" {
2 description = "IDs of the VPC's public subnets"
3 value = module.vpc.public_subnets
4 }
5
6 output "ec2_instance_public_ips" {
7 description = "Public IP addresses of EC2 instances"
8 value = module.ec2_instances.public_ip
9 }
outputs.tf
hosted with ❤ by GitHub view raw
outputs.tf
variable "vpc_name" {
type = string
default = "example-vpc"
Then you can access these varibles in the configuration like this
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.21.0"
name = var.vpc_name
cidr = var.vpc_cidr
azs = var.vpc_azs
private_subnets = var.vpc_private_subnets
public_subnets = var.vpc_public_subnets
enable_nat_gateway = var.vpc_enable_nat_gateway
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 39/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
tags = var.vpc_tags
143. When you use local modules you don’t have to do the command init or get every
time there is a change in the local module. why?
144. When you use remote modules what should you do if there is a change in the
module?
145. A simple configuration consisting of a single directory with one or more .tf files
is a module. Is this true?
True
146. When using a new module for the first time, you must run either terraform
True
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 40/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
147. When installing the modules and where does the terraform save these modules?
.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
source
149. What are the other optional meta-arguments along with the source when
defining modules
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 41/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
https://www.terraform.io/guides/core-workflow.html#working-as-an-
individual-practitioner
https://www.terraform.io/guides/core-workflow.html#working-as-a-team
https://www.terraform.io/guides/core-workflow.html#the-core-
workflow-enhanced-by-terraform-cloud
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 42/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
This is the first command that should be run after writing a new
Terraform configuration or cloning an existing one from version
control.
155. You recently joined a team and you cloned a terraform configuration files from
the version control system. What is the first command you should use?
terraform init
Though subsequent runs may give errors, this command will never
delete your existing configuration or state.
https://www.terraform.io/docs/commands/init.html
156. What is the flag you should use to upgrade modules and plugins a part of their
respective installation steps?
upgrade
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 43/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
157. When you are doing initialization with terraform init, you want to skip
backend initialization. What should you do?
158. When you are doing initialization with terraform init, you want to skip child
module installation. What should you do?
159. When you are doing initialization where do all the plugins stored?
on Windows : %APPDATA%\terraform.d\plugins
160. When you are doing initialization with terraform init, you want to skip plugin
installation. What should you do?
https://www.terraform.io/docs/commands/validate.html
https://www.terraform.io/docs/commands/apply.html
164. You are applying the infrastructure with the command apply and you don’t
want to do interactive approval. Which flag should you use?
https://www.terraform.io/docs/commands/apply.html
166. How do you preview the behavior of the command terraform destroy?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 45/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
Implicit dependency:
Explicit dependency:
provider "aws" {
profile = "default"
region = "us-east-1"
ami = "ami-b374d5a5"
instance_type = "t2.micro"
vpc = true
instance = aws_instance.example.id
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 46/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
bucket = "some_bucket"
acl = "private"
ami = "ami-2757f631"
instance_type = "t2.micro"
depends_on = [aws_s3_bucket.example]
171. You have started writing terraform configuration and you are using some
sample configuration as a basis. How do you copy the example configuration into
your working directory?
https://www.terraform.io/docs/commands/init.html#copy-a-source-
module
172. What is the flag you should use with the terraform plan to get detailed on the
exit codes?
Return a detailed exit code when the command exits. When provided,
this argument changes the exit codes and their meanings to provide
more granular information about what the resulting plan contains:
* 1 = Error
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 47/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
173. How do you target only specific resources when you run a terraform plan?
174. How do you update the state prior to checking differences when you run a
terraform plan?
175. The behavior of any terraform destroy command can be previewed at any time
with an equivalent terraform plan -destroy command. Is this true?
True
176. You have the following file and created two resources docker_image and
docker_container with the command terraform apply and you go to the terminal
and delete the container with the command docker rm. You come back to your
configuration and run the command again. Does terraform recreates the resource?
i tf h t d ith ❤ b GitH b i
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 48/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
main.tf
hosted with ❤ by GitHub view raw
main.tf
Yes. Terrsform creates the resource again since the execution plan
says two resources and the terraform always maintains the desired
state
177. You created a VM instance on AWS cloud provider with the terraform
configuration and you log in AWS console and removed the instance. What does the
next apply do?
178. You have the following file and created two resources docker_image and
docker_container with the command terraform plan and you go to the terminal and
delete the container with the command docker rm. You come back to your
configuration and run the command again. What is the output of the command
plan?
main.tf
hosted with ❤ by GitHub view raw
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 49/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
The local backend stores state on the local filesystem, locks that
state using system APIs, and performs operations locally.
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 50/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
// Example
terraform {
backend "local" {
path = "relative/path/to/terraform.tfstate"
If supported by your backend, Terraform will lock your state for all
operations that could write state. This prevents others from
acquiring the lock and potentially corrupting your state.
No.
Yes.
You can disable state locking for most commands with the -lock flag
but it is not recommended.
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 51/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
Remote state storage makes collaboration easier and keeps state and
secret information off your local disk.
188. If you want to switch from using remote backend to local backend. What
should you do?
If you want to move back to local state, you can remove the backend
configuration block from your configuration and run terraform init
again.
Terraform will once again ask if you want to migrate your state back
to local.
This can be used to detect any drift from the last-known state, and
to update the state file.
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 52/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
The command refresh does not modify infrastructure, but does modify
the state file.
If the state is changed, this may cause changes to occur during the
next plan or apply.
193. What are the ways to provide remaining arguments when using partial
configuration?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 53/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
https://www.terraform.io/docs/backends/config.html
// Example
terraform {
backend "consul" {}
terraform init \
-backend-config="address=demo.consul.io" \
-backend-config="path=example_app/terraform_state" \
-backend-config="scheme=https"
If you no longer want to use any backend, you can simply remove the
configuration from the file. Terraform will detect this like any
other change and prompt you to reinitialize.
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 54/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
200. Why should you be very careful with the Force unlocking the state?
Be very careful with this command. If you unlock the state when
someone else is holding the lock it could cause multiple writers.
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 55/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
Force unlock should only be used to unlock your own lock in the
situation where automatic unlocking failed.
201. You should only use force unlock command when automatic unlocking fails. Is
this true?
True
variable "region" {
default = "us-east-1"
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 56/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
// accessing a variable
provider "aws" {
region = var.region
204. How many ways you can assign variables in the configuration?
Command-line flags
From a file
region = "us-east-1"
terraform apply \
-var-file="secret.tfvars" \
-var-file="production.tfvars"
UI input
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 57/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
No
You can use different varible files with the same configuration
// Example
// For development
// For test
variable "region" {
default = "us-east-1"
string
number
bool
list(<TYPE>)
set(<TYPE>)
map(<TYPE>)
tuple([<TYPE>, ...])
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 58/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
variable "availability_zone_names" {
type = list(string)
default = ["us-west-1a"]
variable "region" {}
variable "amis" {
type = map(string)
amis = {
"us-east-1" = "ami-abc123"
"us-west-2" = "ami-def456"
// accessing
ami = var.amis[var.region]
instance_type = "t2.micro"
* Environment variables
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 59/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
* Any -var and -var-file options on the command line, in the order
they are provided. (This includes variables set by a Terraform Cloud
workspace.)
output "ip" {
value = aws_eip.ip.public_ip
You will see the output when you run the following command
terraform apply
terraform output ip
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 60/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
A dynamic block acts much like a for expression, but produces nested
blocks instead of a complex typed value. It iterates over a given
complex value, and generates a nested block for each element of that
complex value.
https://www.terraform.io/docs/configuration/expressions.html#dynamic
-blocks
example.tf
hosted with ❤ by GitHub view raw
max(5, 12, 9)
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 61/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
No
100
https://www.terraform.io/docs/configuration/functions/abs.html
220. What is the built-in function to evaluates given expression and returns a
boolean whether the expression produced a result without any errors?
can
https://www.terraform.io/docs/configuration/functions/can.html
221. What is the built-in function to evaluates all of its argument expressions in
turn and returns the result of the first one that does not produce any errors?
try
locals {
example = try(
[tostring(var.example)],
tolist(var.example),
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 62/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
module.A.module.B.module.C...
resource_type.resource_name[resource index]
// Examples
# ...
count = 4
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 63/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
# ...
for_each = {
"terraform": "value1",
"resource": "value2",
"indexing": "value3",
"example": "value4",
225. What are complex types and what are the collection types Terraform supports?
226. What are the named values available and how do we refer to?
227. What is the built-in function that reads the contents of a file at the given path
and returns them as a base64-encoded string?
filebase64(path)
https://www.terraform.io/docs/configuration/functions/filebase64.htm
l
228. What is the built-in function that converts a timestamp into a different time
format?
formatdate(spec, timestamp)
https://www.terraform.io/docs/configuration/functions/formatdate.htm
l
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 65/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
229. What is the built-in function encodes a given value to a string using JSON
syntax?
jsonencode({"hello"="world"})
https://www.terraform.io/docs/configuration/functions/jsonencode.htm
l
230. What is the built-in function that calculates a full host IP address for a given
host number within a given IP network address prefix?
10.12.112.16
https://www.terraform.io/docs/configuration/functions/cidrhost.html
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 66/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
https://www.hashicorp.com/blog/why-policy-as-code/
234. What is the difference between public and private module registries when
defined source?
// example
module "vpc" {
source = "app.terraform.io/example_corp/vpc/aws"
version = "1.0.4"
https://registry.terraform.io/
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 67/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
https://www.hashicorp.com/resources/terraform-enterprise-
understanding-workspaces-and-modules/
238. You are configuring a remote backend in the terraform cloud. You didn’t create
an organization before you do terraform init. Does it work?
239. You are configuring a remote backend in the terraform cloud. You didn’t create
a workspace before you do terraform init. Does it work?
240. Terraform workspaces when you are working with CLI and Terraform
workspaces in the Terraform cloud. Is this correct?
If you are familiar with running Terraform using the CLI, you may
have used Terraform workspaces. Terraform Cloud workspaces behave
differently than Terraform CLI workspaces. Terraform CLI workspaces
allow multiple state files to exist within a single directory,
enabling you to use one configuration for multiple environments.
Terraform Cloud workspaces contain everything needed to manage a
given set of infrastructure, and function like separate working
directories.
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 68/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
241. How do you authenticate the CLI with the terraform cloud?
Newer Versions:
1. terraform login
https://learn.hashicorp.com/terraform/tfc/tfc_login
Older versions:
credentials "app.terraform.io" {
token = "xxxxxx.atlasv1.zzzzzzzzzzzzz"
https://www.terraform.io/docs/commands/cli-config.html#credentials
242. You are building infrastructure on your local machine and you changed your
backend to remote backend with the Terraform cloud. What should you do to
migrate the state to the remote backend?
terraform init
https://learn.hashicorp.com/terraform/tfc/tfc_migration#migrate-the-
state-file
243. How do you configure remote backend with the terraform cloud?
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 69/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
terraform {
backend "remote" {
hostname = "app.terraform.io"
organization = "<YOUR-ORG-NAME>"
workspaces {
name = "state-migration"
246. What are the available permissions that terraform clouds can have?
Team Plan
Even if your team member has not signed up for Terraform Cloud yet,
they can still accept the invitation and create a new account.
250. The Terraform Cloud Team plan charges you on a per-user basis. Is this true?
Conclusion
The Terraform associate exam is multiple-choice, multiple answers, text-based, exam.
These sample questions definitely help you prepare for the certification. I would
recommend you go through the documentation first and then refer to this afterward or
right before the exam.
Tutorials Ranging from Beginner guides to advanced on Frontend, Backend, Blockchain, Docker, k8s,
DevOps, Cloud,AI, ML. Thank you for subscribing and let me know if you want me cover anything?
Take a look.
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 71/72
17/01/2022, 23:18 250 Practice Questions For Terraform Associate Certification | by Bhargav Bachina | Bachina Labs | Medium
https://medium.com/bb-tutorials-and-thoughts/250-practice-questions-for-terraform-associate-certification-7a3ccebe6a1a 72/72