Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Terraform Quiz

Total questions: 49

Worksheet time: 35mins

Name
Class
Date
1.

Which of the following statements represents the most accurate statement about the Terraform language?

a)
  • Terraform is a mutable, imperative, Infrastructure as Code provisioning language based on Hashicorp Configuration Language, or optionally YAML.

b)
  • Terraform is an immutable, declarative, Infrastructure as Code provisioning language based on Hashicorp Configuration Language, or optionally JSON.

c)
  • Terraform is a mutable, declarative, Infrastructure as Code configuration management language based on Hashicorp Configuration Language, or optionally JSON.

d)
  • Terraform is an immutable, imperative, Infrastructure as Code configuration management language based on Hashicorp Configuration Language, or optionally JSON.

2.

Why might a user opt to include the following snippet in their configuration file?

  1. terraform {

  2. required_version = ">= 1.9.2"

  3. }

a)

The user wants to specify the minimum version of Terraform that is required to run the configuration

b)
  • The user wants to ensure that the application being deployed is a minimum version of 1.9.2

c)
  • versions before Terraform 1.9.2 were not approved by HashiCorp to be used in production

d)
  • this ensures that all Terraform providers are above a certain version to match the application being deployed

3.

Which of the following are tasks that terraform apply can perform? (select three)

a)
  • import existing infrastructure

b)
  • provision new infrastructure

c)
  • update existing infrastructure with new configurations

d)
  • destroy infrastructure previously deployed with Terraform

4.

Your organization has multiple engineers that have permission to manage Terraform as well as administrative access to the public cloud where these resources are provisioned. If an engineer makes a change outside of Terraform, what command can you run to detect drift and update the state file?

a)
  • terraform get

b)
  • terraform init

c)
  • terraform state list

d)
  • terraform apply -refresh-only

5.

Infrastructure as Code (IaC) provides many benefits to help organizations deploy application infrastructure much faster than manually clicking in the console. Which is NOT an additional benefit to IaC?

a)
  • allows infrastructure to be versioned

b)
  • eliminates API communication to the target platform

c)
  • code can easily be shared and reused

d)
  • creates self-documenting infrastructure

6.

Rather than having to scan and inspect every resource on every run, Terraform relies on what feature to help manage resources?

a)
  • local variables

b)
  • state

c)
  • providers

d)
  • environment variables

7.

What feature does Terraform use to map configuration to resources in the real world?

a)
  • state

b)
  • parallelism

c)
  • resource blocks

d)
  • local variables

8.

Given the code snippet below, how would you identify the arn to be used in the output block that was retrieved by the data block?

  1. ```
    data "aws_s3_bucket" "data-bucket" {

  2. bucket = "my-data-lookup-bucket-btk"

  3. }

  4. ...

  5.  

  6. output "s3_bucket_arn" {

  7. value = ????

  8. }

  • ```

a)
b)
c)
d)
9.

True or False? When referencing a module, you must specify the version of the module in the calling module block.

a)

True

b)

False

10.

You've included two different modules from the official Terraform registry in a new configuration file. When you run a terraform init, where does Terraform OSS download and store the modules locally?

a)
  • in the same root directory where the Terraform configuration files are stored

b)
  • Terraform stores them in memory on the machine running Terraform

c)
  • in the .terraform/modules folder in the working directory

d)
  • in the /tmp directory of the machine executing Terraform

11.

Given the definition below, what Terraform feature is being described?

"helps you share Terraform providers and Terraform modules across your organization. It includes support for versioning, a searchable list of available providers and modules, and a configuration designer to help you build new workspaces faster."

a)
  • Terraform Workspaces

b)
  • Private Registry

c)
  • CDK for Terraform

d)
  • HashiCorp Sentinel

12.

Which statement below is true regarding using Sentinel in Terraform Enterprise?

a)
  • Sentinel can extend the functionality of user permissions in Terraform Enterprise

b)
  • Sentinel runs before each phase of the Terraform workflow, meaning a terraform init, terraform plan, and terraform apply

c)
  • Sentinel policies can be developed using HCL, JSON, or YAML

d)
  • Sentinel runs before a configuration is applied, therefore potentially reducing cost for public cloud resources

13.

True or False? Infrastructure as code (IaC) tools allow you to manage infrastructure with configuration files rather than through a graphical user interface.

a)
  • False

b)
  • True

14.

A child module created a new subnet for some new workloads. What Terraform block type would allow you to pass the subnet ID back to the parent module?

a)
  • resource block

b)
  • output block

c)
  • data block

d)
  • terraform block

15.

You have a number of different variables in a parent module that calls multiple child modules. Can the child modules refer to any of the variables declared in the parent module?

a)
  • Yes, child modules can refer to any variable in a parent module

b)
  • Not the variable, but it can only refer to values that are passed to the child module

c)
  • No, child modules can never refer to any variables or values declared in the parent module

16.

Both you and a colleague are responsible for maintaining resources that host multiple applications using Terraform CLI. What feature of Terraform helps ensure only a single person can update or make changes to the resources Terraform is managing?

a)
  • version control

b)
  • local backend

c)
  • state locking

d)
  • provisioners

17.

The command `terraform destroy` is actually just an alias to which command?

a)
  • terraform apply -replace-all

b)
  • terraform plan - destroy

c)
  • terraform delete

d)
  • terraform apply -destroy

18.

Beyond storing state, what capability can an enhanced storage backend, such as the remote backend, provide your organization?

a)
  • allow multiple people to execute operations on the state file at the same time

b)
  • execute your Terraform on infrastructure either locally or in Terraform Cloud

c)
  • replicate your state to a secondary location for backup

d)
  • provides versioning capabilities on your state file in the event it becomes corrupted

19.

What command can be used to display the resources that are being managed by Terraform?

a)
  • terraform output

b)
  • terraform version

c)
  • terraform show

d)
  • terraform state rm

20.

You need to enable logging for Terraform and persist the logs to a specific file. What two environment variables can be set to enable logs and write them to a file? (select two)

a)
  • TF_LOG_OUTPUT="<file_path>"

b)
  • TF_LOG=TRACE

c)
  • TF_LOG_PATH="<file_path>"

d)
  • TF_ENABLE_LOG=true

21.

Based on the code snippet below, where is the module that the code is referencing?

  1. module "server_subnet_1" {

  2. source = "./modules/web_server"

  3. ami = data.aws_ami.ubuntu.id

  4. key_name = aws_key_pair.generated.key_name

  5. user = "ubuntu"

  6. private_key = tls_private_key.generated.private_key_pem

  7. subnet_id = aws_subnet.public_subnets["public_subnet_1"].id

  8. security_groups = [aws_security_group.vpc-ping.id, aws_security_group.vpc-web.id]

  9. }

a)
  • stored in a private registry managed by the organization

b)
  • in the modules subdirectory in the current working directory where Terraform is being executed

c)
  • the same working directory where Terraform is being executed

d)
  • stored in the Terraform public registry

22.

What is NOT a benefit of using Infrastructure as Code?

a)
  • the reduction of misconfigurations that could lead to security vulnerabilities and unplanned downtime

b)
  • the ability to programmatically deploy infrastructure

c)
  • reducing vulnerabilities in your publicly-facing applications

d)
  • your infrastructure configurations can be version controlled and stored in a code repository alongside the application code

23.

True or False? You can use a combination of Terraform Cloud's cost estimation feature and Sentinel policies to ensure your organization doesn't apply changes to your environment that would result in exceeding your monthly operating budget.

a)
  • False

b)
  • True

24.

What is the primary language used by terraform to define resources and infrastructure?

a)

YAML

b)

JSON

c)

HCL

d)

XML

25.

How would you define Terraform?

a)

A configuration management tool

b)

An orchestration tool

c)

An infrastructure as code tool

d)

A continuous integration tool

26.

What does the terraform plan command do?

a)

Applies the changes required to reach the desired state of the configuration

b)

Shows the execution plan for the changes required to reach the desired state

c)

Initializes the configuration

d)

Deletes the resources defined in the configuration

27.

You are provisioning a set of virtual machines using Terraform, each with its own set of tags(key-value pairs) for classification and organization. Which collection type in Terraform would be most suitable for representing the set of tags for each virtual machine?

a)

list

b)

set

c)

object

d)

map

28.

You want to inspect the details of resources managed by Terraform within your project. Which Terraform command should you use?

a)

terraform plan

b)

terraform apply

c)

terraform show

d)

terraform state list

29.

You want to list all resources tracked by Terraform within your project. Which Terraform command would provide you with this information?

a)

terraform state list

b)

terraform state show

c)

terraform state pull

d)

terraform state refresh

30.

Terraform relies on state in order to create and manage resources. Which of the following is true regarding the state file? (select four)

a)
  • remote state is required when more than one person wants to manage the infrastructure managed by Terraform

b)
  • state should be modified by editing the file directly

c)
  • by default, state is stored in a file named terraform.tfstate in the current working directory

d)
  • it may contain sensitive data that you might not want others to view

e)
  • the state file is formatted using JSON

31.

As you are developing new Terraform code, you are finding that you are constantly repeating the same expression over and over throughout your code, and you are worried about the effort that will be needed if this expression needs to be changed. What feature of Terraform can you use to avoid repetition and make your code easier to maintain?

a)
  • remote backend

b)
  • data block

c)
  • locals

d)
  • terraform graph

32.

You need to set the value for a Terraform input variable. Which of the following allows you to set the value using an environment variable?

a)
  • export TF_VARIABLE_app=eCommerce01

b)
  • export TF_VAR_user=dbadmin01

c)
  • export VAR_database=prodsql01

d)
  • export TF_db-pass=P@ssw0rd01!

33.

What actions does a terraform init perform for you?

a)
  • ensures that all Terraform files match the canonical formatting and style

b)
  • compares the current configuration to the prior state and notes any differences

c)
  • ensures any configuration file that ends with a .tf file extension is syntactically valid and internally consistent

d)
  • downloads plugins and retrieves the source code for referenced modules

34.

True or False? A provider block is required in every configuration file so Terraform can download the proper plugin.

a)

True

b)

False

35.

True or False? In Terraform OSS, workspaces generally use the same code repository while workspaces in Terraform Enterprise/Cloud are often mapped to different code repositories.

a)

True

b)

False

36.

True or False? Running a terraform apply will fail if you do not run a terraform plan first.

a)

True

b)

False

37.

Which of the following code snippets will ensure you're using a specific version of the AWS provider?

a)
  • terraform {

    • required_version = ">= 3.0"

    • }

b)
  • provider "aws" {

    • region = "us-east-1"

    • required_provider ">= 3.0"

    • }

c)
  • provider "aws" {

    • region = "us-east-2"

    • required_version ">= 3.0"

    • }

d)
  • terraform {

    • required_providers {

    • aws = ">= 3.0"

    • }

    • }

38.

You need to define a single input variable to support the IP address of a subnet, which is defined as a string, and the subnet mask, which is defined as a number. What type of variable variable should you use?

a)
  • type = bool

b)
  • type = string

c)
  • type = object ()

d)
  • type = map ()

39.

You want to restrict your team members to specific modules that are approved by the organization's security team when using Terraform Cloud. What feature should you use?

a)
  • Terraform Registry (public)

b)
  • Terraform Workspaces

c)
  • Terraform Cloud Private Registry

d)
  • Terraform Cloud Organizations

40.

Given the following code snippet, what is the managed resource name for this particular resource?

  1. resource "aws_vpc" "prod-vpc" {

  2. cidr_block = var.vpc_cidr

  3.  

  4. tags = {

  5. Name = var.vpc_name

  6. Environment = "demo_environment"

  7. Terraform = "true"

  8. }

  9.  

  10. enable_dns_hostnames = true

  11. }

a)
  • aws_vpc

b)
  • demo environment

c)
  • prod-vpc

41.

Which of the following Terraform versions would be permitted to run the Terraform configuration based on the following code snippet?

  1. terraform {

  2. required_version = "~> 1.0.0"

  3. required_providers {

  4. aws = {

  5. source = "hashicorp/aws"

  6. version = "~> 3.0"

  7. }

  8. random = {

  9. source = "hashicorp/random"

  10. version = "3.1.0"

  11. }

  12. }

  13. }

a)
  • Terraform v1.1.0

b)
  • Terraform v1.4.9

c)
  • Terraform v1.0.5

d)
  • Terraform v1.2.0

42.

Which of the following is an advantage of using Infrastructure as Code?

a)
  • elimination of security vulnerabilities in your application deployment workflow

b)
  • standardize your deployment workflow

c)
  • simplification of using a user interface to define your infrastructure

d)
  • increase the time to market for application deployment

43.

Your colleague provided you with a Terraform configuration file and you're having trouble reading it because parameters and blocks are not properly aligned. What command can you run to quickly update the file configuration file to make it easier to consume?

a)
  • terraform fmt

b)
  • terraform workspace

c)
  • terraform state

d)
  • terraform init

44.

You have declared the variable as shown below. How should you reference this variable throughout your configuration?

  1. variable "aws_region" {

  2. type = string

  3. description = "region used to deploy workloads"

  4. default = "us-east-1"

  5. validation {

  6. condition = can(regex("^us-", var.aws_region))

  7. error_message = "The aws_region value must be a valid region in the USA, starting with \"us-\"."

  8. }

  9. }

45.

By default, where does Terraform CLI store its state?

a)
  • in the terraform.tfstate file on the local backend

b)
  • in the default workspace in Terraform Cloud

c)
  • in a temp directory on the local machine executing the Terraform configurations

d)
  • in the .terraform directory within the current working directory

46.

After hours of development, you've created a new Terraform configuration from scratch and now you want to test it. Before you can provision the resources, what is the first command that you should run?

a)
  • terraform validate

b)
  • terraform init

c)
  • terraform import

d)
  • terraform apply

47.

You are having trouble with executing Terraform and want to enable the most verbose logs. What log level should you set for the TF_LOG environment variable?

a)
  • INFO

b)
  • DEBUG

c)
  • TRACE

d)
  • ERROR

48.

After deploying a new virtual machine using Terraform, you find that the local script didn't run properly. However, Terraform reports the virtual machine was successfully created. How can you force Terraform to replace the virtual machine without impacting the rest of the managed infrastructure?

a)
  • run a terraform destroy and then run terraform import to pull in the other resources under Terraform management

b)
  • use terraform apply -replace to tag the resource for replacement

c)
  • execute a terraform debug command to see why the script failed to run

d)
  • update the virtual machine resource and run a terraform init

49.

Where is the most secure place to store credentials when using a remote backend?

a)
  • environment variables

b)
  • defined outside of Terraform

c)
  • in the backend configuration block where the remote state location is defined

d)