HashiCorp Terraform Associate 003 Practice Test - Questions Answers, Page 13
List of questions
Related questions
Question 121
If a module declares a variable with a default, that variable must also be defined within the module.
Explanation:
A module can declare a variable with a default value without requiring the caller to define it. This allows the module to provide a sensible default behavior that can be customized by the caller if needed.Reference= [Module Variables]
Question 122
A terraform apply can not _________ infrastructure.
Explanation:
The terraform import command is used to import existing infrastructure into Terraform's state. This allows Terraform to manage and destroy the imported infrastructure as part of the configuration. The terraform import command does not modify the configuration, so the imported resources must be manually added to the configuration after the import.Reference= [Importing Infrastructure]
Question 123
How is terraform import run?
Explanation:
The terraform import command is not part of any other Terraform workflow. It must be explicitly invoked by the user with the appropriate arguments, such as the resource address and the ID of the existing infrastructure to import.Reference= [Importing Infrastructure]
Question 124
A provider configuration block is required in every Terraform configuration.
Example:
Explanation:
A provider configuration block isnotrequired in every Terraform configuration. A provider configuration block can be omitted if its contents would otherwise be empty. Terraform assumes an empty default configuration for any provider that is not explicitly configured. However, some providers may require some configuration arguments (such as endpoint URLs or cloud regions) before they can be used. A provider's documentation should list which configuration arguments it expects.For providers distributed on the Terraform Registry, versioned documentation is available on each provider's page, via the ''Documentation'' link in the provider's header1.Reference= [Provider Configuration]1
Question 125
You have multiple team members collaborating on infrastructure as code (IaC) using Terraform, and want to apply formatting standards for readability.
How can you format Terraform HCL (HashiCorp Configuration Language) code according to standard Terraform style convention?
Explanation:
The terraform fmt command is used to rewrite Terraform configuration files to a canonical format and style. This command applies a subset of the Terraform language style conventions, along with other minor adjustments for readability. Running this command on your configuration files before committing them to source control can help ensure consistency of style between different Terraform codebases, and can also make diffs easier to read.You can also use the -check and -diff options to check if the files are formatted and display the formatting changes respectively2.Running the terraform fmt command during the code linting phase of your CI/CD process can help automate this process and enforce the formatting standards for your team.Reference= [Command: fmt]2
Question 126
One remote backend configuration always maps to a single remote workspace.
Explanation:
The remote backend can work with either a single remote Terraform Cloud workspace, or with multiple similarly-named remote workspaces (like networking-dev and networking-prod). The workspaces block of the backend configuration determines which mode it uses. To use a single remote Terraform Cloud workspace, set workspaces.name to the remote workspace's full name (like networking-prod). To use multiple remote workspaces, set workspaces.prefix to a prefix used in all of the desired remote workspace names. For example, set prefix = ''networking-'' to use Terraform cloud workspaces with names like networking-dev and networking-prod.This is helpful when mapping multiple Terraform CLI workspaces used in a single Terraform configuration to multiple Terraform Cloud workspaces3. However, one remote backend configuration always maps to a single remote workspace, either by name or by prefix. You cannot use both name and prefix in the same backend configuration, or omit both.Doing so will result in a configuration error3.Reference= [Backend Type: remote]3
Question 127
Which of the following does terraform apply change after you approve the execution plan? (Choose two.)
Explanation:
Theterraform applycommand changes both the cloud infrastructure and the state file after you approve the execution plan. The command creates, updates, or destroys the infrastructure resources to match the configuration. It also updates the state file to reflect the new state of the infrastructure. The.terraformdirectory, the execution plan, and the Terraform code are not changed by theterraform applycommand.Reference=Command: applyandPurpose of Terraform State
Question 128
You are working on some new application features and you want to spin up a copy of your production deployment to perform some quick tests. In order to avoid having to configure a new state backend, what open source Terraform feature would allow you create multiple states but still be associated with your current code?
Explanation:
Terraform workspaces allow you to create multiple states but still be associated with your current code. Workspaces are like ''environments'' (e.g. staging, production) for the same configuration. You can use workspaces to spin up a copy of your production deployment for testing purposes without having to configure a new state backend. Terraform data sources, local values, and modules are not features that allow you to create multiple states.Reference=WorkspacesandHow to Use Terraform Workspaces
Question 129
Which of the following commands would you use to access all of the attributes and details of a resource managed by Terraform?
Explanation:
Theterraform state showcommand allows you to access all of the attributes and details of a resource managed by Terraform. You can use the resource address (e.g.provider_type.name) as an argument to show the information about a specific resource. Theterraform state listcommand only shows the list of resources in the state, not their attributes. Theterraform getcommand downloads and installs modules needed for the configuration. It does not show any information about resources.Reference= [Command: state show] and [Command: state list]
Question 130
If you manually destroy infrastructure, what is the best practice reflecting this change in Terraform?
Explanation:
If you manually destroy infrastructure, Terraform will automatically detect the change and update the state file during the next plan or apply. Terraform compares the current state of the infrastructure with the desired state in the configuration and generates a plan to reconcile the differences. If a resource is missing from the infrastructure but still exists in the state file, Terraform will attempt to recreate it. If a resource is present in the infrastructure but not in the state file, Terraform will ignore it unless you use the terraform import command to bring it under Terraform's management.Reference= [Terraform State]
Question