Practice Free Terraform Associate 004 Exam Online Questions
When using multiple configurations of the same Terraform provider, what meta-argument must you include in any non-default provider configurations?
- A . depends_on
- B . alias
- C . name
- D . id
B
Explanation:
Rationale for Correct Answer
To configure multiple instances of the same provider (for example, multiple AWS regions/accounts), you define additional provider blocks and set alias on each non-default one:
provider "aws" { region = "us-east-1" } # default
provider "aws" { alias = "west" region="us-west-2" } # non-default
Resources/modules then select it via provider = aws.west (or providers map for modules).
Analysis of Incorrect Options (Distractors):
A (depends_on): Used to force ordering; not for provider configuration identity. C (name): Not a provider meta-argument for multiple configurations.
D (id): Not a provider configuration meta-argument.
Key Concept: Provider aliasing for multiple provider configurations.
Reference: Terraform Objectives ― Manage Terraform Resources and Providers (providers, configuration, aliases).
You want to define a single input variable to capture configuration values for a server. The values must represent memory as a number, and the server name as a string.
Which variable type could you use for this input?
- A . List
- B . Object
- C . Map
- D . Terraform does not support complex input variables of different types
B
Explanation:
This is the variable type that you could use for this input, as it can store multiple attributes of different types within a single value. The other options are either invalid or incorrect for this use case.
Which of the following is not a way to trigger terraform destroy?
- A . terraform destroy
- B . All of these will trigger terraform destroy
- C . terraform plan -destroy
- D . terraform destroy -auto-approve
C
Explanation:
Rationale for Correct Answer
terraform plan -destroy does not destroy anything. It only creates a plan that proposes destroying all managed resources. Actual destruction happens only when you run terraform destroy or terraform apply with an approved destroy plan.
Analysis of Incorrect Options (Distractors):
A: Does trigger destruction (interactive approval by default).
B: Incorrect because terraform plan -destroy does not perform destruction.
D: Does trigger destruction and skips the interactive approval prompt.
Key Concept: Difference between planning a destroy and executing a destroy.
Reference: Terraform Objectives ― Understand Terraform Basics and CLI (plan vs apply/destroy behaviors).
Which of the following commands would you use to access all of the attributes and details of a resource managed by Terraform?
- A . terraform state list ‘provider_type.name’
- B . terraform state show ‘provider_type.name’
- C . terraform get ‘provider_type.name’
- D . terraform state list
B
Explanation:
The terraform state show command 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. The terraform state list command only shows the list of resources in the state, not their attributes. The terraform get command downloads and installs modules needed for the configuration. It does not show any information about resources.
Reference = [Command: state show] and [Command: state list]
Which command lets you experiment with terraform expressions?
- A . Terraform console
- B . Terraform validate
- C . Terraform env
- D . Terraform test
A
Explanation:
This is the command that lets you experiment with Terraform expressions, by providing an interactive console that allows you to evaluate expressions and see their results. You can use this command to test your expressions before using them in your configuration files.
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.
D
Explanation:
Confidentiality: UsingHCP Terraform/Terraform Cloud’s private registrykeeps the module configurations within your organization, ensuring privacy and access control.
Version Constraints: The private registry supportssemantic 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 forprivate registry supportin Terraform, meeting all listed requirements for secure, version-controlled, and searchable module storage.
You add a new provider to your configuration and immediately run terraform apply in the CD using the local backend.
Why does the apply fail?
- A . The Terraform CD needs you to log into Terraform Cloud first
- B . Terraform requires you to manually run terraform plan first
- C . Terraform needs to install the necessary plugins first
- D . Terraform needs you to format your code according to best practices first
C
Explanation:
The reason why the apply fails after adding a new provider to the configuration and immediately running terraform apply in the CD using the local backend is because Terraform needs to install the necessary plugins first. Terraform providers are plugins that Terraform uses to interact with various cloud services and other APIs. Each provider has a source address that determines where to downloadit from. When Terraform encounters a new provider in the configuration, it needs to run terraform init first to install the provider plugins in a local directory. Without the plugins, Terraform cannot communicate with the provider and perform the desired actions.
Reference = [Provider Requirements], [Provider Installation]
Where can Terraform not load a provider from?
- A . Plugins directory
- B . Provider plugin chance
- C . Official HashCrop Distribution on releases.hashcrop.com
- D . Source code
D
Explanation:
This is where Terraform cannot load a provider from, as it requires a compiled binary file that implements the provider protocol. You can load a provider from a plugins directory, a provider plugin cache, or the official HashiCorp distribution on releases.hashicorp.com.
A resource block is shown in the Exhibit space of this page.
What is the Terraform resource name of the resource block?
- A . test
- B . google
- C . compute_instance
- D . main
D
Explanation:
In Terraform, theresource nameis the second argument in the resource block.
The structure of a resource block is:
resource "provider_resource_type" "resource_name" {
# Configuration settings
}
Here, the provider type isgoogle_compute_instance, and theresource nameis "main".
The name "test" is simply the value assigned to the name attribute, which is unrelated to the Terraform resource name.
"google" and "compute_instance" are part of the provider and resource type, not the resource name.
Official Terraform Documentation
Reference: Terraform Resource Documentation
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?
- A . Terraform data sources
- B . Terraform local values
- C . Terraform modules
- D . Terraform workspaces
- E . None of the above
D
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 = Workspaces and How to Use Terraform Workspaces
