What resource dependency information is stored in Terraform's state?
-
A
Only implicit dependencies are stored in state.
-
B
Both implicit and explicit dependencies are stored in state.
-
C
Only explicit dependencies are stored in state.
-
D
No dependency information is stored in state.
Reveal answer details
Close answer details
Correct answerB
ExplanationTerraform state captures all dependency information, both implicit and explicit. One purpose for state is to determine the proper order to destroy resources. When resources are created all of their dependency information is stored in the state. If you destroy a resource with dependencies, Terraform can still determine the correct destroy order for all other resources because the dependencies are stored in the state. https://www.terraform.io/docs/state/purpose.html#metadata
You can develop a custom provider to manage its resources using Terraform.
-
A
-
B
Reveal answer details
Close answer details
Correct answerA
ExplanationYou can develop a custom provider to manage its resources using Terraform, as Terraform is an extensible tool that allows you to write your own plugins in Go language. You can also publish your custom provider to the Terraform Registry or use it privately.
Most Terraform providers interact with ____________.
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerA
ExplanationTerraform relies on plugins called "providers" to interact with cloud providers, SaaS providers, and other APIs, as per: https://www.terraform.io/language/providers
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?
-
A
-
B
-
C
Use the cached state and treat this as the record of truth.
-
D
Reveal answer details
Close answer details
Correct answerA
Explanationhttps://www.terraform.io/docs/state/remote.html
Setting the TF_LOG environment variable to DEBUG causes debug messages to be logged into syslog.
-
A
-
B
Reveal answer details
Close answer details
Correct answerB
ExplanationTF_LOG_PATH IS NOT REQUIRED, in the docs, they do not mention HAVE TO SET TF_LOG_PATH, it is optional, therefore without TF_LOG_PATH will cause detailed logs to appear on stderr. https://www.computerhope.com/jargon/s/stderr.htm#:~:text=Stderr%2C%20also%20known%20as%20standard,defaults%20to%20the%20user's%20screen.
A user creates three workspaces from the command line-prod, dev, and test. Which of the following commands will the user run to switch to the dev workspace?
-
A
-
B
terraform workspace select dev
-
C
terraform workspace-switch dev
-
D
terraform workspace switch dev
Reveal answer details
Close answer details
Correct answerB
ExplanationThe terraform workspace select command is used to choose a different workspace to use for further operations. https://www.terraform.io/docs/commands/workspace/select.html
During a terraform apply, a resource is successfully created but eventually fails during provisioning. What happens to the resource?
-
A
The resource will be planned for destruction and recreation upon the next terraform apply
-
B
Terraform will retry to provision again.
-
C
The failure of provisioner will be ignored and it will not cause a failure to terraform apply
-
D
The resource will be automatically destroyed.
Reveal answer details
Close answer details
Correct answerA
ExplanationIf a creation-time provisioner fails, the resource is marked as tainted. A tainted resource will be planned for destruction and recreation upon the next terraform apply. Terraform does this because a failed provisioner can leave a resource in a semi-configured state. Because Terraform cannot reason about what the provisioner does, the only way to ensure proper creation of a resource is to recreate it. This is tainting. You can change this behavior by setting the on_failure attribute, which is covered in detail below. https://www.terraform.io/docs/provisioners/index.html#creation-time-provisioners https://www.terraform.io/docs/provisioners/index.html#destroy-time-provisioners https://www.terraform.io/docs/provisioners/index.html#failure-behavior
lookup retrieves the value of a single element from which of the below data type?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerA
Explanationhttps://www.terraform.io/docs/configuration/functions/lookup.html
Environment variables can be used to set variables. The environment variables must be in the format "____"_<variablename>. Select the correct prefix string from the following list.
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerC
ExplanationEnvironment variables can be used to set variables. The environment variables must be in the format TF_VAR_name and this will be checked last for a value. For example: export TF_VAR_region=us-west-1 export TF_VAR_ami=ami-049d8641 export TF_VAR_alist='[1,2,3]' export TF_VAR_amap='{ foo = "bar", baz = "qux" }' https://www.terraform.io/docs/commands/environment-variables.html
Question 10
Single choice
When should you use the force-unlock command?
-
A
You see a status message that you cannot acquire the lock
-
B
You have a high priority change
-
C
Automatic unlocking failed
-
D
Your apply failed due to a state lock
Reveal answer details
Close answer details
Correct answerC
ExplanationYou should use the force-unlock command when automatic unlocking failed. Terraform will lock your state for all operations that could write state, such as plan, apply, or destroy. This prevents others from acquiring the lock and potentially corrupting your state. State locking happens automatically on all operations that could write state and you won't see any message that it is happening. If state locking fails, Terraform will not continue. You can disable state locking for most commands with the -lock flag but it is not recommended. If acquiring the lock is taking longer than expected, Terraform will output a status message. If Terraform doesn't output a message, state locking is still occurring if your backend supports it. Terraform has a force-unlock command to manually unlock the state if unlocking failed. Be very careful with this command. If you unlock the state when someone else is holding the lock it could cause multiple writers. Force unlock should only be used to unlock your own lock in the situation where automatic unlocking failed. To protect you, the force-unlock command requires a unique lock ID. Terraform will output this lock ID if unlocking fails. This lock ID acts as a nonce, ensuring that locks and unlocks target the correct lock. The other situations are not valid reasons to use the force-unlock command. You should not use the force-unlock command if you have a high priority change, if apply failed due to a state lock, or if you see a status message that you cannot acquire the lock. These situations indicate that someone else is holding the lock and you should wait for them to finish their operation or contact them to resolve the issue. Using the force-unlock command in these cases could result in data loss or inconsistency. Be very careful with this command. If you unlock the state when someone else is holding the lock it could cause multiple writers. Force unlock should only be used to unlock your own lock in the situation where automatic unlocking failed. Source: https://www.terraform.io/language/state/locking https://www.terraform.io/cli/commands/force-unlock
Question 11
Single choice
Workspaces in Terraform provides similar functionality in the open-source, Terraform Cloud, and Enterprise versions of Terraform.
-
A
-
B
Reveal answer details
Close answer details
Correct answerB
Explanationhttps://www.terraform.io/docs/cloud/migrate/workspaces.html Workspaces, managed with the terraform workspace command, aren't the same thing as Terraform Cloud's workspaces. Terraform Cloud workspaces act more like completely separate working directories; CLI workspaces are just alternate state files.
Question 12
Single choice
How would you output returned values from a child module in the Terraform CLI output?
-
A
Declare the output in the root configuration
-
B
Declare the output in the child module
-
C
Declare the output in both the root and child module
-
D
Reveal answer details
Close answer details
Correct answerC
ExplanationTo output returned values from a child module in the Terraform CLI output, you need to declare the output in both the child module and the root module. The child module output will return the value to the root module, and the root module output will display the value in the CLI. References: [Terraform Outputs]
Question 13
Multiple choice
Which of the below terraform commands do not run terraform refresh implicitly before taking actual action of the command?
-
A
-
B
-
C
-
D
-
E
Reveal answer details
Close answer details
Correct answersC, D
Explanationhttps://www.terraform.io/docs/commands/refresh.html
Question 14
Single choice
Which method for sharing Terraform modules fulfills the following criteria: Keeps the module configurations confidential within your organization. Supports Terraform's semantic version constraints. Provides a browsable directory of your modules.
-
A
A Git repository containing your modules.
-
B
Public Terraform module registry.
-
C
A subfolder within your workspace.
-
D
HCP Terraform/Terraform Cloud private registry.
Reveal answer details
Close answer details
Correct answerD
ExplanationConfidentiality: Using HCP Terraform/Terraform Cloud's private registry keeps the module configurations within your organization, ensuring privacy and access control. Version Constraints: The private registry supports semantic versioning, allowing you to manage versions of your modules as Terraform does natively. Browsable Directory: The private registry offers a user interface to browse modules, making it easy for users within the organization to locate and manage modules. This setup aligns with HashiCorp's design for private registry support in Terraform, meeting all listed requirements for secure, version-controlled, and searchable module storage.
Question 15
Single choice
All standard backend types support state storage, locking, and remote operations like plan. apply and destroy.
-
A
-
B
Reveal answer details
Close answer details
Correct answerB
Explanationhttps://www.terraform.io/language/settings/backends/configuration "Some of these backends act like plain remote disks for state files, while others support locking the state while operations are being performed. This helps prevent conflicts and inconsistencies. The built-in backends listed are the only backends. You cannot load additional backends as plugins."
Question 16
Single choice
terraform init initializes a sample main.tf file in the current directory.
-
A
-
B
Reveal answer details
Close answer details
Correct answerB
ExplanationReferences: https://www.terraform.io/docs/cli/commands/init.html
Question 17
Single choice
In Terraform HCL, an object type of object({name=string, age-number}) would match this value. 
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerB
ExplanationThe name (string) must be written in quotes. The age (number) should not be in quotes and must be written with numeric characters
Question 18
Single choice
When should you write Terraform configuration files for existing infrastructure that you want to start managing with Terraform?
-
A
You can import infrastructure without corresponding Terraform code
-
B
Terraform will generate the corresponding configuration files for you
-
C
Before you run terraform Import
-
D
After you run terraform import
Reveal answer details
Close answer details
Correct answerC
ExplanationYou need to write Terraform configuration files for the existing infrastructure that you want to import into Terraform, otherwise Terraform will not know how to manage it. The configuration files should match the type and name of the resources that you want to import.
Question 19
Single choice
Terraform plan updates your state file.
-
A
-
B
Reveal answer details
Close answer details
Correct answerB
ExplanationThe terraform plan command creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure. The plan command alone will not actually carry out the proposed changes, and so you can use this command to check whether the proposed changes match what you expected before you apply the changes or share your changes with your team for broader review. Source: https://www.terraform.io/cli/commands/plan
Question 20
Single choice
A Terraform local value can reference other Terraform local values.
-
A
-
B
Reveal answer details
Close answer details
Correct answerA
Explanation"The expressions in local values are not limited to literal constants; they can also reference other values in the module in order to transform or combine them, including variables, resource attributes, or other local values:" https://www.terraform.io/language/values/locals#declaring-a-local-value
Question 21
Single choice
You have a list of numbers that represents the number of free CPU cores on each virtual cluster:  What Terraform function could you use to select the largest number from the list?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerB
ExplanationIn Terraform, the max function can be used to select the largest number from a list of numbers. The max function takes multiple arguments and returns the highest one. For the list numcpus = [18, 3, 7, 11, 2], using max(numcpus...) will return 18, which is the largest number in the list. References: Terraform documentation on max function: Terraform Functions - max
Question 22
Single choice
During a terraform plan, a resource is successfully created but eventually fails during provisioning. What happens to the resource?
-
A
Terraform attempts to provision the resource up to three times before exiting with an error
-
B
the terraform plan is rolled back and all provisioned resources are removed
-
C
it is automatically deleted
-
D
the resource is marked as tainted
Reveal answer details
Close answer details
Correct answerD
ExplanationIf a resource successfully creates but fails during provisioning, Terraform will error and mark the resource as "tainted". A resource that is tainted has been physically created, but can't be considered safe to use since provisioning failed. 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.
Question 23
Single choice
Which of the following is not true of Terraform providers?
-
A
An individual person can write a Terraform Provider
-
B
A community of users can maintain a provider
-
C
HashiCorp maintains some providers
-
D
Cloud providers and infrastructure vendors can write, maintain, or collaborate on Terraform providers
-
E
Reveal answer details
Close answer details
Correct answerE
ExplanationAll of the statements are true of Terraform providers. Terraform providers are plugins that enable Terraform to interact with various APIs and services 1. Anyone can write a Terraform provider, either as an individual or as part of a community 2. HashiCorp maintains some providers, such as the AWS, Azure, and Google Cloud providers 3. Cloud providers and infrastructure vendors can also write, maintain, or collaborate on Terraform providers, such as the VMware, Oracle, and Alibaba Cloud providers. References: Providers - Configuration Language | Terraform | HashiCorp Developer Plugin Development - How Terraform Works With Plugins | Terraform | HashiCorp Developer Terraform Registry Terraform Registry
Question 24
Single choice
How do you specify a module's version when publishing it to the public Terraform Module Registry?
-
A
The module's configuration page on the Terraform Module Registry
-
B
Terraform Module Registry does not support versioning modules
-
C
The release tags in the associated repo
-
D
The module's Terraform code
Reveal answer details
Close answer details
Correct answerC
Explanationhttps://www.terraform.io/registry/modules/publish
Question 25
Multiple choice
Which two steps are required to provision new infrastructure in the Terraform workflow? (Choose two.)
-
A
-
B
-
C
-
D
-
E
Reveal answer details
Close answer details
Correct answersB, D
ExplanationThe two steps that are required to provision new infrastructure in the Terraform workflow are init and apply. The terraform init command initializes a working directory containing Terraform configuration files. It downloads and installs the provider plugins that are needed for the configuration, and prepares the backend for storing the state. The terraform apply command applies the changes required to reach the desired state of the configuration, as described by the resource definitions in the configuration files. It shows a plan of the proposed changes and asks for confirmation before making any changes to the infrastructure. References: https://www.terraform.io/guides/core-workflow.html [The Core Terraform Workflow], [Initialize a Terraform working directory with init], [Apply Terraform Configuration with apply]
Question 26
Single choice
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.
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerB
Explanationworkspaces allow conveniently switching between multiple instances of a single configuration within its single backend. They are convenient in a number of situations, but cannot solve all problems. A common use for multiple workspaces is 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. For example, a developer working on a complex set of infrastructure changes might create a new temporary workspace in order to freely experiment with changes without affecting the default workspace. Non-default workspaces are often related to feature branches in version control. The default workspace might correspond to the "master" or "trunk" branch, which describes the intended state of production infrastructure. When a feature branch is created to develop a change, the developer of that feature might create a corresponding workspace and deploy into it a temporary "copy" of the main infrastructure so that changes can be tested without affecting the production infrastructure. Once the change is merged and deployed to the default workspace, the test infrastructure can be destroyed and the temporary workspace deleted. https://www.terraform.io/docs/state/ workspaces.html https://www.terraform.io/docs/state/workspaces.html#when-to-use-multiple-workspaces
Question 27
Single choice
You're writing a Terraform configuration that needs to read input from a local file called id_rsa.pub. Which built-in Terraform function can you use to import the file's contents as a string?
-
A
-
B
-
C
templatefile("id_rsa.pub")
-
D
Reveal answer details
Close answer details
Correct answerD
ExplanationTo import the contents of a local file as a string in Terraform, you can use the built-in file function. By specifying file("id_rsa.pub"), Terraform reads the contents of the id_rsa.pub file and uses it as a string within your Terraform configuration. This function is particularly useful for scenarios where you need to include file data directly into your configuration, such as including an SSH public key for provisioning cloud instances. References: This information is a standard part of Terraform's functionality with built-in functions, as outlined in Terraform's official documentation and commonly used in various Terraform configurations. (https://www.terraform.io/language/functions/file)
Question 28
Single choice
Terraform must track metadata such as resource dependencies. Where is this data stored?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerC
ExplanationTerraform typically uses the configuration to determine dependency order. However, when you delete a resource from a Terraform configuration, Terraform must know how to delete that resource. Terraform can see that a mapping exists for a resource not in your configuration and plan to destroy. However, since the configuration no longer exists, the order cannot be determined from the configuration alone. To ensure correct operation, Terraform retains a copy of the most recent set of dependencies within the state. Now Terraform can still determine the correct order for destruction from the state when you delete one or more items from the configuration. https://www.terraform.io/docs/state/purpose.html#metadata
Question 29
Single choice
What is terraform refresh intended to detect?
-
A
Terraform configuration code changes
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerC
Explanation"The terraform refresh command reads the current settings from all managed remote objects and updates the Terraform state to match. Warning: This command is deprecated, because its default behavior is unsafe if you have misconfigured credentials for any of your providers. See below for more information and recommended alternatives." https://www.terraform.io/cli/commands/refresh
Question 30
Single choice
Terraform init can indeed be run only a few times, because, every time terraform init will initialize the project , and download all plugins from the internet repository , regardless of whether they were present or not , and this increases the waiting time
-
A
-
B
Reveal answer details
Close answer details
Correct answerB
ExplanationRe-running init with modules already installed will install the sources for any modules that were added to configuration since the last init, but will not change any already-installed modules. Use-upgrade to override this behavior, updating all modules to the latest available source code. https://www.terraform.io/docs/commands/init.html
Question 31
Single choice
Given the Terraform configuration below, in which order will the resources be created?
-
A
-
B
resources will be created simultaneously
-
C
aws_eip will be created first aws_instance will be created second
-
D
aws_instance will be created first aws_eip will be created second
Reveal answer details
Close answer details
Correct answerD
ExplanationThe aws_instance will be created first, and then aws_eip will be created second due to the aws_eip's resource dependency of the aws_instance id
Question 32
Single choice
A Terraform provisioner must be nested inside a resource configuration block.
-
A
-
B
Reveal answer details
Close answer details
Correct answerA
ExplanationMost provisioners require access to the remote resource via SSH or WinRM, and expect a nested connection block with details about how to connect. References: https://www.terraform.io/docs/language/resources/provisioners/connection.html
Question 33
Single choice
Which statements best describes what the local variable assignment is doing in the following code snippet:
-
A
Create a distinct list of route table name objects
-
B
Create a map of route table names to subnet names
-
C
Create a map of route table names from a list of subnet names
-
D
Create a list of route table names eliminating duplicates
Reveal answer details
Close answer details
Question 34
Single choice
A data block requests that Terraform read from a given data source and export the result under the given local name.
-
A
-
B
Reveal answer details
Close answer details
Question 35
Single choice
What does Terraform not reference when running a terraform apply -refresh-only ?
-
A
-
B
-
C
-
D
Terraform resource definitions in configuration files
Reveal answer details
Close answer details
Correct answerD
ExplanationWhen running a terraform apply -refresh-only, Terraform does not reference the configuration files, but only the state file, credentials, and cloud provider. The purpose of this command is to update the state file with the current status of the real resources, without making any changes to them 1.
Question 36
Single choice
What features stops multiple admins from changing the Terraform state at the same time?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerD
ExplanationSomewhat ambiguous question however the key phrase is "feature". You need a remote backend first with a State Locking feature available to avoid this scenario. https://blog.gruntwork.io/how-to-manage-terraform-state-28f5697e68fa
Question 37
Single choice
Terraform configuration can only import modules from the public registry.
-
A
-
B
Reveal answer details
Close answer details
Correct answerB
ExplanationTerraform configuration can import modules from various sources, not only from the public registry. Modules can be sourced from local file paths, Git repositories, HTTP URLs, Mercurial repositories, S3 buckets, and GCS buckets. Terraform supports a number of common conventions and syntaxes for specifying module sources, as documented in the [Module Sources] page. References: [Module Sources]
Question 38
Multiple choice
Which of the below are paid features of Terraform Cloud?
-
A
-
B
-
C
-
D
-
E
-
F
Reveal answer details
Close answer details
Correct answersC, D, F
Explanationhttps://www.hashicorp.com/products/terraform/pricing/
Question 39
Single choice
Select the command that doesn't cause Terraform to refresh its state.
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerD
ExplanationThis is the command that does not cause Terraform to refresh its state, as it only lists the resources that are currently managed by Terraform in the state file. The other commands will refresh the state file before performing their operations, unless you use the - refresh=false flag.
Question 40
Multiple choice
Which of these are features of HCP Terraform/Terraform Cloud? (Pick the 2 correct responses)
-
A
Automatic backups of configuration and state.
-
B
-
C
Automated infrastructure deployment visualization.
-
D
A web-based user interface (UI).
Reveal answer details
Close answer details
Correct answersB, D
ExplanationTerraform Cloud provides features like remote state storage and a web-based user interface for managing your Terraform runs. While it offers robust infrastructure as code capabilities, automatic backups of configuration and state are not directly provided by Terraform Cloud; instead, the state is stored remotely and secured. References: Terraform Cloud Features
Question 41
Single choice
As a developer, you want to ensure your plugins are up to date with the latest versions. Which Terraform command should you use?
-
A
terreform providers-upgrade
-
B
-
C
terreform refresh-upgrade
-
D
Reveal answer details
Close answer details
Correct answerD
ExplanationThis command will upgrade the plugins to the latest acceptable version within the version constraints specified in the configuration. The other commands do not have an - upgrade option.
Question 42
Single choice
Which option can not be used to keep secrets out of Terraform configuration files?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerD
ExplanationA secure string is not a valid option to keep secrets out of Terraform configuration files. A secure string is a feature of AWS Systems Manager Parameter Store that allows you to store sensitive data encrypted with a KMS key. However, Terraform does not support secure strings natively and requires a custom data source to retrieve them. The other options are valid ways to keep secrets out of Terraform configuration files. A Terraform provider can expose secrets as data sources that can be referenced in the configuration. Environment variables can be used to set values for input variables that contain secrets. A -var flag can be used to pass values for input variables that contain secrets from the command line or a file. References: [AWS Systems Manager Parameter Store], [Terraform AWS Provider Issue #55], [Terraform Providers], [Terraform Input Variables] (https://secrethub.io/blog/secret-management-for-terraform/)
Question 43
Single choice
Which task does teraform init not perform?
-
A
Sources any modules and copies the configuration locally
-
B
Validates all required variables are present
-
C
-
D
Sources all providers present in the configuration and ensures they are downloaded and available locally
Reveal answer details
Close answer details
Question 44
Multiple choice
What is the purpose of using the local-exec provisioner? (Select Two)
-
A
To invoke a local executable.
-
B
Executes a command on the resource to invoke an update to the Terraform state.
-
C
To execute one or more commands on the machine running Terraform.
-
D
Ensures that the resource is only executed in the local infrastructure where Terraform is deployed.
Reveal answer details
Close answer details
Correct answersA, C
ExplanationThe local-exec provisioner invokes a local executable after a resource is created. This invokes a process on the machine running Terraform, not on the resource. Note that even though the resource will be fully created when the provisioner is run, there is no guarantee that it will be in an operable state-for example system services such as sshd may not be started yet on compute resources. Example usage resource "aws_instance" "web" { # ... provisioner "local-exec" { command = "echo ${aws_instance.web.private_ip} >> private_ips.txt" } } Note: Provisioners should only be used as a last resort. For most common situations there are better alternatives. https://www.terraform.io/docs/provisioners/local-exec.html
Question 45
Single choice
The canonical format may change in minor ways between Terraform versions, so after upgrading Terraform it is recommended to proactively run.
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 46
Multiple choice
You have used Terraform to create an ephemeral development environment in the cloud and are now ready to destroy all the infrastructure described by your Terraform configuration. To be safe, you would like to first see all the infrastructure that will be deleted by Terraform. Which command should you use to show all of the resources that will be deleted? (Choose two.)
-
A
Run terraform plan-destroy.
-
B
This is not possible. You can only show resources that will be created.
-
C
Run terraform state rm *.
-
D
Run terraform destroy and it will first output all the resources that will be deleted before prompting for approval.
Reveal answer details
Close answer details
Correct answersA, D
ExplanationTo see all the resources that Terraform will delete, you can use either of these two commands: terraform destroy will show the plan of destruction and ask for your confirmation before proceeding. You can cancel the command if you do not want to destroy the resources. terraform plan -destroy will show the plan of destruction without asking for confirmation. You can use this command to review the changes before running terraform destroy. References: Destroy Infrastructure : Plan Command: Reference: (https://www.terraform.io/docs/cli/commands/state/rm.html)
Question 47
Lab simulation
Simulation You need to migrate a workspace to use a remote backend. After updating your configuration, what command do you run to perform the migration? Type your answer in the field provided. The text field is not case-sensitive and all variations of the correct answer are accepted.
Reveal model answer
Close model answer
terraform init Once you have authenticated to Terraform Cloud, you're ready to migrate your local state file to Terraform Cloud. To begin the migration, reinitialize. This causes Terraform to recognize your cloud block configuration.
Question 48
Single choice
Open source Terraform can only import publicly-accessible and open-source modules.
-
A
-
B
Reveal answer details
Close answer details
Correct answerB
ExplanationTerraform can load modules from a public or private registry. This makes it possible to publish modules for others to use, and to use modules that others have published. Also, members of your organization might produce modules specifically crafted for your own infrastructure needs. Terraform Cloud and Terraform Enterprise both include a private module registry for sharing modules internally within your organization. Source: https://www.terraform.io/language/modules
Question 49
Single choice
Complete the following sentence: The terraform state command can be used to ____
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerA
Explanationhttps://www.terraform.io/docs/commands/state/index.html
Question 50
Single choice
What information does the public Terraform Module Registry automatically expose about published modules?
-
A
-
B
Optional inputs variables and default values
-
C
-
D
-
E
Reveal answer details
Close answer details
Correct answerD
Explanationhttps://www.terraform.io/registry/modules/publish "The registry extracts information about the module from the module's source. The module name, provider, documentation, inputs/outputs, and dependencies are all parsed and available via the UI or API, as well as the same information for any submodules or examples in the module's source repository."
Question 51
Single choice
Given the below resource configuration-resource "aws_instance" "web" { # ... count = 4 } What does the terraform resource address aws_instance.web refer to?
-
A
It refers to all 4 web instances , together , for further individual segregation , indexing is required , with a 0 based index.
-
B
It refers to the last web EC2 instance , as by default , if no index is provided , the last / N-1 index is used.
-
C
It refers to the first web EC2 instance out of the 4 ,as by default , if no index is provided , the first / 0th index is used.
-
D
The above will result in a syntax error , as it is not syntactically correct . Resources defined using count , can only be referenced using indexes.
Reveal answer details
Close answer details
Correct answerA
ExplanationA Resource Address is a string that references a specific resource in a larger infrastructure. An address is made up of two parts: [module path][resource spec] Module path: A module path addresses a module within the tree of modules. It takes the form: module.A.module.B.module.C... Multiple modules in a path indicate nesting. If a module path is specified without a resource spec, the address applies to every resource within the module. If the module path is omitted, this addresses the root module. Given a Terraform config that includes: resource "aws_instance" "web" { # ... count = 4 } An address like this: aws_instance.web[3] Refers to only the last instance in the config, and an address like this: aws_instance.web Refers to all four "web" instances. https://www.terraform.io/docs/internals/resource-addressing.html
Question 52
Single choice
You want to define multiple data disks as nested blocks inside the resource block for a virtual machine. What Terraform feature would help you define the blocks using the values in a variable?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerB
ExplanationDynamic blocks in Terraform allow you to define multiple nested blocks within a resource based on the values of a variable. This feature is particularly useful for scenarios where the number of nested blocks is not fixed and can change based on variable input.
Question 53
Single choice
When does Sentinel enforce policy logic during a Terraform Enterprise run?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerC
Explanation"Enforcing policy checks on runs-Policies are checked when a run is performed, after the terraform plan but before it can be confirmed or the terraform apply is executed." Sentinel policies are checked after the plan stage of a Terraform run, but before it can be confirmed or the terraform apply is executed 3. This allows you to enforce rules on your infrastructure before it is created or modified.
Question 54
Single choice
Your firm employs a version control system (for example, git) and has requested that you commit all terraform code to it. During the commit, you must be cautious with sensitive information. Which of the following files should be left out of the commit?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 55
Single choice
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?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerB
ExplanationIf 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. State locking happens automatically on all operations that could write state. You won't see any message that it is happening. If state locking fails, Terraform will not continue. You can disable state locking for most commands with the-lock flag but it is not recommended. If acquiring the lock is taking longer than expected, Terraform will output a status message. If Terraform doesn't output a message, state locking is still occurring if your backend supports it. Not all backends support locking. Please view the list of backend types for details on whether a backend supports locking or not. https://www.terraform.io/docs/state/locking.html
Question 56
Single choice
In order to reduce the time it takes to provision resources, Terraform uses parallelism. By default, how many resources will Terraform provision concurrently?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 57
Single choice
A Terraform provider is not responsible for:
-
A
Understanding API interactions with some service
-
B
Provisioning infrastructure in multiple clouds
-
C
Exposing resources and data sources based on an API
-
D
Managing actions to take based on resource differences
Reveal answer details
Close answer details
Correct answerB
ExplanationThis is not a responsibility of a Terraform provider, as it does not make sense grammatically or logically. A Terraform provider is responsible for exposing resources and data sources based on an API, managing actions to take based on resource differences, and understanding API interactions with some service. https://www.terraform.io/language/providers
Question 58
Single choice
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. }
-
A
To remove older versions of the provider.
-
B
To ensure that the provider version matches the version of Terraform you are using.
-
C
Providers are released on a separate schedule from Terraform itself; therefore a newer version could introduce breaking changes.
-
D
To match the version number of your application being deployed via Terraform.
Reveal answer details
Close answer details
Question 59
Single choice
If you enable TF_LOG = DEBUG, the log will be stored in syslog.log file in the currect directory.
-
A
-
B
Reveal answer details
Close answer details
Correct answerA
Explanationhttps://www.terraform.io/docs/internals/debugging.html
Question 60
Single choice
Which of the following is an invalid variable name?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerA
Explanationhttps://www.terraform.io/intro/examples/count.html
Question 61
Single choice
Terraform configuration (including any module references) can contain only one Terraform provider type.
-
A
-
B
Reveal answer details
Close answer details
Correct answerB
ExplanationTerraform configuration (including any module references) can contain more than one Terraform provider type. Terraform providers are plugins that Terraform uses to interact with various cloud services and other APIs. A Terraform configuration can use multiple providers to manage resources across different platforms and services. For example, a configuration can use the AWS provider to create a virtual machine, the Cloudflare provider to manage DNS records, and the GitHub provider to create a repository. Terraform supports hundreds of providers for different use cases and scenarios. References: [Providers], [Provider Requirements], [Provider Configuration]
Question 62
Single choice
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.
-
A
Create individual workspaces for each team , and ask them to share modules across workspaces.
-
B
Implement a Private module registry in Terraform cloud , and ask teams to reference them.
-
C
Upgrade to Terraform enterprise , since this is not possible in terraform cloud.
-
D
Upload the modules in the terraform public module registry , and ask teams to reference them
Reveal answer details
Close answer details
Correct answerB
ExplanationTerraform Cloud's private module registry helps you share Terraform modules across your organization. It includes support for module versioning, a searchable and filterable list of available modules, and a configuration designer to help you build new workspaces faster. By design, the private module registry works much like the public Terraform Registry. If you're already used the public registry, Terraform Cloud's registry will feel familiar. Understand the different offerings in Terraform OS, Terraform Cloud and Terraform Enterprise. Terraform Cloud's private module registry helps you share Terraform modules across your organization. https://www.terraform.io/docs/cloud/registry/index.html https://www.terraform.io/docs/cloud/registry/ publish.html
Question 63
Single choice
What is a downside to using the Vault provider to read secrets from Vault?
-
A
Secrets are persisted to the state file and plans.
-
B
Terraform and Vault must be running on the same version.
-
C
Terraform and Vault must be running on the same physical host.
-
D
Terraform requires a unique auth method to work with Vault.
Reveal answer details
Close answer details
Correct answerA
ExplanationThe Vault provider allows Terraform to read from, write to, and configure Hashicorp Vault. Interacting with Vault from Terraform causes any secrets that you read and write to be persisted in both Terraform's state file and in any generated plan files. For any Terraform module that reads or writes Vault secrets, these files should be treated as sensitive and protected accordingly.
Question 64
Single choice
How would you reference the attribute "name* of this fictitious resource in HCL? 
-
A
resource.kubrnetes_namespace>example.name
-
B
kubernetes_namespace.test.name
-
C
kubernetes_namespace.example,name
-
D
data kubernetes_namespace.name
-
E
Reveal answer details
Close answer details
Correct answerC
Explanationhttps://www.terraform.io/language/expressions/references#references-to-resource-attributes
Question 65
Single choice
Which of the following statements about local modules is incorrect:
-
A
Local modules are not cached by terraform init command
-
B
Local modules are sourced from a directory on disk
-
C
Local modules support versions
-
D
All of the above (all statements above are incorrect
-
E
None of the above (all statements above are correct)
Reveal answer details
Close answer details
Correct answerC
ExplanationVersion constraints are supported only for modules installed from a module registry, such as the public Terraform Registry or Terraform Cloud's private module registry. Other module sources can provide their own versioning mechanisms within the source string itself, or might not support versions at all. In particular, modules sourced from local file paths do not support version; since they're loaded from the same source repository, they always share the same version as their caller. https://www.terraform.io/language/modules/syntax
Question 66
Single choice
You can configure Terraform to log to a file using the TF_LOG environment variable.
-
A
-
B
Reveal answer details
Close answer details
Correct answerA
ExplanationYou can configure Terraform to log to a file using the TF_LOG environment variable. This variable can be set to one of the log levels: TRACE, DEBUG, INFO, WARN or ERROR. You can also use the TF_LOG_PATH environment variable to specify a custom log file location. References: Debugging Terraform
Question 67
Single choice
How is terraform import run?
-
A
As a part of terraform init
-
B
As a part of terraform plan
-
C
As a part of terraform refresh
-
D
-
E
Reveal answer details
Close answer details
Correct answerD
Explanation"The current implementation of Terraform import can only import resources into the state. It does not generate configuration. A future version of Terraform will also generate configuration. Because of this, prior to running terraform import it is necessary to write manually a resource configuration block for the resource, to which the imported object will be mapped. While this may seem tedious, it still gives Terraform users an avenue for importing existing resources." https://www.terraform.io/cli/import/usage
Question 68
Single choice
After running into issues with Terraform, you need to enable verbose logging to assist with troubleshooting the error. Which of the following values provides the MOST verbose logging?
-
A
-
B
-
C
-
D
-
E
Reveal answer details
Close answer details
Correct answerD
ExplanationTerraform has detailed logs that can be enabled by setting the TF_LOG environment variable to any value. This will cause detailed logs to appear on stderr. 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. Examples: export TF_LOG=DEBUG export TF_LOG=TRACE
Question 69
Single choice
Which command(s) adds existing resources in a public cloud into Terraform state?
-
A
-
B
-
C
-
D
-
E
Reveal answer details
Close answer details
Correct answerD
ExplanationImporting Existing Resources: The terraform import command brings resources already deployed in a cloud environment into Terraform's state file, allowing Terraform to manage them. Workflow Usage: Importing is vital when managing resources created outside of Terraform or those in place before Terraform adoption. Refer to Terraform's import command documentation.
Question 70
Single choice
Your company has a lot of workloads in AWS , and Azure that were respectively created using CloudFormation , and AzureRM Templates. However , now your CIO has decided to use Terraform for all new projects , and has asked you to check how to integrate the existing environment with terraform code. What should be your next plan of action?
-
A
Tell the CIO that this is not possible . Resources created in CloudFormation , and AzureRM templates cannot be tracked using terraform.
-
B
Use terraform import command to import each resource one by one .
-
C
This is only possible in Terraform Enterprise , which has the TerraformConverter exe that can take any other template language like AzureRM and convert to Terraform code.
-
D
Just write the terraform config file for the new resources , and run terraform apply , the state file will automatically be updated with the details of the new resources to be imported.
Reveal answer details
Close answer details
Question 71
Single choice
You have a Terraform configuration that defines a single virtual machine with no references to it, You have run terraform apply to create the resource, and then removed the resource definition from your Terraform configuration file. What will happen you run terraform apply in the working directory again?
-
A
Terraform will remove the virtual machine from the state file, but the resource will still exist
-
B
-
C
-
D
Terraform will destroy the virtual machine
Reveal answer details
Close answer details
Correct answerD
ExplanationThis is what will happen if you run terraform apply in the working directory again, after removing the resource definition from your Terraform configuration file. Terraform will detect that there is a resource in the state file that is not present in the configuration file, and will assume that you want to delete it.
Question 72
Single choice
Which of the following best describes the default local backend?
-
A
The local backend is where Terraform Enterprise stores logs to be processed by an log collector.
-
B
The local backend stores state on the local filesystem, locks the state using system APIs, and performs operations locally.
-
C
The local backend is the directory where resources deployed by Terraform have direct access to in order to update their current state.
-
D
The local backend is how Terraform connects to public cloud services, such as AWS, Azure, or GCP.
Reveal answer details
Close answer details
Correct answerB
ExplanationThe local backend stores state on the local filesystem, locks that state using system APIs, and performs operations locally. terraform { backend "local" { path = "relative/path/to/terraform.tfstate" } } https://www.terraform.io/docs/backends/types/local.html
Question 73
Single choice
Terraform is currently being used by your organisation to create resources on AWS for the development of a web application. One of your coworkers wants to change the instance type to "t2.large" while keeping the default set values. What adjustments does the teammate make in order to meet his goal?
-
A
Issue Terraform plan instance.type".t2.large" and it deploys the instance
-
B
Modify the tf.variableswith the instance type and issue terraform apply
-
C
Create a new file my.tfvars and add the type of the instance and issue terraform plan and apply
-
D
Modify the terraform.tfvars with the instance type and issue terraform plan and then terraform apply to deploy the instances
Reveal answer details
Close answer details
Question 74
Single choice
A junior admin accidentally deleted some of your cloud instances. What does Terraform do when you run terraform apply?
-
A
Build a completely brand new set of infrastructure
-
B
Tear down the entire workspace infrastructure and rebuild it
-
C
Rebuild only the instances that were deleted
-
D
Stop and generate an error message about the missing instances
Reveal answer details
Close answer details
Question 75
Single choice
Which provider authentication method prevents credentials from being stored in the state file?
-
A
Using environment variables
-
B
Specifying the login credentials in the provider block
-
C
Setting credentials as Terraform variables
-
D
Reveal answer details
Close answer details
Question 76
Single choice
You have created a custom variable definition file my_vars.tfvars. How will you use it for provisioning infrastructure?
-
A
terraform apply-var-state-file ="my_vars.tfvars"
-
B
terraform apply var-file="my_vars.tfvars"
-
C
terraform plan-var-file="my_vars.tfvar"
-
D
terraform apply-var-file="my_vars.tfvars"
Reveal answer details
Close answer details
Correct answerD
ExplanationTo set lots of variables, it is more convenient to specify their values in a variable definitions file (with a filename ending in either .tfvars or .tfvars.json) and then specify that file on the command line with-var-file: terraform apply-var-file="my_vars.tfvars" https://www.terraform.io/docs/configuration/variables.html#variable-definitions-tfvars-files
Question 77
Single choice
You would like to reuse the same Terraform configuration for your development and production environments with a different state file for each. Which command would you use?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerB
Explanationhttps://www.terraform.io/language/state/workspaces#when-to-use-multiple-workspaces
Question 78
Single choice
How can terraform plan aid in the development process?
-
A
Validates your expectations against the execution plan without permanently modifying state
-
B
Initializes your working directory containing your Terraform configuration files
-
C
Formats your Terraform configuration files
-
D
Reconciles Terraform's state against deployed resources and permanently modifies state using the current status of deployed resources
Reveal answer details
Close answer details
Correct answerA
Explanation"The terraform plan command creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure. By default, when Terraform creates a plan it: Reads the current state of any already-existing remote objects to make sure that the Terraform state is up-to-date. Compares the current configuration to the prior state and noting any differences. Proposes a set of change actions that should, if applied, make the remote objects match the configuration." "The plan command alone will not actually carry out the proposed changes, and so you can use this command to check whether the proposed changes match what you expected before you apply the changes or share your changes with your team for broader review. If Terraform detects that no changes are needed to resource instances or to root module output values, terraform plan will report that no actions need to be taken." https://www.terraform.io/cli/commands/plan
Question 79
Single choice
What feature of Terraform Cloud and/or Terraform Enterprise can you publish and maintain a set of custom modules which can be used within your organization?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 80
Single choice
Which of the following state management command allow you to retrieve a list of resources that are part of the state file?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Correct answerA
ExplanationThe terraform state list command is used to list resources within a Terraform state. Usage: terraform state list [options] [address...] The command will list all resources in the state file matching the given addresses (if any). If no addresses are given, all resources are listed. https://www.terraform.io/docs/commands/state/ list.html
Question 81
Single choice
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?
-
A
-
B
-
C
This can be done using any of the local or remote backends.
-
D
Reveal answer details
Close answer details
Correct answerD
ExplanationWhen using full remote operations, operations like terraform plan or terraform apply can be executed in Terraform Cloud's run environment, with log output streaming to the local terminal. Remote plans and applies use variable values from the associated Terraform Cloud workspace. Terraform Cloud can also be used with local operations, in which case only state is stored in the Terraform Cloud backend. https://www.terraform.io/docs/backends/types/remote.html
Question 82
Multiple choice
You want to use API tokens and other secrets within your team's Terraform workspaces. Where does HashiCorp recommend you store these sensitive values? (Pick the 3 correct responses)
-
A
In an HCP Terraform/Terraform Cloud variable, with the sensitive option checked.
-
B
-
C
In a terraform.tfvars file, securely managed and shared with your team.
-
D
In a terraform.tfvars file, checked into your version control system.
-
E
In a plaintext document on a shared drive.
Reveal answer details
Close answer details
Correct answersA, B, C
ExplanationSensitive values such as API tokens should be stored in a secure way, either in Terraform Cloud variables marked as sensitive or in HashiCorp Vault. Storing secrets in version control systems or plaintext files is not recommended. References: Terraform Cloud Environment Variables
Question 83
Single choice
Valarie has created a database instance in AWS and for ease of use is outputting the value of the database password with the following code. Valarie wants to hide the output value in the CLI after terraform apply that's why she has used sensitive parameter. 1. output "db_password" { 2. value = local.db_password 3. sensitive = true 4. } Since sensitive is set to true, will the value associated with db password be available in plain-text in the state file for everyone to read?
-
A
-
B
Reveal answer details
Close answer details
Correct answerA
ExplanationOutputs can be marked as containing sensitive material by setting the sensitive attribute to true, like this: output "sensitive" { sensitive = true value = VALUE } When outputs are displayed on-screen following a terraform apply or terraform refresh, sensitive outputs are redacted, with <sensitive> displayed in place of their value. Limitations of Sensitive Outputs The values of sensitive outputs are still stored in the Terraform state, and available using the terraform output command, so cannot be relied on as a sole means of protecting values. Sensitivity is not tracked internally, so if the output is interpolated in another module into a resource, the value will be displayed.
|