What is one disadvantage of using dynamic blocks in Terraform?
Answer : D
This is one disadvantage of using dynamic blocks in Terraform, as they can introduce complexity and reduce readability of the configuration. The other options are either advantages or incorrect statements.
Which command doesnotcause Terraform to refresh its state?
Answer : A
terraform state listonly displays resources stored in the state filebut doesnot interact with the cloud provideror refresh the state.
terraform plan, terraform apply, and terraform destroycompare or modify the infrastructure, so theyrefresh the stateto ensure accuracy.
Official Terraform Documentation Reference:
terraform state list - HashiCorp Documentation
Which of the following is not a valid string function in Terraform?
Answer : C
Referencing Terraform Built-in Functions:
chomp: removes trailing newlines
join: combines list into string
split: splits string into list
slice:is nota valid Terraform string function (it's used in other languages like Python)
How can terraform plan aid in the development process?
Answer : B
The terraform plan command is used to create an execution plan. It allows you to see what actions Terraform will take to reach the desired state defined in your configuration files. It evaluates the current state and configuration, showing a detailed outline of the resources that will be created, updated, or destroyed. This is a critical step in the development process as it helps you verify that the changes you are about to apply will perform as expected, without actually modifying any state or infrastructure.
Terraform documentation on terraform plan: Terraform Plan
You just upgraded the version of a provider in an existing Terraform project. What do you need to do to install the new provider?
Answer : B
When upgrading a provider,you must run terraform init -upgrade to install the new version.
Thisdownloads the latest provider versionand updates the local dependency cache.
terraform refresh(A)only updates the state file but doesnotupgrade providers.
terraform apply -upgrade(C)isnot a valid command.
terraform version can be upgraded separately, but(D)does not install a new provider version.
Official Terraform Documentation Reference:
Upgrading Providers in Terraform
Your Terraform configuration declares a variable. You want to enforce that its value meets your specific requirements, and you want to block the Terraform operation if it does not. What should you add to your configuration?
Answer : B
Rationale for Correct Answer: To enforce constraints on an input variable, Terraform provides variable validation using a validation block inside the variable block. If the condition fails, Terraform produces an error and prevents the operation (plan/apply) from continuing with invalid input.
Analysis of Incorrect Options (Distractors):
A (Top-level check block): check blocks validate conditions, but they are not the standard mechanism for constraining input variable values at the point of declaration; variable validation is.
C (Top-level validation block): Terraform does not support a standalone top-level validation block.
D (check block in the variable block): check is not placed inside variable blocks for input validation; the correct construct is validation.
Key Concept: Input variable validation to enforce constraints and fail fast.
Which command should you run to check if all code in a Terraform configuration that references multiple modules is properly formatted without making changes?
Answer : C
This command will check if all code in a Terraform configuration that references multiple modules is properly formatted without making changes, and will return a non-zero exit code if any files need formatting. The other commands will either make changes, list the files that need formatting, or not check the modules.