Font size
WorksheetsT4 # 166-220
Total questions: 55
Worksheet time: 55mins
Which of the below commands will rename a EC2 instance without destroying and recreating it?
terraform state mv
terraform mv
terraform plan
terraform plan mv
You want terraform plan and terraform apply to be executed in Terraform Cloud's run environment but the output is to be streamed locally. Which one of the below you will choose?
Local Backends.
Terraform Backends.
This can be done using any of the local or remote backends.
Remote Backends.
A single terraform resource file that defines an aws_instance resource can simply be renamed to vsphere_virtual_machine in order to switch cloud providers.
True
False
A data block requests that Terraform read from a given data source and export the result under the given local name.
True
False
You have multiple developers working on a terraform project (using terraform OSS), and have saved the terraform state in a remote S3 bucket . However ,team is intermittently experiencing inconsistencies in the provisioned infrastructure / failure in the code . You have traced this problem to simultaneous/concurrent runs of terraform apply command for 2/more developers . What can you do to fix this problem?
Use terraform workspaces feature, this will fix this problem by default , as every developer will have their own state file , and terraform will merge them on server side on its own.
Structure your team in such a way that only one individual will run terraform apply , everyone will just make changes and share with him. Then there will be no chance of any inconsistencies.
Stop using remote state , and store the developer tfstate in their own machine . Once a day , all developers should sit together and merge the state files manually , to avoid any inconsistencies.
Enable terraform state locking for the S3 backend using DynamoDB table. This prevents others from acquiring the lock and potentially corrupting your state.
You have created an AWS EC2 instance of type t2.micro through your terraform configuration file ec2.tf . Now you want to change the instance type from t2.micro to t2.medium. Accordingly you have changed your configuration file and and ran terraform plan. After running terraform plan you check the output and saw one instance will be updated from t2.micro --> t2.medium. After this you went to grab a coffee without running terraform apply and meanwhile a member of your team changed the instance type of that EC2 instance to t2.medium from aws console. After coming to your desk you run terraform apply. What will happen?
No resource will be updated and you will see the message : Apply Complete ! Resources : 0 added, 0 changed, 0 destroyed.
The instance type will be changed to t2.micro and again will be changed to t2.medium
terraform apply will through an error.
1 resource will be updated and you will see the message : Apply Complete ! Resources : 0 added, 1 changed, 0 destroyed.
Which of the below datatype is not supported by Terraform.
Array
List
Object
Map
Which of the following value will be accepted for var1?
variable "var1" {
type = string
}
None of the above
Both A and B
"5"
5
When multiple engineers start deploying infrastructure using the same state file, what is a feature of remote state storage that is critical to ensure the state doesn't become corrupt?
Object Storage
State Locking
WorkSpaces
Encryption
Once a resource is marked as tainted, the next plan will show that the resource will be _________ and ___________ and the next apply will implement this change.
recreated and tainted
destroyed and not recreated
tainted and not destroyed
destroyed and recreated
Multiple providers can be declared within a single Terraform configuration file.
True
False
Hanah is writing a terraform configuration with nested modules, there are multiple places where she has to use the same conditional expression but she wants to avoid repeating the same values or expressions multiple times in the configuration,. What is a better approach to dealing with this?
Expressions
Local Values
Variables
Functions
Why is it a good idea to declare the required version of a provider in a Terraform configuration file?
1. terraform
2. {
3. required_providers
4. {
5. aws = "~> 1.0"
6. }
7. }
To remove older versions of the provider.
To ensure that the provider version matches the version of Terraform you are using.
Providers are released on a separate schedule from Terraform itself; therefore a newer version could introduce breaking changes
To match the version number of your application being deployed via Terraform
In regards to Terraform state file, select all the statements below which are correct? Select four
When using local state, the state file is stored in plain-text.
Storing state remotely can provide better security.
Using the mask feature, you can instruct Terraform to mask sensitive data in the state file.
The Terraform state can contain sensitive data, therefore the state file should be protected from unauthorized access.
Terraform Cloud always encrypts state at rest.
Your manager has instructed you to start using terraform for your day-to-day operations, but your security team is concerned about the terraform state files. They have heard it contains confidential information, and are worried that it will not be securely protected. What should be your response to the security team in this regard?
Inform the security team that using terraform state is optional . There are ways to avoid it , and you will do the same.
Ensure that the state is managed in a remote backend , preferably an enterprise grade state management system like Terraform Cloud.
Mask the confidential entries in the terraform state file , using Vault Enterprise, another Hashicorp product , while keeping it locally.
Keep the state file locally on each developer machine , and ensure that there is a local protection software like KeyPass protecting it.
You have created a terraform script that uses a lot of new constructs that have been introduced in terraform v0.12. However, many developers who are cloning the script from your git repo, are using v0.11, and getting errors.
What can be done from your end to solve this problem?
Force developer to use v0.12 by using terraform setting ‘required_version’ and set it to >=0.12.
Refactor the code to support both v0.11, and v0.12. It might be a difficult process, but there is no other way.
Add a condition in front of each such specific construct, to check whether the running terraform version id v0.11 or v0.12, and ,work accordingly.
Add comments in your code to tell developers to use v0.12 . If they use v0.11 , that should be their problem , which they need to figure out.
Your company has been using Terraform Cloud for a some time now . But every team is creating their own modules , and there is no standardization of the modules , with each team creating the resources in their own unique way . You want to enforce a standardization of the modules across the enterprise . What should be your approach.
Create individual workspaces for each team , and ask them to share modules across workspaces.
Implement a Private module registry in Terraform cloud , and ask teams to reference them.
Upgrade to Terraform enterprise , since this is not possible in terraform cloud.
Upload the modules in the terraform public module registry , and ask teams to reference them
Refer below code where pessimistic constraint operator has been used to specify a version of a provider.
terraform {
required_providers {
aws = "~> 1.1.0"
}
}
Which of the following options are valid provider versions that satisfy the above constraint. (select two)
1.1.1
1.2.9
1.1.8
1.2.0
By default, provisioners that fail will also cause the Terraform apply itself to error. How can you change this default behavior within a provisioner?
provisioner "local-exec" {
on_failure = "next"
}
provisioner "local-exec" {
when = "failure" terraform apply
}
provisioner "local-exec" {
on_failure = "continue"
}
provisioner "local-exec" {
on_failure = continue
}
You have a Terraform configuration file where a variable itemNum is defined as follows:
variable "itemNum" {
default = 3
}
You also have a defined the following environment variables in your shell:
TF_itemNum =6, TF_VAR_itemNum =9.
You also have a terraform.tfvars file with the following contents itemNum = 7
When you run the following apply command, what is the value assigned to the itemNum variable?
terraform apply -var itemNum =4
10
6
1
4
3
You have provisioned some aws resources in your test environment through Terraform for a POC work. After the POC, now you want to destroy the resources but before destroying them you want to check what resources will be getting destroyed through terraform. what are the options of doing that? (Select TWO)
Use terraform destroy command
This is not possible
Use terraform plan command
Use terraform plan -destroy command.
Which of the following challenges would Terraform be a candidate for solving? (Select THREE)
Enable self-service infrastructure to allocate resources on your proprietary private cloud.
Reduce the number of workflows needed for managing infrastructure across each of the companies public and private clouds.
Utilize a single tool for all of the infrastructure and configuration management needs.
Have a single interoperable tool to manage the variety of services including GitHub repositories, MySQL database, and Kubernetes clusters.
Which of the following variable definition files will terraform load automatically? Select three
terraform.tfvar
Any files with names ending in .auto.tfvars.json
terraform.tfvars
terraform.tfvars.json
When using Terraform in a team it is important for everyone to be working with the same state so that operations will be applied to the same remote objects. Which of the below option is a recommended solution for this?
Remote State
Module
Use the cached state and treat this as the record of truth.
Workspace
Which of the below features of Terraform can be used for managing small differences between different environments which can act more like completely separate working directories.
Repositories
Workspaces
Environment Variables
Backends
Refer to the following terraform variable definition
variable "track_tag" {
type = list
default = ["data_ec2","integration_ec2","digital_ec2"]
}
track_tag = {
Name = element(var.track_tag,count.index)
}
If count.index is set to 2, which of the following values will be assigned to the name attribute of track_tag variable?
integration_ec2
digital_ec2
track_tag
data_ec2
You are reviewing Terraform configurations for a big project in your company. You noticed that there are several identical sets of resources that appear in multiple configurations. What feature of Terraform would you recommend to use to reduce the amount of cloned configuration between the different configurations?
Packages
Backends
Provisioners
Modules
The Security Operations team of ABC Enterprise wants to mandate that all the Terraform configuration that creates an S3 bucket must have encryption feature enabled. What is the best way to achieve it?
Use Sentinel Policies.
Use S3 bucket policy.
Create a script that checks the encryption parameter is enabled on every git commit.
Shared a SOP to engineers to mandate encryption feature on S3.
A colleague has informed you that a new version of a Terraform module that your team hosts on an Amazon S3 bucket is broken. The Amazon S3 bucket has versioning enabled. Your colleague tells you to make sure you are not using the latest version in your configuration. You have the following configuration block in your code that refers to the module:
module "infranet" {
source = "s3::https://s3-us-west- 2.amazonaws.com/infrabucket/infra_module.zip"
}
What is the best way to ensure that you are not using the latest version of the module?
Add a module version constraint in your configuration's backend block and specify a previous version.
Add a version key to the module configuration and specify a previous version.
Delete the latest version of the module in S3 to rollback to the previous version.
Add a version property to the module in Terraform's state file and specify a previous version.
Which of the following are string functions? Select three
tostring
tonumber
chomp
format
join
What kind of resource dependency is stored in terraform.tfstate file?
Both implicit and explicit dependencies are stored in state file.
Only explicit dependencies are stored in state file.
Only implicit dependencies are stored in state file.
No dependency information is stored in state file.
Terraform Cloud always encrypts state at rest and protects it with TLS in transit. Terraform Cloud also knows the identity of the user requesting state and maintains a history of state changes.
True
False
You have already set TF_LOG = DEBUG to enable debug log. Now you want to always write the log to the directory you're currently running terraform from. what should you do to achieve this.
Run the command export TF_LOG_FILE=./terraform.log.
Run the command export TF_LOG_PATH=./terraform.log.
Run the command export TF_DEBUG_PATH=./terraform.log.
No explicit action required. Terraform will take care of this as you have enable TF_LOG.
You have been given requirements to create a security group for a new application. Since your organization standardizes on Terraform, you want to add this new security group with the fewest number of lines of code. What feature could you use to iterate over a list of required tcp ports to add to the new security group?
dynamic backend
splat expression
terraform import
dynamic block
After creating a new workspace "PROD" you need to run the command terraform select PROD to switch to it.
True
False
Dawn has created the below child module. Without changing the module, can she override the instance_type from t2.micro to t2.large form her code while calling this module?
1. resource "aws_instance" "myec2"
2. {
3. ami = "ami-082b5a644766e0e6f"
4. instance_type = "t2.micro
5. }
True
False
Mary has created a database instance in AWS and for ease of use is outputting the value of the database password with the following code:
1. output "db_password"
2. {
3. value = local.db_password
4. }
Mary wants to hide the output value in the CLI after terraform apply?
What is the best way?
Use secure parameter
Use sensitive parameter
Use cryptographic hash
Encrypt the value using encrypt() function
Every region in AWS has a different AMI ID for Linux and these are keep on changing. What is the best approach to create the EC2 instances that can deal with different AMI IDs based on regions?
Use data source aws_ami.
Create a map of region to ami id.
Create different configuration file for different region.
None of the above
Forcing the recreation of a resource is useful when you want a certain side effect of recreation that is not visible in the attributes of a resource. What command will do this?
terraform taint
terraform apply
terraform graph
terraform refresh
What happens when a terraform apply command is executed?
Creates the execution plan for the deployment of resources.
Applies the changes required in the target infrastructure in order to reach the desired configuration.
The backend is initialized and the working directory is prepped.
Reconciles the state Terraform knows about with the real-world infrastructure.
Which of the below command will upgrade the provider version to the latest acceptable one?
terraform plan upgrade
terraform provider -upgrade
terraform init -upgrade
terraform init -update
Your manager has instructed you to start using terraform for the entire infra provisioning of the application stack. There are 4 environments – DEV , QA , UAT , and PROD. The application team has asked for complete segregation between these environments including the backend , state , and also configurations ,since there will be unique resources in different environments . What is the possible way to structure the terraform code to facilitate that.
Completely separate the working directories , keep one for each environment . For each working directory , maintain a separate configuration file , variables file , and map to a different backend.
Completely separate the working directories , keep one for each environment . For each working directory , maintain a separate configuration file , variables file , and map to the same backend.
Implement terraform workspaces , and map each environment with one workspace.
Enable remote backend storage . Configure 4 different backend storages , one for each environment.
Eric needs to make use of module within his terraform code. Should the module always be public and open-source to be able to be used?
True
False
You cannot publish your own modules on the Terraform Registry.
True
False
Which of the below options is the equivalent Terraform 0.12 version of the snippet which is written in Terraform 0.11?
"${var.instance_id}"
variable.instance_id
var.instance_ids
var.instance_id
None of the above
You have created two workspaces PROD and DEV. You have switched to DEV and provisioned DEV infrastructure from this workspace. Where is your state file stored?
terraform.d
terraform.tfstate
terraform.tfstate.DEV
terraform.tfstate.d
Multiple configurations for the same provider can be used in a single configuration file.
True
False
Taint the resource "aws_instance" "baz" resource that lives in module bar which lives in module foo.
terraform taint module.foo.module.bar.baz
terraform taint module.foo.bar.aws_instance.baz
terraform taint module.foo.module.bar.aws_instance.baz
terraform taint foo.bar.aws_instance.baz
The terraform state command can be used to ____
Update current state
Refresh existing state file
Print the current state file in console
It is not a valid command
Command terraform refresh will update state file?
True
False
State locking does not happen automatically and must be specified at run
True
False
Which of the below options is a valid interpolation syntax for retrieving a data source?
${google_storage_bucket.backend}
${azurerm_resource_group.test.data}
${aws_instance.web.id.data}
${data.google_dns_keys.foo_dns_keys.key_signing_keys[0].ds_record}
Jim has created several AWS resources from a single terraform configuration file. Someone from his team has manually modified one of the EC2 instance. Now to discard the manual change, Jim wants to destroy and recreate the EC2 instance. What is the best way to do it?
terraform recreate
terraform taint
terraform destroy
terraform refresh
Which flag would be used within a Terraform configuration block to identify the specific version of a provider required?
required-provider
required-version
required_providers
required_versions
Terraform-specific settings and behaviors are declared in which configuration block type?
provider
terraform
resource
data
