---
title: "Terraform: Infrastructure as Code Essentials"
description: "Test your knowledge of Terraform fundamentals with this quiz covering key concepts and best practices."
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/quizzes/post/terraform-essentials-quiz
---

# Terraform: Infrastructure as Code Essentials

Welcome to the Terraform Basics Quiz! This quiz is designed to test your understanding of fundamental Terraform concepts and best practices. Each question is multiple-choice, and you'll find hints to help you along the way. Good luck!

## Questions

### 1. In Terraform dynamic blocks, which attribute determines the number of times the nested configuration is repeated?

- `content`
- `iterator`
- `count`
- `for_each`

**Hint:** It shares its name with the meta-argument used to create multiple instances of a resource.

### 2. Which feature allows you to verify infrastructure health without needing to define a specific resource instance?

- `check` blocks
- `output` blocks
- `import` blocks
- `assert` blocks

**Hint:** Think of a top-level block that performs assertions independently.

### 3. Which lifecycle meta-argument ensures a new resource is provisioned before the old one is removed?

- `depends_on`
- `ignore_changes`
- `prevent_destroy`
- `create_before_destroy`

**Hint:** Reverses the default destruction behavior.

### 4. When refactoring code to rename a resource without destroying it, which block should be added to the HCL?

- `import`
- `moved`
- `alias`
- `state`

**Hint:** Records a movement or rename directly in the configuration.

### 5. What is the correct priority order for variable values (lowest to highest precedence)?

- `Env vars` < `terraform.tfvars` < `*.auto.tfvars` < `CLI flags`
- `terraform.tfvars` < `Env vars` < `*.auto.tfvars` < `CLI flags`
- `Env vars` < `*.auto.tfvars` < `terraform.tfvars` < `CLI flags`
- `CLI flags` < `*.auto.tfvars` < `terraform.tfvars` < `Env vars`

**Hint:** CLI flags are generally considered the final override.

### 6. In HCP Terraform, what is the primary purpose of a 'Project'?

- Isolating provider logic
- Grouping related workspaces
- Versioning module source
- Managing backend state

**Hint:** An organizational layer above workspaces.

### 7. True or False: Values marked as 'sensitive = true' in HCL are encrypted within the state file.

- True
- False

**Hint:** Masking in the CLI is different from storage in the backend.

### 8. Which command provides an interactive REPL to evaluate HCL expressions?

- `terraform console`
- `terraform debug`
- `terraform output`
- `terraform graph`

**Hint:** Useful for testing functions and variable values.

### 9. Which command removes a resource from the state file without deleting the cloud resource?

- `terraform taint`
- `terraform delete`
- `terraform state rm`
- `terraform untrack`

**Hint:** Forces Terraform to "forget" an object.

### 10. What is the function of the 'depends_on' meta-argument?

- Forcing resource order
- Handling error logic
- Optimizing plan speed
- Managing provider bits

**Hint:** Used when dependencies cannot be automatically inferred.

### 11. Which command downloads providers and initializes the working directory?

- `terraform get`
- `terraform init`
- `terraform plan`
- `terraform start`

**Hint:** The mandatory first step for any project.

### 12. What is the default number of concurrent operations used during a Terraform apply?

- 5
- 10
- 25
- 50

**Hint:** The standard parallelism setting.

### 13. Which built-in function is used to combine multiple maps into one?

- `concat()`
- `merge()`
- `join()`
- `union()`

**Hint:** Commonly used for merging sets of tags.

### 14. Which block type allows for code-based importing of existing infrastructure?

- `resource`
- `import`
- `external`
- `include`

**Hint:** The modern alternative to the "terraform import" CLI command.

### 15. Where does the 'local' backend store its data by default?

- `terraform.tfstate`
- `.terraform/state`
- `terraform.config`
- `state.json`

**Hint:** The standard filename for local state.

### 16. Which feature handles data that should not be persisted in the state file at all?

- Sensitive values
- Ephemeral values
- Dynamic values
- Output values

**Hint:** Used for transient data like temporary credentials.

### 17. What is the result of a creation-time provisioner failing during an apply?

- Resource is deleted
- Resource is tainted
- State is rolled back
- Command is retried

**Hint:** Affects the reliability status of the resource.

### 18. What is the definition of a 'child module' in Terraform?

- The root directory
- A module called by another
- A provider plugin
- A local variable set

**Hint:** Relates to how modules are called in the hierarchy.

### 19. Which command automatically updates HCL code to follow canonical styling?

- `terraform lint`
- `terraform fmt`
- `terraform tidy`
- `terraform clean`

**Hint:** Standardizes indentation and layout.

### 20. In HCP Terraform, what is a 'Variable Set'?

- A collection of modules
- Shared workspace variables
- A provider configuration
- A list of state backups

**Hint:** A way to apply common variables to many workspaces at once.

### 21. Which lifecycle rule prevents a resource from being deleted during an apply or destroy?

- `create_before_destroy`
- `ignore_changes`
- `prevent_destroy`
- `fixed_resource`

**Hint:** Commonly used for high-value data resources.

### 22. What is the primary technical benefit of using Remote Backends?

- Reducing HCL complexity
- State locking and sharing
- Automating cloud login
- Eliminating the need for init

**Hint:** Addresses issues with local file sharing.

### 23. Which flag allows an operation to focus on a single specific resource?

- `-target`
- `-only`
- `-focus`
- `-single`

**Hint:** Used to isolate changes during troubleshooting.

### 24. Which value is used with the 'sensitive' argument to mask CLI output?

- `mask`
- `hide`
- `true`
- `private`

**Hint:** A standard HCL boolean.

### 25. What is the official name for HashiCorp's managed Terraform service?

- HCP Terraform
- Terraform SaaS
- Terraform Hub
- HCP Infrastructure

**Hint:** Reflects the move to the unified Cloud Platform.

### 26. Which block type is used for global settings like the required Terraform version?

- `provider`
- `terraform`
- `settings`
- `version`

**Hint:** Named after the application itself.

### 27. True or False: A provider block must be explicitly defined for every resource in the HCL.

- True
- False

**Hint:** Terraform can often guess based on resource prefixes.

### 28. Which command displays the current state file in a human-readable format?

- `terraform show`
- `terraform list`
- `terraform read`
- `terraform view`

**Hint:** Used to inspect what Terraform is currently managing.

### 29. What is an 'Implicit Dependency' in Terraform?

- Using `depends_on`
- Resource attribute reference
- Manual state modification
- Global variable usage

**Hint:** Created automatically when one resource references another.

### 30. Which command verifies that HCL is syntactically correct and internally consistent?

- `terraform fmt`
- `terraform plan`
- `terraform validate`
- `terraform check`

**Hint:** Checks for logic errors without connecting to the cloud.
