Practice Free Terraform Associate 004 Exam Online Questions
Before you can use a new backend or HCP Terraform/Terraform Cloud integration, you must first execute terraform init.
- A . True
- B . False
A
Explanation:
The terraform init command is required before using a new backend or integrating with HCP Terraform/Terraform Cloud.
terraform init initializes the working directory and sets up the backend, downloading necessary provider plugins and modules.
If the backend configuration changes, Terraform willrequirere-initialization to apply those changes.
Without running terraform init, Terraform willfailto use a new backend or remote Terraform Cloud workspace.
Official Terraform Documentation
Reference: terraform init – HashiCorp Documentation
You need to destroy all of the resources in your Terraform workspace, except for
aws_instance.ubuntu[1], which you want to keep.
How can you tell Terraform to stop managing that specific resource without destroying it?
- A . Remove the resource block from your configuration.
- B . Change the value of the count argument on the resource.
- C . Run terraform state rm aws_instance.ubuntu[1].
- D . Use a moved block.
C
Explanation:
Rationale for Correct Answer
terraform state rm <address> removes a resource from Terraform state without destroying the real infrastructure. After removal, Terraform “forgets” it and will no longer manage it (unless it’s re-imported). That matches the requirement: keep the resource, stop managing it.
Analysis of Incorrect Options (Distractors):
A: Removing the resource block causes Terraform to plan to destroy the resource (because it’s in state but no longer in config), which is the opposite of “keep it.”
B: Changing count can cause Terraform to destroy instances that no longer have an address (depending on indexing), and it doesn’t explicitly “stop managing” a specific existing instance safely.
D: moved blocks are for renaming/refactoring addresses while keeping management; they do not stop managing a resource.
Key Concept: Detaching resources from Terraform management using state subcommands (terraform state rm).
Reference: Terraform Objectives ― Implement and Maintain State (state manipulation), Navigate Terraform State and Backends (state operations).
Exhibit:
module "network" {
source = "terraform-google-modules/network/google"
version = "~> 11.0"
}
What version of the source module does Terraform allow with the module block shown in the exhibit?
- A . Any version of the module > 11.0.
- B . Any version of the module >= 11.0.
- C . Any version of the module >= 11.0 and < 12.0.
- D . Any version of the module >= 11.0.0 and < 11.1.0.
C
Explanation:
Rationale for Correct Answer
The pessimistic constraint operator ~> allows updates that do not change the leftmost specified digits beyond what’s declared. With ~> 11.0, Terraform allows any version that is >= 11.0 but < 12.0 (i.e., any 11.x release). This pins to the major version while allowing minor/patch updates.
Analysis of Incorrect Options (Distractors):
A: Incorrect―this excludes exactly 11.0 and doesn’t express the upper bound that ~> imposes.
B: Incorrect―missing the upper bound; ~> always implies an upper limit.
D: Incorrect―>= 11.0.0 and < 11.1.0 corresponds to ~> 11.0.0, not ~> 11.0. Key Concept: Module version constraints using the pessimistic (~>) operator.
Reference: Terraform Objectives ― Interact with Terraform Modules (module versioning and registry usage).
Which statement describes a goal of Infrastructure as Code (IaC)?
- A . A pipeline process to test and deliver software.
- B . Write once, run anywhere.
- C . The programmatic configuration of resources.
- D . Defining a vendor-agnostic API.
C
Explanation:
Infrastructure as Code (IaC) refers to managing infrastructureprogrammatically, enabling automation and repeatability.
Ais incorrect becauseIaC is not just about software delivery pipelines; it specifically deals with infrastructure.
Bis incorrect because"Write once, run anywhere" applies more to software development than IaC.
Dis incorrect becauseIaC does not enforce vendor-agnostic APIs; it depends on the tool and provider.
Official Terraform Documentation
Reference: What is Infrastructure as Code?
Why would you use the -replace flag for terraform apply?
- A . You want Terraform to ignore a resource on the next apply
- B . You want Terraform to destroy all the infrastructure in your workspace
- C . You want to force Terraform to destroy a resource on the next apply
- D . You want to force Terraform to destroy and recreate a resource on the next apply
D
Explanation:
The -replace flag is used with the terraform apply command when there is a need to explicitly force Terraform to destroy and then recreate a specific resource during the next apply. This can be necessary in situations where a simple update is insufficient or when a resource must be re-provisioned to pick up certain changes.
You created infrastructure outside the Terraform workflow that you now want to manage using Terraform.
Which command brings the infrastructure into Terraform state?
- A . terraform get
- B . terraform refresh
- C . terraform import
- D . terraform init
C
Explanation:
The terraform import command allows Terraform to takeexistinginfrastructure andbring it under Terraform’s management.
A (terraform get)is incorrect because it is used to fetch modules.
B (terraform refresh)is incorrect because it only updates Terraform’s state to match the infrastructure but does not import resources.
D (terraform init)is incorrect because it only initializes the Terraform working directory.
Official Terraform Documentation
Reference: terraform import – HashiCorp Documentation
It is best practice to store secret data in the same version control repository as your Terraform configuration.
- A . True
- B . False
B
Explanation:
It is not a best practice to store secret data in the same version control repository as your Terraform configuration, as it could expose your sensitive information to unauthorized parties or compromise your security. You should use environment variables, vaults, or other mechanisms to store and provide secret data to Terraform.
A child module can always access variables declared in its parent module.
- A . True
- B . False
B
Explanation:
Child modulesdo not automatically inheritvariables from the parent module.
To pass values from theparent moduleto thechild module, you mustexplicitly define input variablesin the child module and pass them in the parent module.
Example:
hcl
CopyEdit
module "example" {
source = "./child_module"
var1 = "value"
}
Official Terraform Documentation
Reference: Passing Variables to Modules
Which command(s) adds existing resources in a public cloud into Terraform state?
- A . terraform init
- B . terraform plan
- C . terraform refresh
- D . terraform import
- E . All of these
D
Explanation:
Importing Existing Resources: Theterraform importcommand 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.
Which command(s) adds existing resources in a public cloud into Terraform state?
- A . terraform init
- B . terraform plan
- C . terraform refresh
- D . terraform import
- E . All of these
D
Explanation:
Importing Existing Resources: Theterraform importcommand 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.
