Font size
WorksheetsTFTJS
Total questions: 68
Worksheet time: 34mins
Which command initializes the terraform configuration?
terraform start
terraform init
terraform fmt
terraform apply
What does the terraform plan command do?
Applies the changes required to reach the desired state of the configuration
Shows the execution plan for the changes required to reach the desired state
Initializes the configuration
Deletes the resources defined in the configuration
When checking the syntax of Terraform configuration files, which command ought to be executed?
terraform check
terraform validate
terraform plan
terraform fmt
What happens when you apply Terraform configuration? Choose TWO correct answers.
Terraform makes any infrastructure changes that are defined in your configuration.
Terraform gets the plugins that the configuration requires.
Terraform updates the state file with the configuration changes it made.
Terraform will destroy and recreate all your infrastructure from scratch.
What is the workflow for deploying new infrastructure when using Terraform?
Use the Terraform plan command to import the current infrastructure to the state file, make code changes, and run the Terraform apply command to update the infrastructure.
Write the Terraform configuration, run the terraform show command to view proposed changes, and run terraform apply to create the new infrastructure.
Terraform import is used to import the current infrastructure to the state file, make code changes, and apply terraform to update the infrastructure.
Write a Terraform configuration, run Terraform init, run Terraform plan to view planned infrastructure changes, and terraform apply to create new infrastructure.
How do you specify a provider in a Terraform configuration file?
provider "name" { }
module "name" { }
resource "name" { }
data "name" { }
What is the default file name where Terraform stores its state locally?
state.tf
terraform.state
terraform.tfstate
terraform.tf.state
Does running 'terraform init' automatically initialize a file named 'main.tf'
Yes
No
In the context of Terraform, what does "Desired State Management" refer to?
The current configuration of the infrastructure
The configuration that should be applied to the infrastructure
The historical state of the infrastructure
The default settings of the infrastructure
If we need to destroy the Terraform-managed infrastructure using terraform destroy command without confirmation which option should we use?
-auto-noapprove
-auto-proceed
-auto-destroy
-auto-approve
We have copied a sample terraform code from a GitHub repository to his local terraform configuration file.
There are certain formatting issues in the code.
resource "aws_instance" "cloudthat-ec2" {
ami = "ami-090fa75af13c156b4"
instance_type = "m5.large"
count = 5
}
Which command can we run to ensure that code is automatically formatted?
terraform code format
terraform format
terraform fmt
none of the given
Code in the Terraform language is stored in files with the ........... file extension
.tf
.yml
.sh
.terra
Terraform commands order ………….
terraform init,terraform plan,terraform apply,terraform destroy
terraform init,terraform apply,terraform plan,terraform destroy
terraform plan,terraform init,terraform apply,terraform destroy
terraform apply,terraform plan,terraform init,terraform destroy
There is a requirement to save a terraform plan to a specific file.
Which of the following command can be used to achieve this use-case?
terraform plan out <filename>
terraform output plan <filename>
terraform plan -out=<filename>
terraform plan <filename>
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?
list
set
object
map
Terraform apply creates an EC2 instance (name: example)
We want Terraform to display the private_ip of the EC2 after creation automatically. How can we do this?
output "privateip"
{
value = aws_instance.example.private_ip
}
input "privateip"
{
value = aws_instance.example.private_ip
}
data "privateip"
{
value = aws_instance.example.private_ip
}
output "privateip"
{
value = example.private_ip
}
What is the purpose of the "terraform.tfvars" file?
To define variables that are specific to a particular environment
To define variables that are automatically loaded by Terraform
To manage state
To define providers
Your Terraform configuration deployed a web application, including an AWS EC2 instance. Now, you require the public IP address of the instance.
Execute terraform show and search for the public IP address in the output.
Use the AWS Management Console to locate the public IP address.
Check the terraform.tfstate file for the public IP address.
Run terraform output and specify the name of the output variable containing the public IP address.
What is the main purpose of using locals in Terraform?
To define resources that are only available within the local network and not accessible from the internet.
To define reusable values or expressions that can be referenced within the Terraform configuration.
To create remote connections to other Terraform configurations or infrastructure deployments.
To manage the state of Terraform resources and track changes over time.
Which block is used to define local values in Terraform?
(a)
You are managing a Terraform configuration for deploying a network infrastructure. You need to retrieve a value from a map based on a specific key. Which function should you use?
get()
lookup()
find()
search()
Which Terraform function is used to retrieve a specific element from a list?
lookup()
fetch()
search()
element()
Can we create a function and use it in our terraform configuration?
No
Yes
Which data structure in Terraform is used to store unique values without any specific order?
list
set
map
tuple
Which of the following best describes a Terraform data source?
A plugin to extend Terraform's functionality.
A mechanism to retrieve information from external systems for use in your configuration.
A module to provision infrastructure resources.
A backend storage for Terraform state files.
Your organization has been managing AWS resources manually or with another tool, and now you are transitioning to using Terraform for infrastructure as code. You need to reference existing VPCs, subnets, and security groups that were created outside of Terraform to avoid duplicating infrastructure and ensure consistency. Which option is most suitable?
By storing state files remotely.
By defining output variables.
By using version control for configuration files.
By using data sources
Usernames and passwords referenced in the Terraform code, even as variables, will end up in plain text in the state file.
True
False
You write a new Terraform configuration and immediately run terraform apply in the CLI using the local backend. Why will the apply fail?
Terraform needs you to format your code according to best practices first
Terraform needs to install the necessary plugins first
The Terraform CLI needs you to log into Terraform cloud first
Terraform requires you to manually run terraform plan first
Your team is collaborating on a Terraform project, and you're concerned about potential conflicts when multiple team members try to apply changes simultaneously. Which feature of Terraform helps prevent such conflicts?
State management
Locking
State commands
Terraform Cloud
You want to inspect the details of resources managed by Terraform within your project. Which Terraform command should you use?
terraform plan
terraform apply
terraform show
terraform state list
You want to list all resources tracked by Terraform within your project. Which Terraform command would provide you with this information?
terraform state list
terraform state show
terraform state pull
terraform state refresh
In your Terraform project, you have accidentally deleted an EC2 resource outside of Terraform, and now you need to remove it from Terraform's state file to avoid conflicts. Which Terraform command should you use to remove the resource from the state file?
terraform state remove aws_instance.example
terraform state rm aws_instance.example
terraform state delete aws_instance.example
terraform state clean aws_instance.example
Where in your Terraform configuration do you specify a state backend?
The terraform block
The resource block
The provider block
The datasource block
You suspect there might be issues with your current state file and want to manually inspect its contents. Which command would you use to download and view the state file in JSON format?
terraform state show
terraform state pull
terraform plan
terraform state list
You need to inspect the details of a specific resource within your state file to verify its attributes. Which command should you use?
terraform state list
terraform state show
terraform plan
terraform state mv
You want to clean up your state file by removing resources that are no longer needed, but you want to confirm the exact resource names first. Which sequence of commands should you use?
terraform plan followed by terraform destroy
terraform state list followed by terraform state rm
terraform state show followed by terraform state rm
terraform apply followed by terraform state rm
What is the default backends used by terraform CLI?
Terraform Cloud
Consul
Remote
Local
What does the default "local" Terraform backend store?
tfplan files
Terraform binary
Provider plugins
State file
what contains a terraform state?
The mapping of the resource's configuration
Information of the real infrastructure
Metadata of the resources created
Why is it useful to use remote backends?
To work in a team
for remote operations
for state locking
By default, where does Terraform store its state file?
remotely using Terraform Cloud
current working directory
shared directory
Amazon S3 bucket
Which of these provisioners can execute a command on the machine where Terraform is run?
remote-exec
local-exec
script-exec
manual-exec
Which provisioner would you use to transfer files to a remote machine in Terraform?
file
upload-exec
remote-exec
local-exec
What is the key difference between local-exec and remote-exec provisioners in Terraform?
local-exec runs on the target resource, and remote-exec runs on the local machine
local-exec runs on the local machine, and remote-exec runs on the target resource
local-exec runs before resource creation, while remote-exec runs after
There is no difference; both run the same commands
When using the file provisioner in Terraform, which parameter specifies the file to be uploaded?
source
destination
content
remote_path
Which command is used to initialize a backend configuration in Terraform?
terraform init
terraform backend
terraform state
terraform configure
Which connection type is supported by Terraform for connecting to a remote machine for provisioning?
ssh
ftp
http
rdp
Which GCP service is typically used for storing remote state files in Terraform?
Google Cloud Datastore
Google Cloud Storage (GCS)
Google Cloud Bigtable
Google Cloud Functions
Where is the backend block typically located within a Terraform configuration file?
Inside the provider block
At the beginning of the file, outside of any block.
Inside the terraform block.
After the resource definitions
Which of the following actions will NOT trigger a reinitialization of the backend in Terraform?
Changing the backend configuration values
Running terraform plan
Running terraform init -reconfigure
Switching from a local backend to a remote backend
Rahul is working on a project that requires him to create a Virtual Private Cloud (VPC) for his application. He has a module locally located at ./modules/vpc which creates a VPC. How would he correctly use this module in his Terraform configuration?
module "vpc" {
source = "./modules/vpc"
cidr_block = "10.0.0.0/16"
}
module "vpc" {
source = "github.com/modules/vpc"
cidr_block = "10.0.0.0/16"
}
module "vpc" {
path = "./modules/vpc"
cidr_block = "10.0.0.0/16"
}
module "vpc" {
directory = "./modules/vpc"
cidr_block = "10.0.0.0/16"
}
Aarush is trying to find where published modules can be located for his project.
In the root module locally
Only on local filesystems
Inside the Terraform state file
On Public, Private Repositories
What is a child module in Terraform?
The top-level module that Terraform starts with
A module that is only used for testing purposes
A module that contains the Terraform state file
A module that is called from within a root module
Aarav is learning about Terraform for his cloud infrastructure project. What is a Terraform Module?
A Terraform module is a set of Terraform configuration files in a single directory.
A set of configuration files that define the infrastructure
A method to organize Terraform configurations for reusability
All of the above
Aarav is working on a Terraform module for his project. Which of the following parameters is essential to include in a Terraform module's when publishing it?
input variables
output variables
Module Description
Access Keys
What is the primary reason for publishing a module to the Terraform Registry?
To hide the module's source code
To make the module available for other Terraform users, like Sneha and Asher, to use and collaborate on
To prevent any modifications to the module
To increase the complexity of the module
Aarav is working on a project that requires him to reference resources defined within a local module. How does he do this?
By using the module block and specifying the module's path
By importing the resources into the root module using the import command
By defining global variables that reference the local module's resources
By directly accessing the resources within the module's configuration files
Sanya is trying to understand the different source types for calling modules in her project.
Local Paths
Github
Terraform Registry
All of the above
Ishika is trying to understand what the required argument for the module is in her programming assignment.
(a)
Akhil is working on a Terraform project and needs to manage his workspaces. What command should he run to display all workspaces for the current configuration?
terraform workspace
terraform workspace show
terraform workspace list
terraform show workspace
Aarush is working on a project using Terraform. What is a Terraform workspace used for?
To execute Terraform functions
To manage separate state files for different environments.
To define variable values.
To execute Terraform commands
Aanya is managing infrastructure for a software development company with separate environments for development, staging, and production. Each environment requires its own set of infrastructure resources. She decides to use Terraform workspaces to manage these environments efficiently.
Given the scenario described above, which Terraform workspace command should Aanya use to create a new workspace named "staging" to manage infrastructure resources specific to the staging environment?
terraform workspace new staging
terraform workspace create staging
terraform workspace switch staging
terraform workspace add staging
Which Terraform workspace command should Saisha use to switch to the workspace named "project-a" to manage infrastructure resources for the "Project A" team?
terraform workspace switch project-a
terraform workspace select project-a
terraform workspace change project-a
terraform workspace use project-a
What is the correct sequence of actions for Divya to safely delete her workspace in Terraform?
Run terraform workspace delete <workspace-name> directly without any additional steps.
Use terraform destroy to destroy all resources in the workspace, switch to another workspace, and then run terraform workspace delete <workspace-name>.
Switch to another workspace (not the one you want to delete), then run terraform workspace delete <workspace-name>.
Ensure you are in the workspace you want to delete, then run terraform workspace delete <workspace-name>.
Avni is managing her infrastructure using Terraform. She knows that each Terraform CLI Workspace uses its own state file to manage the infrastructure associated with that particular workspace.
False
True
Sneha is learning about Terraform. Where are Terraform Workspace local state files stored?
a directory called terraform.tfstate.d
a temp directory called .tfstate*
a directory called terraform.workspaces.tfstate
a file called terraform.tfstate
Aditi would like to reuse the same Terraform configuration for her development and production environments with a different state file for each. Which command would she use?
terraform import
terraform init
terraform state
terraform workspace
Aanya is using Terraform Cloud for her project. What is the purpose of workspaces in her setup?
To manage different versions of the Terraform CLI
To segregate infrastructure deployments
To store Docker images
To monitor network traffic
