Save 15% on 2 packs BUY2 · 20% on 3+ BUY3

Skip to content

50 Free Terraform Associate 004 Practice Questions and Answers

50 questions for the Terraform Associate 004 exam, each answer explained. Watch it here, try the questions yourself, or read the transcript.

1:22:5250 questionsWatch on YouTube

Questions in this video

Tap an answer to see why it is right or wrong. Tap it again to reset.

Question 1 Play from 00:00

You want to define multiple data disks as nested blocks inside the resource block for a virtual machine.
What Terraform feature would help you define the blocks using the values in a variable?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Count arguments replicate entire resources, not nested blocks within a resource.

Not this one. Try another answer.

Why B is wrong

Collection functions manipulate data but do not generate nested block structures.

Not this one. Try another answer.

Why C is wrong

Local values store computed values but do not generate dynamic nested blocks.

Right, D is the answer.

Why D is right

Dynamic blocks allow you to construct nested blocks (like multiple data disks) using values from a variable or list. The dynamic block iterates over a collection and generates the nested block structure for each item, making it ideal for defining a variable number of similar configuration blocks.

Question 2 Play from 01:35

You developed a new Terraform configuration for two virtual machines with a cloud provider. You’re ready to create the infrastructure for the first time.
Which Terraform command should you run first?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

terraform apply cannot be run before terraform init, as the provider plugins and backend configuration are not yet initialized.

Not this one. Try another answer.

Why B is wrong

While terraform plan should be run before apply, it requires terraform init to have been executed first.

Right, C is the answer.

Why C is right

terraform init must be run first in any Terraform project before running plan or apply. This command initializes the working directory, downloads provider plugins, configures the backend, and prepares the environment for Terraform operations. It is the foundational step required before any other Terraform commands can function properly.

Not this one. Try another answer.

Why D is wrong

terraform show is used to view state information and should only be run after initialization and infrastructure creation.

Question 3 Play from 03:14

What HCP Terraform feature helps organize similar workspaces together and let you configure them as a group?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Variable sets manage variables across workspaces but do not organize or group workspaces themselves.

Not this one. Try another answer.

Why B is wrong

Change requests relate to run approvals and do not organize workspaces.

Right, C is the answer.

Why C is right

Projects in HCP Terraform are the organizational construct that groups related workspaces together, enabling team-based management and allowing configuration of permissions and policies at the project level. This feature helps organize infrastructure by business unit, application, or team.

Not this one. Try another answer.

Why D is wrong

Policy sets enforce policies across workspaces but do not provide organizational grouping functionality.

Question 4 Play from 04:45

Which backend does the Terraform CLI use by default?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Remote backends require explicit configuration and are not the default.

Right, B is the answer.

Why B is right

Terraform uses a local backend by default, storing state in a local file (terraform.tfstate) in the working directory. This is the default behavior when no explicit backend configuration is specified in the Terraform code. Remote, HCP Terraform, and HTTP backends all require explicit configuration, and there is no automatic selection based on the cloud provider.

Not this one. Try another answer.

Why C is wrong

HCP Terraform is an optional backend that must be explicitly configured.

Not this one. Try another answer.

Why D is wrong

Terraform does not automatically select backends based on cloud providers.

Not this one. Try another answer.

Why E is wrong

HTTP backends require explicit configuration and are not a default option.

Question 5 Play from 06:21

What does state locking accomplish?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

State locking does not set a password on the state file; it implements a mutual exclusion mechanism.

Right, B is the answer.

Why B is right

State locking prevents concurrent modifications to the Terraform state by blocking Terraform commands from modifying the state file when another operation is in progress. This ensures data consistency and prevents conflicts when multiple users or processes attempt to modify infrastructure simultaneously. Option A is incorrect because state locking is not a password mechanism. Option C is incorrect because state locking does not encrypt credentials. Option D is incorrect because state locking protects against concurrent modifications, not deletion.

Not this one. Try another answer.

Why C is wrong

State locking does not encrypt credentials; credential encryption is a separate concern handled by backend encryption features.

Not this one. Try another answer.

Why D is wrong

State locking prevents concurrent modifications, not accidental deletion of the state file.

Question 6 Play from 08:19

Which of these can you do with terraform plan? (Choose two.)

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

terraform plan does not schedule execution; scheduling requires external tools.

Right, B is one of the answers.

Why B is right

terraform plan can display an execution plan showing proposed changes, allowing you to verify expectations (option B), and can save that plan to a file for later application with terraform apply (option D). Option A refers to scheduling functionality not available in terraform plan itself. Option C is not a feature of terraform plan; you manage workspaces separately with terraform workspace commands.

Not this one. Try another answer.

Why C is wrong

Executing a plan in a different workspace is not a terraform plan feature.

Right, D is one of the answers.

Why D is right

terraform plan can display an execution plan showing proposed changes, allowing you to verify expectations (option B), and can save that plan to a file for later application with terraform apply (option D). Option A refers to scheduling functionality not available in terraform plan itself. Option C is not a feature of terraform plan; you manage workspaces separately with terraform workspace commands.

Question 7 Play from 09:55

Why would you use the -replace flag for terraform apply?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

The -replace flag does not just destroy; it destroys and then recreates the resource.

Not this one. Try another answer.

Why B is wrong

The -replace flag does not ignore resources; it actively recreates them.

Not this one. Try another answer.

Why C is wrong

The -replace flag only affects the specified resource, not all infrastructure in the workspace.

Right, D is the answer.

Why D is right

The -replace flag forces Terraform to destroy and recreate a specified resource on the next apply, even if no configuration changes have been made. This is useful when a resource needs to be forcefully redeployed without modifying the configuration itself.

Question 8 Play from 11:41

When should you use the force-unlock command?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

A lock acquisition failure message is not sufficient justification; you should investigate the root cause first.

Not this one. Try another answer.

Why B is wrong

Apply failures due to state locks should be resolved by waiting or identifying the blocking operation, not immediately force-unlocking.

Right, C is the answer.

Why C is right

The force-unlock command should only be used when automatic state lock release has failed. This is a recovery mechanism for stuck locks and should not be used casually, as improper use can cause state corruption if another Terraform operation is still running.

Not this one. Try another answer.

Why D is wrong

High priority changes do not warrant bypassing state locking; the locking mechanism protects all operations equally.

Question 9 Play from 13:13

You want to retrieve the ID of an existing cloud resource for use in your Terraform configuration.
Which block type would you use?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

The resource block is used to declare and create new resources, not retrieve information about existing ones.

Not this one. Try another answer.

Why B is wrong

The import command is used to bring existing resources into Terraform state management, not to retrieve resource data for use in configuration.

Right, C is the answer.

Why C is right

Data sources in Terraform retrieve information about existing infrastructure resources for use in your configuration. The data block type is used to query existing cloud resources and make their attributes available for reference.

Not this one. Try another answer.

Why D is wrong

The output block is used to expose values from your configuration to the user, not to retrieve existing resource information.

Question 10 Play from 14:45

What does terraform destroy do?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Terraform destroy removes infrastructure, not code files, and the state file is updated to reflect the destroyed resources.

Right, B is the answer.

Why B is right

The terraform destroy command removes all infrastructure resources that are defined in and tracked by the Terraform state file. It does not delete the Terraform code files or the state file itself. It only destroys the actual cloud resources that Terraform has management responsibility for.

Not this one. Try another answer.

Why C is wrong

Terraform destroy removes infrastructure resources, not the state file; the state file persists after destroy.

Not this one. Try another answer.

Why D is wrong

Terraform destroy acts based on the state file, not by querying all resources in the provider account.

Show all 50 questionsShow fewer questions

Question 11 Play from 16:34

What is the purpose of state locking in a remote backend?

Tap an answer. The reason for that answer shows here.

Right, A is the answer.

Why A is right

State locking in a remote backend prevents multiple Terraform operations from running concurrently and modifying the state simultaneously. This ensures consistency and prevents corruption or conflicts that could occur if two instances tried to update state at the same time.

Not this one. Try another answer.

Why B is wrong

State locking does not create backups; it only prevents concurrent modifications.

Not this one. Try another answer.

Why C is wrong

Encryption is a separate security measure from state locking.

Not this one. Try another answer.

Why D is wrong

State locking does not enforce provider version requirements across instances.

Question 12 Play from 18:12

Which is a benefit of the Terraform state file?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

State files do not schedule recurring infrastructure tasks; that functionality would come from external scheduling systems or cloud services.

Not this one. Try another answer.

Why B is wrong

The desired state is expressed by Terraform code files (configuration), not the state file; the state file tracks actual/current state.

Right, C is the answer.

Why C is right

The Terraform state file serves as the source of truth for resources provisioned with Terraform. It maintains a record of all resources that Terraform has created and manages, allowing Terraform to track what exists in the real world and compare it against the desired configuration to determine what changes need to be made.

Not this one. Try another answer.

Why D is wrong

The state file only tracks resources provisioned by Terraform, not resources created through other means like a public cloud console.

Question 13 Play from 20:07

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?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Top-level check blocks exist in Terraform but are used for test assertions, not for enforcing variable value requirements.

Right, B is the answer.

Why B is right

In Terraform, variable validation is enforced using a validation block nested within the variable block definition. This validation block contains a condition and error_message to enforce specific requirements and block operations if they are not met.

Not this one. Try another answer.

Why C is wrong

Top-level validation blocks do not exist as a Terraform configuration construct.

Not this one. Try another answer.

Why D is wrong

Check blocks cannot be added to variable blocks; they are separate top-level constructs used for testing.

Question 14 Play from 21:48

Where can Terraform not load a provider from?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Terraform can load providers from the local provider plugin cache.

Right, B is the answer.

Why B is right

Terraform cannot load a provider from source code directly. Providers must be compiled binaries. Terraform can load providers from the provider plugin cache (local directory), the official HashiCorp distribution on releases.hashicorp.com, and the plugins directory. Source code would need to be compiled first before it could be used as a provider plugin.

Not this one. Try another answer.

Why C is wrong

Terraform can load providers from the official HashiCorp releases.hashicorp.com distribution.

Not this one. Try another answer.

Why D is wrong

Terraform can load providers from the plugins directory in .terraform.

Question 15 Play from 23:21

You provisioned virtual machines (VMs) on Google Cloud Platform using the gcloud command line tool.
What must be done to manage these VMs using Terraform instead? (Choose two.)

Tap an answer. The reason for that answer shows here.

Right, A is one of the answers.

Why A is right

To manage VMs created outside Terraform with Terraform, you must add a resource block defining the desired state of the VM in your configuration. You then use terraform import to import the existing VM's state into Terraform's state file, linking the resource block to the actual GCP resource. Alternatively, an import block can be used in newer Terraform versions to automate this process. Option B is incorrect because terraform apply -refresh-only only updates state without importing resources. Option D is incorrect because terraform state pull retrieves state but does not import resources.

Not this one. Try another answer.

Why B is wrong

terraform apply -refresh-only updates existing state but does not import new resources from GCP.

Right, C is one of the answers.

Why C is right

To manage VMs created outside Terraform with Terraform, you must add a resource block defining the desired state of the VM in your configuration. You then use terraform import to import the existing VM's state into Terraform's state file, linking the resource block to the actual GCP resource. Alternatively, an import block can be used in newer Terraform versions to automate this process. Option B is incorrect because terraform apply -refresh-only only updates state without importing resources. Option D is incorrect because terraform state pull retrieves state but does not import resources.

Not this one. Try another answer.

Why D is wrong

terraform state pull retrieves the state file content but does not import external resources into Terraform management.

Question 16 Play from 25:25

Which parameters does the import block require? (Choose two.)

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Backend configuration is not required in the import block; it is a separate configuration concern.

Right, B is one of the answers.

Why B is right

B. The target resource address D. The resource ID The import block requires two parameters: the target resource address (the Terraform resource identifier where the resource will be managed) and the resource ID (the identifier from the cloud provider for the existing resource being imported). Backend and provider configurations are separate concerns not required in the import block itself.

Not this one. Try another answer.

Why C is wrong

Provider is configured elsewhere in the Terraform configuration, not as a required parameter in the import block.

Right, D is one of the answers.

Why D is right

B. The target resource address D. The resource ID The import block requires two parameters: the target resource address (the Terraform resource identifier where the resource will be managed) and the resource ID (the identifier from the cloud provider for the existing resource being imported). Backend and provider configurations are separate concerns not required in the import block itself.

Question 17 Play from 26:53

Which command allows you to access all of the attributes and details of a resource managed by Terraform?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

The syntax is incorrect and terraform get is for retrieving modules, not inspecting resources.

Right, B is the answer.

Why B is right

The terraform state show command displays all attributes and details of a specific resource in the state file. This command accepts a resource address as an argument and outputs the complete resource configuration including all attributes. terraform state list only displays resource names without details, terraform get retrieves modules, and the syntax in option A is incorrect.

Not this one. Try another answer.

Why C is wrong

terraform state list only shows resource names and addresses, not their attributes and details.

Not this one. Try another answer.

Why D is wrong

terraform state list without arguments only lists resource names, not their attributes.

Question 18 Play from 28:36

A senior admin accidentally deleted some of your cloud instances.
What will Terraform do when you run terraform apply?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Terraform does not stop and error; it reconciles the difference by rebuilding missing resources.

Right, B is the answer.

Why B is right

When terraform apply is run, Terraform compares the current state file with the actual infrastructure and the desired configuration. When it detects that instances defined in the configuration no longer exist in reality, it will rebuild only those missing instances to match the configuration. Terraform does not error out, rebuild everything from scratch, or tear down the entire workspace.

Not this one. Try another answer.

Why C is wrong

Terraform only rebuilds the specific missing instances, not a completely new infrastructure set.

Not this one. Try another answer.

Why D is wrong

Terraform does not tear down and rebuild the entire workspace; it only addresses the missing resources.

Question 19 Play from 30:23

Which argument can you set on a module block to prevent Terraform from updating the module’s configuration during an init or get operation?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

The count argument controls resource instantiation, not module version management.

Not this one. Try another answer.

Why B is wrong

The lifecycle argument is for resource configuration, not applicable to module blocks for version control.

Not this one. Try another answer.

Why C is wrong

The source argument specifies the location of the module, not whether it should be updated.

Right, D is the answer.

Why D is right

The version argument on a module block constraints which versions of the module can be downloaded and used. By specifying a version constraint, you prevent Terraform from automatically updating to newer versions during terraform init or terraform get operations. This provides control over when module updates occur.

Question 20 Play from 31:50

A Terraform configuration is returning errors when running terraform plan.
How would you enable debug logging to investigate further?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

There is no specific flag to terraform plan that enables debug logging; the solution requires an environment variable.

Not this one. Try another answer.

Why B is wrong

Editing a client configuration file does not enable debug logging in Terraform.

Not this one. Try another answer.

Why C is wrong

Updating the backend configuration does not enable debug logging for terraform plan operations.

Right, D is the answer.

Why D is right

Terraform debug logging is enabled by setting the TF_LOG environment variable (e.g., TF_LOG=DEBUG) before running terraform commands. This environment variable controls the log level for Terraform operations and is the standard method for enabling detailed debugging output to investigate errors during terraform plan or apply.

Question 21 Play from 33:33

When should you run terraform init?

Tap an answer. The reason for that answer shows here.

Right, A is the answer.

Why A is right

terraform init should be run after you begin a new Terraform project and before running terraform plan for the first time. This single initialization prepares the working directory with necessary provider plugins and backend configuration, after which plan and apply can be executed without re-initializing. Running init repeatedly is unnecessary and inefficient.

Not this one. Try another answer.

Why B is wrong

terraform init does not need to be run before every terraform apply; it is a one-time setup operation per project or when configuration significantly changes.

Not this one. Try another answer.

Why C is wrong

terraform init should be run after starting to code, not before, since it needs configuration files to process.

Not this one. Try another answer.

Why D is wrong

terraform init should be run before terraform plan, not after it, since plan requires the initialized environment.

Question 22 Play from 35:36

Once you configure a new Terraform backend with a terraform code block, which command should you use to migrate the state file?

Tap an answer. The reason for that answer shows here.

Right, A is the answer.

Why A is right

terraform init is the command used to initialize a Terraform working directory and migrate state to a newly configured backend. When you change the backend configuration in a terraform block, running terraform init will prompt you to migrate existing state from the old backend to the new one.

Not this one. Try another answer.

Why B is wrong

terraform state rm removes resources from state but does not migrate state between backends.

Not this one. Try another answer.

Why C is wrong

terraform push is not a standard Terraform command and does not exist in modern versions.

Not this one. Try another answer.

Why D is wrong

terraform apply applies changes to infrastructure but does not handle backend migration.

Question 23 Play from 37:04

Which of these statements about HCP Terraform workspaces is false?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

VCS integrations are a core HCP Terraform feature that automatically triggers plans and applies based on repository changes.

Not this one. Try another answer.

Why B is wrong

HCP Terraform provides comprehensive role-based access control for managing team and workspace permissions.

Right, C is the answer.

Why C is right

HCP Terraform workspaces are managed through the web UI, API, and CLI, providing multiple methods to switch between workspaces. You are not restricted to CLI-only access. VCS integrations can trigger runs, role-based access controls are available, and credentials are securely stored, making all other statements true and C the false statement.

Not this one. Try another answer.

Why D is wrong

HCP Terraform securely stores and manages cloud provider credentials with encryption and access controls.

Question 24 Play from 39:00

Which of these is stored in the .terraform directory?

Tap an answer. The reason for that answer shows here.

Right, A is the answer.

Why A is right

The .terraform directory stores downloaded providers and modules required by your configuration. When you run terraform init, Terraform downloads the necessary providers and modules into this directory so they can be used during planning and applying. The lock file is stored at the root level as .terraform.lock.hcl, the state file is stored at the root as terraform.tfstate, and configuration files remain in your working directory.

Not this one. Try another answer.

Why B is wrong

The lock file (.terraform.lock.hcl) is stored in the root directory, not in .terraform.

Not this one. Try another answer.

Why C is wrong

The state file (terraform.tfstate) is stored in the root directory, not in .terraform.

Not this one. Try another answer.

Why D is wrong

Configuration files are stored in your working directory, not in .terraform.

Question 25 Play from 40:37

When you run terraform apply -refresh-only, which of the following is not consulted by Terraform to update the state file?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Authentication credentials are required to query the provider API during refresh operations.

Right, B is the answer.

Why B is right

The terraform apply -refresh-only command updates the state file to match the actual infrastructure without applying any changes from configuration. It consults the provider API to get current infrastructure state, the state file for comparison, and credentials to authenticate. The configuration files themselves are not consulted because no changes are being planned or applied.

Not this one. Try another answer.

Why C is wrong

The actual infrastructure reported by the provider API is the primary source consulted for refresh-only operations.

Not this one. Try another answer.

Why D is wrong

The most recent state file is consulted to determine what Terraform is currently managing.

Question 26 Play from 42:29

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?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Changing the count argument will cause Terraform to modify the resource during plan and apply operations.

Not this one. Try another answer.

Why B is wrong

Removing the resource block from configuration will cause Terraform to destroy the resource during apply operations.

Right, C is the answer.

Why C is right

The terraform state rm command removes a resource from the Terraform state file without destroying the actual infrastructure. This tells Terraform to stop managing the resource while leaving it running in your cloud provider. When you then run terraform destroy, that resource will not be touched.

Not this one. Try another answer.

Why D is wrong

Moved blocks are used to refactor resource addresses within state, not to stop managing specific resources.

Question 27 Play from 44:19

When using multiple configurations of the same Terraform provider, what meta-argument must you include in any non-default provider configurations?

Tap an answer. The reason for that answer shows here.

Right, A is the answer.

Why A is right

The alias meta-argument is required when defining multiple configurations of the same provider. The alias allows you to distinguish between different provider configurations and reference them specifically in resource blocks using the provider meta-argument.

Not this one. Try another answer.

Why B is wrong

The name argument is not a valid meta-argument for provider configuration.

Not this one. Try another answer.

Why C is wrong

The depends_on argument is used to establish resource dependencies, not to configure multiple provider instances.

Not this one. Try another answer.

Why D is wrong

The id argument is not a provider meta-argument and is not used for this purpose.

Question 28 Play from 45:45

How does the use of Infrastructure as Code (IaC) enhance the reliability of your infrastructure? (Choose two.)

Tap an answer. The reason for that answer shows here.

Right, A is one of the answers.

Why A is right

IaC enhances reliability through configuration drift reduction and change review processes. Declarative IaC definitions prevent configuration drift by continuously enforcing desired state, ensuring infrastructure remains consistent. Additionally, proposed changes can be reviewed and validated before deployment, preventing problematic configurations from reaching production.

Not this one. Try another answer.

Why B is wrong

Zero-downtime updates are an advanced deployment strategy (blue-green, canary) and not inherent to IaC itself.

Right, C is one of the answers.

Why C is right

IaC enhances reliability through configuration drift reduction and change review processes. Declarative IaC definitions prevent configuration drift by continuously enforcing desired state, ensuring infrastructure remains consistent. Additionally, proposed changes can be reviewed and validated before deployment, preventing problematic configurations from reaching production.

Not this one. Try another answer.

Why D is wrong

IaC does not prevent incorrect configurations from being deployed; it requires additional validation and testing mechanisms.

Not this one. Try another answer.

Why E is wrong

Automatic scaling to meet demand is an infrastructure capability independent of IaC; scaling policies must be explicitly configured.

Question 29 Play from 47:49

Which type of information does the Terraform Registry provide about the modules it hosts?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

This is incomplete; the registry provides more than just required variables.

Not this one. Try another answer.

Why B is wrong

This is incomplete; the registry provides more than just outputs.

Not this one. Try another answer.

Why C is wrong

This is incomplete; the registry provides more than just optional variables and defaults.

Right, D is the answer.

Why D is right

The Terraform Registry provides comprehensive documentation for hosted modules, including required input variables, optional input variables with their default values, and the outputs that the module produces. All of this information is available to help users understand how to use the module.

Question 30 Play from 49:17

Which of the following is allowed as a Terraform variable name?

Tap an answer. The reason for that answer shows here.

Right, A is the answer.

Why A is right

The variable name 'name' is a valid identifier for a Terraform variable. The options 'source', 'version', and 'count' are reserved keywords or meta-arguments in Terraform that cannot be used as variable names. Reserved words and meta-arguments are protected syntax elements that serve specific purposes in Terraform configurations.

Not this one. Try another answer.

Why B is wrong

source is a reserved keyword used in module and provider blocks.

Not this one. Try another answer.

Why C is wrong

version is a reserved keyword used in provider version constraints.

Not this one. Try another answer.

Why D is wrong

count is a reserved meta-argument used for resource iteration.

Question 31 Play from 50:35

What does Terraform use to deploy infrastructure for different cloud providers?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Terraform uses vendor APIs, not custom APIs developed by HashiCorp, to interact with cloud services.

Not this one. Try another answer.

Why B is wrong

Terraform does not depend on or wrap vendors' CLI tools for deployment.

Not this one. Try another answer.

Why C is wrong

Terraform does not use cloud provider UIs; it interacts programmatically through APIs via providers.

Right, D is the answer.

Why D is right

Terraform uses vendor-specific providers to deploy infrastructure for different cloud platforms. Each provider contains the logic to interact with a particular cloud service's API, abstracting the vendor's API complexity into a consistent Terraform configuration syntax. Providers are the core mechanism enabling Terraform to work across AWS, Azure, Google Cloud, and thousands of other platforms.

Question 32 Play from 52:15

Which of the following locations can Terraform use as a private source for modules? (Choose two.)

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Public repositories on GitHub are public sources, not private sources for modules.

Right, B is one of the answers.

Why B is right

Terraform can use private repositories on GitHub and internally hosted VCS platforms as private module sources. These allow organizations to host proprietary or internal modules securely. The public Terraform Registry and public GitHub repositories are public sources, not private sources.

Not this one. Try another answer.

Why C is wrong

The public Terraform Registry is a public source and does not qualify as a private source for modules.

Right, D is one of the answers.

Why D is right

Terraform can use private repositories on GitHub and internally hosted VCS platforms as private module sources. These allow organizations to host proprietary or internal modules securely. The public Terraform Registry and public GitHub repositories are public sources, not private sources.

Question 33 Play from 53:47

Which command must you run before you run a plan or apply for the first time?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

terraform validate checks configuration syntax but does not initialize the working directory.

Not this one. Try another answer.

Why B is wrong

terraform workspace manages state file workspaces but is not a prerequisite.

Not this one. Try another answer.

Why C is wrong

terraform import brings existing resources into state but requires init to have already run.

Right, D is the answer.

Why D is right

The terraform init command must be run first before any plan or apply operation. This command initializes the working directory, downloads required providers and modules, and prepares the environment for Terraform operations. Without running init, Terraform lacks the necessary dependencies to execute plans or apply configurations.

Question 34 Play from 55:17

Why is it considered important to treat your Terraform state file as sensitive?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

State files do not contain personal information about the last user to update them.

Right, B is the answer.

Why B is right

Terraform state files contain sensitive information including resource passwords, API keys, database credentials, and other secrets that Terraform stores in plaintext. Exposure of the state file compromises security and can lead to unauthorized access to managed infrastructure. This is why state files must be treated as sensitive and protected with encryption and access controls. Option A is incorrect because state files do not contain personal information about users. Option C is incorrect because manual editing of state is a separate concern. Option D is incorrect because state files do not store environment variables from the host machine.

Not this one. Try another answer.

Why C is wrong

While state files can be manually edited, this is not the primary reason they are considered sensitive.

Not this one. Try another answer.

Why D is wrong

State files do not automatically store environment variables from the machine that created them.

Question 35 Play from 57:19

Which is not a benefit of adopting IaC (Infrastructure as Code)?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Reusability of code is a direct benefit of IaC, allowing templates and modules to be reused across projects.

Not this one. Try another answer.

Why B is wrong

Automation is a core benefit of IaC, eliminating manual provisioning steps.

Right, C is the answer.

Why C is right

A GUI (Graphical User Interface) is not a benefit of adopting IaC; in fact, IaC explicitly moves away from GUI-based provisioning toward code-based management. The actual benefits of IaC include reusability of code, automation of infrastructure provisioning, and versioning of infrastructure configurations.

Not this one. Try another answer.

Why D is wrong

Versioning is a fundamental benefit of IaC, enabling infrastructure to be tracked and managed like application code.

Question 36 Play from 58:52

Which configuration consistency error does terraform validate report?

Tap an answer. The reason for that answer shows here.

Right, A is the answer.

Why A is right

terraform validate checks the syntax and structural consistency of Terraform configuration files, including verifying that resource identifiers are not declared more than once. It validates configuration logic before any infrastructure operations occur, catching duplicate resource declarations and other configuration errors.

Not this one. Try another answer.

Why B is wrong

Differences between local and remote state are identified through terraform plan or state comparison, not terraform validate.

Not this one. Try another answer.

Why C is wrong

Out-of-date modules are detected during terraform init or plan operations, not by terraform validate.

Not this one. Try another answer.

Why D is wrong

Whitespace consistency (spaces vs tabs) is not validated by terraform validate; Terraform's HCL parser is flexible about formatting.

Question 37 Play from 1:00:37

You have a list of numbers that represents the number of free CPU cores on each virtual cluster:
numcpus = [ 18, 3, 7, 11, 2]
What Terraform built-in function would you use to select the largest number from the list?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

top() is not a valid Terraform function.

Right, B is the answer.

Why B is right

The max() function is the Terraform built-in function that returns the largest value from a list of numbers. When called with a list like numcpus, it evaluates all elements and returns the maximum value, which would be 18 in this case.

Not this one. Try another answer.

Why C is wrong

ceil() rounds a number up to the nearest integer but does not select the maximum from a list.

Not this one. Try another answer.

Why D is wrong

high[numcpus] is not valid Terraform syntax; indexing with brackets is for accessing specific elements, not finding the maximum.

Question 38 Play from 1:02:13

Which task does terraform init not perform?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

terraform init explicitly sources and downloads remote modules.

Not this one. Try another answer.

Why B is wrong

terraform init connects to and initializes the configured backend.

Right, C is the answer.

Why C is right

terraform init downloads providers and modules, connects to configured backends, and performs backend initialization. It does not validate that all required input variables have values; that validation occurs during terraform plan or apply. Variable validation is a separate process triggered when configuration is evaluated against actual values, not during initialization.

Not this one. Try another answer.

Why D is wrong

terraform init downloads all providers specified in the configuration.

Question 39 Play from 1:03:53

What is the primary purpose of IaC (Infrastructure as Code)?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Defining deployment pipelines is the purpose of CI/CD tools, not the primary purpose of IaC.

Not this one. Try another answer.

Why B is wrong

Cost reduction is a potential benefit but not the primary purpose of IaC.

Right, C is the answer.

Why C is right

The primary purpose of Infrastructure as Code is to programmatically create and configure infrastructure resources. IaC enables infrastructure to be provisioned, modified, and managed through code rather than manual processes, providing repeatability, consistency, and automation.

Not this one. Try another answer.

Why D is wrong

While some IaC tools may support multiple vendors, defining vendor-agnostic APIs is not the primary purpose of IaC.

Question 40 Play from 1:05:29

What is an advantage of immutable infrastructure?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Immutable infrastructure does not provide automatic upgrades; upgrades still require intentional deployment.

Not this one. Try another answer.

Why B is wrong

Immutable infrastructure explicitly avoids in-place upgrades by replacing entire instances.

Right, C is the answer.

Why C is right

Immutable infrastructure enables quicker infrastructure upgrades because new instances are created with updated configurations and old instances are replaced rather than modified in-place. This approach reduces deployment time, complexity, and the risk of partial failures since the entire infrastructure is replaced atomically.

Not this one. Try another answer.

Why D is wrong

While immutable infrastructure can reduce complexity, the primary advantage over mutable approaches is faster deployment speed.

Question 41 Play from 1:07:01

What does the import block do?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Import does not migrate between state files; state pulling/pushing handles state file transfers.

Not this one. Try another answer.

Why B is wrong

Module installation is handled by the module block or terraform init; import is unrelated.

Not this one. Try another answer.

Why C is wrong

Combining state files is not a feature of import; state merging requires manual state manipulation or backend configuration.

Right, D is the answer.

Why D is right

The import block (or terraform import command) is used to bring existing infrastructure resources into Terraform state management. This allows you to take resources that were created outside of Terraform, such as through a cloud console or API, and add them to your Terraform state so they can be managed by Terraform going forward.

Question 42 Play from 1:08:38

You want to create a string that is a combination of a generated random_id and a variable and reuse that string several times in your configuration.
What is the simplest correct way to implement this without repeating the random_id and variable?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Output values are intended for sharing values outside the configuration module, not for internal reuse within a configuration.

Right, B is the answer.

Why B is right

A local value is the simplest and most appropriate way to store a computed value that will be reused multiple times within a configuration. Locals are defined using the locals block and can reference other values like random_id and variables, then be referenced anywhere in the configuration without repetition.

Not this one. Try another answer.

Why C is wrong

Data sources retrieve information from external systems; this use case requires storing a computed value locally.

Not this one. Try another answer.

Why D is wrong

Modules add unnecessary complexity for a simple value computation and reuse pattern.

Question 43 Play from 1:10:18

Which of the following arguments are required when declaring a Terraform output?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

The default argument is optional for outputs and is not required.

Right, B is the answer.

Why B is right

The value argument is the only required argument when declaring a Terraform output. It specifies what value should be exported from the module or configuration. The description, default, and sensitive arguments are all optional and provide additional metadata or behavior for the output.

Not this one. Try another answer.

Why C is wrong

The description argument is optional and provides documentation but is not required.

Not this one. Try another answer.

Why D is wrong

The sensitive argument is optional and controls whether the output value is masked in logs but is not required.

Question 44 Play from 1:11:38

What does terraform apply change after you approve the execution plan? (Choose two.)

Tap an answer. The reason for that answer shows here.

Right, A is one of the answers.

Why A is right

When you approve and run terraform apply, it makes two primary changes: the state file is updated to reflect the current infrastructure, and the cloud infrastructure itself is provisioned or modified according to the execution plan. The execution plan itself is not modified by apply; it is merely followed. The Terraform code remains unchanged unless you edit it separately. The .terraform directory contains cached plugins and does not change as a result of apply.

Right, B is one of the answers.

Why B is right

When you approve and run terraform apply, it makes two primary changes: the state file is updated to reflect the current infrastructure, and the cloud infrastructure itself is provisioned or modified according to the execution plan. The execution plan itself is not modified by apply; it is merely followed. The Terraform code remains unchanged unless you edit it separately. The .terraform directory contains cached plugins and does not change as a result of apply.

Not this one. Try another answer.

Why C is wrong

The execution plan is used by apply but is not changed by it.

Not this one. Try another answer.

Why D is wrong

Your Terraform configuration code is not modified by apply unless you manually edit it.

Not this one. Try another answer.

Why E is wrong

The .terraform directory contains provider plugins and is not modified during apply execution.

Question 45 Play from 1:13:25

Which of these commands makes your code more human-readable?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

terraform show displays the current state or a plan file but does not modify code formatting.

Right, B is the answer.

Why B is right

The terraform fmt command rewrites Terraform configuration files to follow a canonical format and style, making the code more human-readable and consistent across the codebase.

Not this one. Try another answer.

Why C is wrong

terraform output displays output values but does not affect code readability or formatting.

Not this one. Try another answer.

Why D is wrong

terraform validate checks configuration syntax and consistency but does not modify formatting for readability.

Question 46 Play from 1:14:48

What kind of configuration block will manage an infrastructure object with settings specified within the block?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Data blocks retrieve information about existing infrastructure rather than managing new resources.

Not this one. Try another answer.

Why B is wrong

Locals define local values for reuse within a configuration but do not manage infrastructure.

Not this one. Try another answer.

Why C is wrong

Provider blocks configure how Terraform interacts with cloud platforms but do not themselves manage resources.

Right, D is the answer.

Why D is right

A resource block declares and manages infrastructure objects with the settings specified within the block. The resource block syntax is resource "type" "name" { settings }, and it tells Terraform to create or manage an actual infrastructure component like an EC2 instance, database, or network resource.

Question 47 Play from 1:16:14

Your configuration contains a module block that references a module from the Terraform registry, and sets the version argument to 1.0. You just published a new version of the module and updated your configuration to point to version 1.1.
Which command must be run to install the new version?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

terraform apply does not download or update module versions; it applies the configuration.

Right, B is the answer.

Why B is right

terraform init is the command that downloads and installs modules from the Terraform Registry. When you update the version argument in a module block, you must run terraform init to fetch and install the new version of the module.

Not this one. Try another answer.

Why C is wrong

terraform plan generates an execution plan but does not download updated modules.

Not this one. Try another answer.

Why D is wrong

terraform modules is not a valid Terraform command.

Question 48 Play from 1:17:47

What feature stops multiple users from operating on the Terraform state at the same time?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Remote state storage allows centralized state management but does not inherently prevent concurrent access without additional locking mechanisms.

Not this one. Try another answer.

Why B is wrong

Version control tracks changes to files over time but does not prevent simultaneous modifications to the state file.

Right, C is the answer.

Why C is right

State locking is the feature that prevents concurrent operations on Terraform state by multiple users or processes. When enabled, it creates a lock that must be acquired before any state modification can occur, ensuring that only one operation modifies state at a time. This prevents race conditions and state corruption from simultaneous operations.

Not this one. Try another answer.

Why D is wrong

Provider constraints specify which provider versions are compatible with the configuration and have no role in preventing concurrent state access.

Question 49 Play from 1:19:24

Which of the following is not a valid Terraform collection type?

Tap an answer. The reason for that answer shows here.

Not this one. Try another answer.

Why A is wrong

Set is a valid Terraform collection type for storing unique values.

Not this one. Try another answer.

Why B is wrong

List is a valid Terraform collection type for ordered sequences.

Not this one. Try another answer.

Why C is wrong

Map is a valid Terraform collection type for key-value pairs.

Right, D is the answer.

Why D is right

Terraform supports three collection types: list, map, and set. The tree type does not exist in Terraform's type system. Lists are ordered collections of values of the same type, maps are key-value pairs, and sets are unordered collections of unique values.

Question 50 Play from 1:20:41

Which is an advantage of using IaC (Infrastructure as Code) that is not possible when provisioning with a GUI (Graphical User Interface)?

Tap an answer. The reason for that answer shows here.

Right, A is the answer.

Why A is right

The unique advantage of IaC that GUI provisioning cannot provide is the ability to version, reuse, and share infrastructure configuration. IaC allows infrastructure definitions to be treated as code, enabling version control, code reuse across projects, and easy sharing among team members, which are not feasible with GUI-based provisioning.

Not this one. Try another answer.

Why B is wrong

Both IaC and GUI provisioning can be insecure if credentials are mishandled; this is not an IaC-exclusive advantage.

Not this one. Try another answer.

Why C is wrong

Cost is determined by resource usage, not the provisioning method; both approaches provision identical resources at the same cost.

Not this one. Try another answer.

Why D is wrong

Neither IaC nor GUI provisioning inherently prevents manual modifications; both require additional controls like role-based access to prevent drift.

Transcript

Play from 00:00 Question 1. You want to define multiple data disks as nested blocks inside the resource block for a virtual machine. What Terraform feature would help you define the blocks using the values in a variable? Here are the options. Option A. Count arguments. Option B. Collection functions. Option C. Local values. Option D. Dynamic blocks. Pause the video now if you want time to think about the answer.

The correct answer is D. Dynamic blocks. Dynamic blocks allow you to construct nested blocks (like multiple data disks) using values from a variable or list. The dynamic block iterates over a collection and generates the nested block structure for each item, making it ideal for defining a variable number of similar configuration blocks. Now, why are the other options incorrect? Option A is incorrect. Count arguments replicate entire resources, not nested blocks within a resource. Option B is incorrect. Collection functions manipulate data but do not generate nested block structures. Option C is incorrect. Local values store computed values but do not generate dynamic nested blocks. Therefore, D, Dynamic blocks, is the correct answer.

Play from 01:35 Question 2. You developed a new Terraform configuration for two virtual machines with a cloud provider. You’re ready to create the infrastructure for the first time. Which Terraform command should you run first? Here are the options. Option A. terraform apply. Option B. terraform plan. Option C. terraform init. Option D. terraform show. Pause the video now if you want time to think about the answer.

The correct answer is C. terraform init. terraform init must be run first in any Terraform project before running plan or apply. This command initializes the working directory, downloads provider plugins, configures the backend, and prepares the environment for Terraform operations. It is the foundational step required before any other Terraform commands can function properly. Now, why are the other options incorrect? Option A is incorrect. terraform apply cannot be run before terraform init, as the provider plugins and backend configuration are not yet initialized. Option B is incorrect. While terraform plan should be run before apply, it requires terraform init to have been executed first. Option D is incorrect. terraform show is used to view state information and should only be run after initialization and infrastructure creation. Therefore, C, terraform init, is the correct answer.

Play from 03:14 Question 3. What HCP Terraform feature helps organize similar workspaces together and let you configure them as a group? Here are the options. Option A. Variable sets. Option B. Change requests. Option C. Projects. Option D. Policy sets. Pause the video now if you want time to think about the answer.

The correct answer is C. Projects. Projects in HCP Terraform are the organizational construct that groups related workspaces together, enabling team-based management and allowing configuration of permissions and policies at the project level. This feature helps organize infrastructure by business unit, application, or team. Now, why are the other options incorrect? Option A is incorrect. Variable sets manage variables across workspaces but do not organize or group workspaces themselves. Option B is incorrect. Change requests relate to run approvals and do not organize workspaces. Option D is incorrect. Policy sets enforce policies across workspaces but do not provide organizational grouping functionality. Therefore, C, Projects, is the correct answer.

Show full transcriptShow less

Play from 04:45 Question 4. Which backend does the Terraform CLI use by default? Here are the options. Option A. Remote. Option B. Local. Option C. HCP Terraform. Option D. The default backend for the cloud provider. Option E. HTTP. Pause the video now if you want time to think about the answer.

The correct answer is B. Local. Terraform uses a local backend by default, storing state in a local file (terraform.tfstate) in the working directory. This is the default behavior when no explicit backend configuration is specified in the Terraform code. Remote, HCP Terraform, and HTTP backends all require explicit configuration, and there is no automatic selection based on the cloud provider. Now, why are the other options incorrect? Option A is incorrect. Remote backends require explicit configuration and are not the default. Option C is incorrect. HCP Terraform is an optional backend that must be explicitly configured. Option D is incorrect. Terraform does not automatically select backends based on cloud providers. Option E is incorrect. HTTP backends require explicit configuration and are not a default option. Therefore, B, Local, is the correct answer.

Play from 06:21 Question 5. What does state locking accomplish? Here are the options. Option A. Sets a password on the state file. Option B. Blocks Terraform commands from modifying the state file. Option C. Encrypts any credentials stored within the state file. Option D. Prevents accidental deletion of the state file. Pause the video now if you want time to think about the answer.

The correct answer is B. Blocks Terraform commands from modifying the state file. State locking prevents concurrent modifications to the Terraform state by blocking Terraform commands from modifying the state file when another operation is in progress. This ensures data consistency and prevents conflicts when multiple users or processes attempt to modify infrastructure simultaneously. Option A is incorrect because state locking is not a password mechanism. Option C is incorrect because state locking does not encrypt credentials. Option D is incorrect because state locking protects against concurrent modifications, not deletion. Now, why are the other options incorrect? Option A is incorrect. State locking does not set a password on the state file; it implements a mutual exclusion mechanism. Option C is incorrect. State locking does not encrypt credentials; credential encryption is a separate concern handled by backend encryption features. Option D is incorrect. State locking prevents concurrent modifications, not accidental deletion of the state file. Therefore, B, Blocks Terraform commands from modifying the state file, is the correct answer.

Play from 08:19 Question 6. Which of these can you do with terraform plan? (Choose two.) Here are the options. Option A. Schedule Terraform to run at a planned time in the future. Option B. View the execution plan and check if the changes match your expectations. Option C. Execute a plan in a different workspace. Option D. Save a generated execution plan to apply later. Pause the video now if you want time to think about the answer.

The correct answers are B. View the execution plan and check if the changes match your expectations, and D. Save a generated execution plan to apply later. terraform plan can display an execution plan showing proposed changes, allowing you to verify expectations (option B), and can save that plan to a file for later application with terraform apply (option D). Option A refers to scheduling functionality not available in terraform plan itself. Option C is not a feature of terraform plan; you manage workspaces separately with terraform workspace commands. Now, why are the other options incorrect? Option A is incorrect. terraform plan does not schedule execution; scheduling requires external tools. Option C is incorrect. Executing a plan in a different workspace is not a terraform plan feature. Therefore, B and D are the correct answers.

Play from 09:55 Question 7. Why would you use the -replace flag for terraform apply? Here are the options. Option A. You want to force Terraform to destroy a resource on the next apply. Option B. You want Terraform to ignore a resource on the next apply. Option C. You want Terraform to destroy all the infrastructure in your workspace. Option D. You want to force Terraform to destroy and recreate a resource on the next apply. Pause the video now if you want time to think about the answer.

The correct answer is D. You want to force Terraform to destroy and recreate a resource on the next apply. The -replace flag forces Terraform to destroy and recreate a specified resource on the next apply, even if no configuration changes have been made. This is useful when a resource needs to be forcefully redeployed without modifying the configuration itself. Now, why are the other options incorrect? Option A is incorrect. The -replace flag does not just destroy; it destroys and then recreates the resource. Option B is incorrect. The -replace flag does not ignore resources; it actively recreates them. Option C is incorrect. The -replace flag only affects the specified resource, not all infrastructure in the workspace. Therefore, D, You want to force Terraform to destroy and recreate a resource on the next apply, is the correct answer.

Play from 11:41 Question 8. When should you use the force-unlock command? Here are the options. Option A. When you see a status message stating that you cannot acquire the lock. Option B. When apply has failed due to a state lock. Option C. When automatic unlocking has failed. Option D. When you have a high priority change. Pause the video now if you want time to think about the answer.

The correct answer is C. When automatic unlocking has failed. The force-unlock command should only be used when automatic state lock release has failed. This is a recovery mechanism for stuck locks and should not be used casually, as improper use can cause state corruption if another Terraform operation is still running. Now, why are the other options incorrect? Option A is incorrect. A lock acquisition failure message is not sufficient justification; you should investigate the root cause first. Option B is incorrect. Apply failures due to state locks should be resolved by waiting or identifying the blocking operation, not immediately force-unlocking. Option D is incorrect. High priority changes do not warrant bypassing state locking; the locking mechanism protects all operations equally. Therefore, C, When automatic unlocking has failed, is the correct answer.

Play from 13:13 Question 9. You want to retrieve the ID of an existing cloud resource for use in your Terraform configuration. Which block type would you use? Here are the options. Option A. resource. Option B. import. Option C. data. Option D. output. Pause the video now if you want time to think about the answer.

The correct answer is C. data. Data sources in Terraform retrieve information about existing infrastructure resources for use in your configuration. The data block type is used to query existing cloud resources and make their attributes available for reference. Now, why are the other options incorrect? Option A is incorrect. The resource block is used to declare and create new resources, not retrieve information about existing ones. Option B is incorrect. The import command is used to bring existing resources into Terraform state management, not to retrieve resource data for use in configuration. Option D is incorrect. The output block is used to expose values from your configuration to the user, not to retrieve existing resource information. Therefore, C, data, is the correct answer.

Play from 14:45 Question 10. What does terraform destroy do? Here are the options. Option A. Destroys all Terraform code files in the current directory, leaves the state file intact. Option B. Destroys all infrastructure in the Terraform state file. Option C. Destroys the Terraform state file, leaves the infrastructure intact. Option D. Destroys all infrastructure in the configured Terraform provider. Pause the video now if you want time to think about the answer.

The correct answer is B. Destroys all infrastructure in the Terraform state file. The terraform destroy command removes all infrastructure resources that are defined in and tracked by the Terraform state file. It does not delete the Terraform code files or the state file itself. It only destroys the actual cloud resources that Terraform has management responsibility for. Now, why are the other options incorrect? Option A is incorrect. Terraform destroy removes infrastructure, not code files, and the state file is updated to reflect the destroyed resources. Option C is incorrect. Terraform destroy removes infrastructure resources, not the state file; the state file persists after destroy. Option D is incorrect. Terraform destroy acts based on the state file, not by querying all resources in the provider account. Therefore, B, Destroys all infrastructure in the Terraform state file, is the correct answer.

Play from 16:34 Question 11. What is the purpose of state locking in a remote backend? Here are the options. Option A. Ensures only one instance of Terraform can modify state at a time. Option B. Creates a backup of the state file in a secure location. Option C. Encrypts the state in the remote backend. Option D. Requires every instance of Terraform uses the same provider version. Pause the video now if you want time to think about the answer.

The correct answer is A. Ensures only one instance of Terraform can modify state at a time. State locking in a remote backend prevents multiple Terraform operations from running concurrently and modifying the state simultaneously. This ensures consistency and prevents corruption or conflicts that could occur if two instances tried to update state at the same time. Now, why are the other options incorrect? Option B is incorrect. State locking does not create backups; it only prevents concurrent modifications. Option C is incorrect. Encryption is a separate security measure from state locking. Option D is incorrect. State locking does not enforce provider version requirements across instances. Therefore, A, Ensures only one instance of Terraform can modify state at a time, is the correct answer.

Play from 18:12 Question 12. Which is a benefit of the Terraform state file? Here are the options. Option A. A state file can schedule recurring infrastructure tasks. Option B. A state file is the desired state expressed by the Terraform code files. Option C. A state file is a source of truth for resources provisioned with Terraform. Option D. A state file is a source of truth for resources provisioned with a public cloud console. Pause the video now if you want time to think about the answer.

The correct answer is C. A state file is a source of truth for resources provisioned with Terraform. The Terraform state file serves as the source of truth for resources provisioned with Terraform. It maintains a record of all resources that Terraform has created and manages, allowing Terraform to track what exists in the real world and compare it against the desired configuration to determine what changes need to be made. Now, why are the other options incorrect? Option A is incorrect. State files do not schedule recurring infrastructure tasks; that functionality would come from external scheduling systems or cloud services. Option B is incorrect. The desired state is expressed by Terraform code files (configuration), not the state file; the state file tracks actual/current state. Option D is incorrect. The state file only tracks resources provisioned by Terraform, not resources created through other means like a public cloud console. Therefore, C, A state file is a source of truth for resources provisioned with Terraform, is the correct answer.

Play from 20:07 Question 13. 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? Here are the options. Option A. Add a top-level check block. Option B. Add a validation block to the variable block. Option C. Add a top-level validation block. Option D. Add a check block to the variable block. Pause the video now if you want time to think about the answer.

The correct answer is B. Add a validation block to the variable block. In Terraform, variable validation is enforced using a validation block nested within the variable block definition. This validation block contains a condition and error_message to enforce specific requirements and block operations if they are not met. Now, why are the other options incorrect? Option A is incorrect. Top-level check blocks exist in Terraform but are used for test assertions, not for enforcing variable value requirements. Option C is incorrect. Top-level validation blocks do not exist as a Terraform configuration construct. Option D is incorrect. Check blocks cannot be added to variable blocks; they are separate top-level constructs used for testing. Therefore, B, Add a validation block to the variable block, is the correct answer.

Play from 21:48 Question 14. Where can Terraform not load a provider from? Here are the options. Option A. Provider plugin cache. Option B. Source code. Option C. Official HashiCorp distribution on releases.hashicorp.com. Option D. Plugins directory. Pause the video now if you want time to think about the answer.

The correct answer is B. Source code. Terraform cannot load a provider from source code directly. Providers must be compiled binaries. Terraform can load providers from the provider plugin cache (local directory), the official HashiCorp distribution on releases.hashicorp.com, and the plugins directory. Source code would need to be compiled first before it could be used as a provider plugin. Now, why are the other options incorrect? Option A is incorrect. Terraform can load providers from the local provider plugin cache. Option C is incorrect. Terraform can load providers from the official HashiCorp releases.hashicorp.com distribution. Option D is incorrect. Terraform can load providers from the plugins directory in .terraform. Therefore, B, Source code, is the correct answer.

Play from 23:21 Question 15. You provisioned virtual machines (VMs) on Google Cloud Platform using the gcloud command line tool. What must be done to manage these VMs using Terraform instead? (Choose two.) Here are the options. Option A. Add an import block to the configuration. Option B. Run terraform apply -refresh-only. Option C. Add a resource block for the existing VM. Option D. Run terraform state pull. Pause the video now if you want time to think about the answer.

The correct answers are A. Add an import block to the configuration, and C. Add a resource block for the existing VM. To manage VMs created outside Terraform with Terraform, you must add a resource block defining the desired state of the VM in your configuration. You then use terraform import to import the existing VM's state into Terraform's state file, linking the resource block to the actual GCP resource. Alternatively, an import block can be used in newer Terraform versions to automate this process. Option B is incorrect because terraform apply -refresh-only only updates state without importing resources. Option D is incorrect because terraform state pull retrieves state but does not import resources. Now, why are the other options incorrect? Option B is incorrect. terraform apply -refresh-only updates existing state but does not import new resources from GCP. Option D is incorrect. terraform state pull retrieves the state file content but does not import external resources into Terraform management. Therefore, A and C are the correct answers.

Play from 25:25 Question 16. Which parameters does the import block require? (Choose two.) Here are the options. Option A. backend. Option B. The target resource address. Option C. provider. Option D. The resource ID. Pause the video now if you want time to think about the answer.

The correct answers are B. The target resource address, and D. The resource ID. B. The target resource address D. The resource ID The import block requires two parameters: the target resource address (the Terraform resource identifier where the resource will be managed) and the resource ID (the identifier from the cloud provider for the existing resource being imported). Backend and provider configurations are separate concerns not required in the import block itself. Now, why are the other options incorrect? Option A is incorrect. Backend configuration is not required in the import block; it is a separate configuration concern. Option C is incorrect. Provider is configured elsewhere in the Terraform configuration, not as a required parameter in the import block. Therefore, B and D are the correct answers.

Play from 26:53 Question 17. Which command allows you to access all of the attributes and details of a resource managed by Terraform? Here are the options. Option A. terraform get ‘provider_type.name’. Option B. terraform state show ‘provider_type.name’. Option C. terraform state list ‘provider_type.name’. Option D. terraform state list. Pause the video now if you want time to think about the answer.

The correct answer is B. terraform state show ‘provider_type.name’. The terraform state show command displays all attributes and details of a specific resource in the state file. This command accepts a resource address as an argument and outputs the complete resource configuration including all attributes. terraform state list only displays resource names without details, terraform get retrieves modules, and the syntax in option A is incorrect. Now, why are the other options incorrect? Option A is incorrect. The syntax is incorrect and terraform get is for retrieving modules, not inspecting resources. Option C is incorrect. terraform state list only shows resource names and addresses, not their attributes and details. Option D is incorrect. terraform state list without arguments only lists resource names, not their attributes. Therefore, B, terraform state show ‘provider_type.name’, is the correct answer.

Play from 28:36 Question 18. A senior admin accidentally deleted some of your cloud instances. What will Terraform do when you run terraform apply? Here are the options. Option A. Stop and generate an error message about the missing instances. Option B. Rebuild only the instances that were deleted. Option C. Build a completely brand new set of infrastructure. Option D. Tear down the entire workspace’s infrastructure and rebuild it. Pause the video now if you want time to think about the answer.

The correct answer is B. Rebuild only the instances that were deleted. When terraform apply is run, Terraform compares the current state file with the actual infrastructure and the desired configuration. When it detects that instances defined in the configuration no longer exist in reality, it will rebuild only those missing instances to match the configuration. Terraform does not error out, rebuild everything from scratch, or tear down the entire workspace. Now, why are the other options incorrect? Option A is incorrect. Terraform does not stop and error; it reconciles the difference by rebuilding missing resources. Option C is incorrect. Terraform only rebuilds the specific missing instances, not a completely new infrastructure set. Option D is incorrect. Terraform does not tear down and rebuild the entire workspace; it only addresses the missing resources. Therefore, B, Rebuild only the instances that were deleted, is the correct answer.

Play from 30:23 Question 19. Which argument can you set on a module block to prevent Terraform from updating the module’s configuration during an init or get operation? Here are the options. Option A. count. Option B. lifecycle. Option C. source. Option D. version. Pause the video now if you want time to think about the answer.

The correct answer is D. version. The version argument on a module block constraints which versions of the module can be downloaded and used. By specifying a version constraint, you prevent Terraform from automatically updating to newer versions during terraform init or terraform get operations. This provides control over when module updates occur. Now, why are the other options incorrect? Option A is incorrect. The count argument controls resource instantiation, not module version management. Option B is incorrect. The lifecycle argument is for resource configuration, not applicable to module blocks for version control. Option C is incorrect. The source argument specifies the location of the module, not whether it should be updated. Therefore, D, version, is the correct answer.

Play from 31:50 Question 20. A Terraform configuration is returning errors when running terraform plan. How would you enable debug logging to investigate further? Here are the options. Option A. Rerun terraform plan with the correct flag. Option B. Edit the client configuration file. Option C. Update the backend configuration. Option D. Set the correct environment variable. Pause the video now if you want time to think about the answer.

The correct answer is D. Set the correct environment variable. Terraform debug logging is enabled by setting the TF_LOG environment variable (e.g., TF_LOG=DEBUG) before running terraform commands. This environment variable controls the log level for Terraform operations and is the standard method for enabling detailed debugging output to investigate errors during terraform plan or apply. Now, why are the other options incorrect? Option A is incorrect. There is no specific flag to terraform plan that enables debug logging; the solution requires an environment variable. Option B is incorrect. Editing a client configuration file does not enable debug logging in Terraform. Option C is incorrect. Updating the backend configuration does not enable debug logging for terraform plan operations. Therefore, D, Set the correct environment variable, is the correct answer.

Play from 33:33 Question 21. When should you run terraform init? Here are the options. Option A. After you start coding a new Terraform project, and before you run terraform plan for the first time. Option B. Every time you run terraform apply. Option C. Before you start coding a new Terraform project. Option D. After you run terraform plan for the first time in a new Terraform project, and before you run terraform apply. Pause the video now if you want time to think about the answer.

The correct answer is A. After you start coding a new Terraform project, and before you run terraform plan for the first time. terraform init should be run after you begin a new Terraform project and before running terraform plan for the first time. This single initialization prepares the working directory with necessary provider plugins and backend configuration, after which plan and apply can be executed without re-initializing. Running init repeatedly is unnecessary and inefficient. Now, why are the other options incorrect? Option B is incorrect. terraform init does not need to be run before every terraform apply; it is a one-time setup operation per project or when configuration significantly changes. Option C is incorrect. terraform init should be run after starting to code, not before, since it needs configuration files to process. Option D is incorrect. terraform init should be run before terraform plan, not after it, since plan requires the initialized environment. Therefore, A, After you start coding a new Terraform project, and before you run terraform plan for the first time, is the correct answer.

Play from 35:36 Question 22. Once you configure a new Terraform backend with a terraform code block, which command should you use to migrate the state file? Here are the options. Option A. terraform init. Option B. terraform state rm. Option C. terraform push. Option D. terraform apply. Pause the video now if you want time to think about the answer.

The correct answer is A. terraform init. terraform init is the command used to initialize a Terraform working directory and migrate state to a newly configured backend. When you change the backend configuration in a terraform block, running terraform init will prompt you to migrate existing state from the old backend to the new one. Now, why are the other options incorrect? Option B is incorrect. terraform state rm removes resources from state but does not migrate state between backends. Option C is incorrect. terraform push is not a standard Terraform command and does not exist in modern versions. Option D is incorrect. terraform apply applies changes to infrastructure but does not handle backend migration. Therefore, A, terraform init, is the correct answer.

Play from 37:04 Question 23. Which of these statements about HCP Terraform workspaces is false? Here are the options. Option A. You can trigger plans and applies using version control system integrations. Option B. HCP Terraform workspaces offer role-based access controls. Option C. You must use the CLI to switch between workspaces. Option D. HCP Terraform workspaces can securely store cloud credentials. Pause the video now if you want time to think about the answer.

The correct answer is C. You must use the CLI to switch between workspaces. HCP Terraform workspaces are managed through the web UI, API, and CLI, providing multiple methods to switch between workspaces. You are not restricted to CLI-only access. VCS integrations can trigger runs, role-based access controls are available, and credentials are securely stored, making all other statements true and C the false statement. Now, why are the other options incorrect? Option A is incorrect. VCS integrations are a core HCP Terraform feature that automatically triggers plans and applies based on repository changes. Option B is incorrect. HCP Terraform provides comprehensive role-based access control for managing team and workspace permissions. Option D is incorrect. HCP Terraform securely stores and manages cloud provider credentials with encryption and access controls. Therefore, C, You must use the CLI to switch between workspaces, is the correct answer.

Play from 39:00 Question 24. Which of these is stored in the .terraform directory? Here are the options. Option A. Providers and modules. Option B. Lock file. Option C. State file. Option D. Configuration files. Pause the video now if you want time to think about the answer.

The correct answer is A. Providers and modules. The .terraform directory stores downloaded providers and modules required by your configuration. When you run terraform init, Terraform downloads the necessary providers and modules into this directory so they can be used during planning and applying. The lock file is stored at the root level as .terraform.lock.hcl, the state file is stored at the root as terraform.tfstate, and configuration files remain in your working directory. Now, why are the other options incorrect? Option B is incorrect. The lock file (.terraform.lock.hcl) is stored in the root directory, not in .terraform. Option C is incorrect. The state file (terraform.tfstate) is stored in the root directory, not in .terraform. Option D is incorrect. Configuration files are stored in your working directory, not in .terraform. Therefore, A, Providers and modules, is the correct answer.

Play from 40:37 Question 25. When you run terraform apply -refresh-only, which of the following is not consulted by Terraform to update the state file? Here are the options. Option A. Authentication credentials for the provider. Option B. Terraform configuration files defining the resources. Option C. The actual infrastructure as reported by the provider API. Option D. The most recent state file. Pause the video now if you want time to think about the answer.

The correct answer is B. Terraform configuration files defining the resources. The terraform apply -refresh-only command updates the state file to match the actual infrastructure without applying any changes from configuration. It consults the provider API to get current infrastructure state, the state file for comparison, and credentials to authenticate. The configuration files themselves are not consulted because no changes are being planned or applied. Now, why are the other options incorrect? Option A is incorrect. Authentication credentials are required to query the provider API during refresh operations. Option C is incorrect. The actual infrastructure reported by the provider API is the primary source consulted for refresh-only operations. Option D is incorrect. The most recent state file is consulted to determine what Terraform is currently managing. Therefore, B, Terraform configuration files defining the resources, is the correct answer.

Play from 42:29 Question 26. 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? Here are the options. Option A. Change the value of the count argument on the resource. Option B. Remove the resource block from your configuration. Option C. Run terraform state rm aws_instance.ubuntu[1]. Option D. Use a moved block. Pause the video now if you want time to think about the answer.

The correct answer is C. Run terraform state rm aws_instance.ubuntu[1]. The terraform state rm command removes a resource from the Terraform state file without destroying the actual infrastructure. This tells Terraform to stop managing the resource while leaving it running in your cloud provider. When you then run terraform destroy, that resource will not be touched. Now, why are the other options incorrect? Option A is incorrect. Changing the count argument will cause Terraform to modify the resource during plan and apply operations. Option B is incorrect. Removing the resource block from configuration will cause Terraform to destroy the resource during apply operations. Option D is incorrect. Moved blocks are used to refactor resource addresses within state, not to stop managing specific resources. Therefore, C, Run terraform state rm aws_instance.ubuntu[1], is the correct answer.

Play from 44:19 Question 27. When using multiple configurations of the same Terraform provider, what meta-argument must you include in any non-default provider configurations? Here are the options. Option A. alias. Option B. name. Option C. depends_on. Option D. id. Pause the video now if you want time to think about the answer.

The correct answer is A. alias. The alias meta-argument is required when defining multiple configurations of the same provider. The alias allows you to distinguish between different provider configurations and reference them specifically in resource blocks using the provider meta-argument. Now, why are the other options incorrect? Option B is incorrect. The name argument is not a valid meta-argument for provider configuration. Option C is incorrect. The depends_on argument is used to establish resource dependencies, not to configure multiple provider instances. Option D is incorrect. The id argument is not a provider meta-argument and is not used for this purpose. Therefore, A, alias, is the correct answer.

Play from 45:45 Question 28. How does the use of Infrastructure as Code (IaC) enhance the reliability of your infrastructure? (Choose two.) Here are the options. Option A. Configuration drift is reduced with declarative definitions. Option B. Updates are deployed with zero downtime. Option C. Proposed changes can be reviewed before being applied. Option D. Incorrect configurations cannot be deployed. Option E. Infrastructure is automatically scaled to meet demand. Pause the video now if you want time to think about the answer.

The correct answers are A. Configuration drift is reduced with declarative definitions, and C. Proposed changes can be reviewed before being applied. IaC enhances reliability through configuration drift reduction and change review processes. Declarative IaC definitions prevent configuration drift by continuously enforcing desired state, ensuring infrastructure remains consistent. Additionally, proposed changes can be reviewed and validated before deployment, preventing problematic configurations from reaching production. Now, why are the other options incorrect? Option B is incorrect. Zero-downtime updates are an advanced deployment strategy (blue-green, canary) and not inherent to IaC itself. Option D is incorrect. IaC does not prevent incorrect configurations from being deployed; it requires additional validation and testing mechanisms. Option E is incorrect. Automatic scaling to meet demand is an infrastructure capability independent of IaC; scaling policies must be explicitly configured. Therefore, A and C are the correct answers.

Play from 47:49 Question 29. Which type of information does the Terraform Registry provide about the modules it hosts? Here are the options. Option A. Required input variables. Option B. Outputs. Option C. Optional input variables and default values. Option D. All of these are provided. Pause the video now if you want time to think about the answer.

The correct answer is D. All of these are provided. The Terraform Registry provides comprehensive documentation for hosted modules, including required input variables, optional input variables with their default values, and the outputs that the module produces. All of this information is available to help users understand how to use the module. Now, why are the other options incorrect? Option A is incorrect. This is incomplete; the registry provides more than just required variables. Option B is incorrect. This is incomplete; the registry provides more than just outputs. Option C is incorrect. This is incomplete; the registry provides more than just optional variables and defaults. Therefore, D, All of these are provided, is the correct answer.

Play from 49:17 Question 30. Which of the following is allowed as a Terraform variable name? Here are the options. Option A. name. Option B. source. Option C. version. Option D. count. Pause the video now if you want time to think about the answer.

The correct answer is A. name. The variable name 'name' is a valid identifier for a Terraform variable. The options 'source', 'version', and 'count' are reserved keywords or meta-arguments in Terraform that cannot be used as variable names. Reserved words and meta-arguments are protected syntax elements that serve specific purposes in Terraform configurations. Now, why are the other options incorrect? Option B is incorrect. source is a reserved keyword used in module and provider blocks. Option C is incorrect. version is a reserved keyword used in provider version constraints. Option D is incorrect. count is a reserved meta-argument used for resource iteration. Therefore, A, name, is the correct answer.

Play from 50:35 Question 31. What does Terraform use to deploy infrastructure for different cloud providers? Here are the options. Option A. Custom APIs developed by HashiCorp. Option B. Vendors’ CLI tools. Option C. Vendors’ UI. Option D. Vendor-specific providers. Pause the video now if you want time to think about the answer.

The correct answer is D. Vendor-specific providers. Terraform uses vendor-specific providers to deploy infrastructure for different cloud platforms. Each provider contains the logic to interact with a particular cloud service's API, abstracting the vendor's API complexity into a consistent Terraform configuration syntax. Providers are the core mechanism enabling Terraform to work across AWS, Azure, Google Cloud, and thousands of other platforms. Now, why are the other options incorrect? Option A is incorrect. Terraform uses vendor APIs, not custom APIs developed by HashiCorp, to interact with cloud services. Option B is incorrect. Terraform does not depend on or wrap vendors' CLI tools for deployment. Option C is incorrect. Terraform does not use cloud provider UIs; it interacts programmatically through APIs via providers. Therefore, D, Vendor-specific providers, is the correct answer.

Play from 52:15 Question 32. Which of the following locations can Terraform use as a private source for modules? (Choose two.) Here are the options. Option A. Public repository on GitHub. Option B. Internally hosted VCS (Version Control System) platform. Option C. Public Terraform Registry. Option D. Private repository on GitHub. Pause the video now if you want time to think about the answer.

The correct answers are B. Internally hosted VCS (Version Control System) platform, and D. Private repository on GitHub. Terraform can use private repositories on GitHub and internally hosted VCS platforms as private module sources. These allow organizations to host proprietary or internal modules securely. The public Terraform Registry and public GitHub repositories are public sources, not private sources. Now, why are the other options incorrect? Option A is incorrect. Public repositories on GitHub are public sources, not private sources for modules. Option C is incorrect. The public Terraform Registry is a public source and does not qualify as a private source for modules. Therefore, B and D are the correct answers.

Play from 53:47 Question 33. Which command must you run before you run a plan or apply for the first time? Here are the options. Option A. terraform validate. Option B. terraform workspace. Option C. terraform import. Option D. terraform init. Pause the video now if you want time to think about the answer.

The correct answer is D. terraform init. The terraform init command must be run first before any plan or apply operation. This command initializes the working directory, downloads required providers and modules, and prepares the environment for Terraform operations. Without running init, Terraform lacks the necessary dependencies to execute plans or apply configurations. Now, why are the other options incorrect? Option A is incorrect. terraform validate checks configuration syntax but does not initialize the working directory. Option B is incorrect. terraform workspace manages state file workspaces but is not a prerequisite. Option C is incorrect. terraform import brings existing resources into state but requires init to have already run. Therefore, D, terraform init, is the correct answer.

Play from 55:17 Question 34. Why is it considered important to treat your Terraform state file as sensitive? Here are the options. Option A. It contains personal information about the last user to update it. Option B. It can contain information such as resource passwords and keys. Option C. It can be manually edited to change the deployed resources. Option D. It stores all environment variables from the machine that created it. Pause the video now if you want time to think about the answer.

The correct answer is B. It can contain information such as resource passwords and keys. Terraform state files contain sensitive information including resource passwords, API keys, database credentials, and other secrets that Terraform stores in plaintext. Exposure of the state file compromises security and can lead to unauthorized access to managed infrastructure. This is why state files must be treated as sensitive and protected with encryption and access controls. Option A is incorrect because state files do not contain personal information about users. Option C is incorrect because manual editing of state is a separate concern. Option D is incorrect because state files do not store environment variables from the host machine. Now, why are the other options incorrect? Option A is incorrect. State files do not contain personal information about the last user to update them. Option C is incorrect. While state files can be manually edited, this is not the primary reason they are considered sensitive. Option D is incorrect. State files do not automatically store environment variables from the machine that created them. Therefore, B, It can contain information such as resource passwords and keys, is the correct answer.

Play from 57:19 Question 35. Which is not a benefit of adopting IaC (Infrastructure as Code)? Here are the options. Option A. Reusability of code. Option B. Automation. Option C. A GUI (Graphical User Interface). Option D. Versioning. Pause the video now if you want time to think about the answer.

The correct answer is C. A GUI (Graphical User Interface). A GUI (Graphical User Interface) is not a benefit of adopting IaC; in fact, IaC explicitly moves away from GUI-based provisioning toward code-based management. The actual benefits of IaC include reusability of code, automation of infrastructure provisioning, and versioning of infrastructure configurations. Now, why are the other options incorrect? Option A is incorrect. Reusability of code is a direct benefit of IaC, allowing templates and modules to be reused across projects. Option B is incorrect. Automation is a core benefit of IaC, eliminating manual provisioning steps. Option D is incorrect. Versioning is a fundamental benefit of IaC, enabling infrastructure to be tracked and managed like application code. Therefore, C, A GUI (Graphical User Interface), is the correct answer.

Play from 58:52 Question 36. Which configuration consistency error does terraform validate report? Here are the options. Option A. Declaring a resource identifier more than once. Option B. Differences between local and remote state. Option C. An out-of-date module. Option D. A mix of spaces and tabs in configuration files. Pause the video now if you want time to think about the answer.

The correct answer is A. Declaring a resource identifier more than once. terraform validate checks the syntax and structural consistency of Terraform configuration files, including verifying that resource identifiers are not declared more than once. It validates configuration logic before any infrastructure operations occur, catching duplicate resource declarations and other configuration errors. Now, why are the other options incorrect? Option B is incorrect. Differences between local and remote state are identified through terraform plan or state comparison, not terraform validate. Option C is incorrect. Out-of-date modules are detected during terraform init or plan operations, not by terraform validate. Option D is incorrect. Whitespace consistency (spaces vs tabs) is not validated by terraform validate; Terraform's HCL parser is flexible about formatting. Therefore, A, Declaring a resource identifier more than once, is the correct answer.

Play from 1:00:37 Question 37. You have a list of numbers that represents the number of free CPU cores on each virtual cluster: numcpus = [ 18, 3, 7, 11, 2] What Terraform built-in function would you use to select the largest number from the list? Here are the options. Option A. top(numcpus). Option B. max(numcpus). Option C. ceil(numcpus). Option D. high[numcpus]. Pause the video now if you want time to think about the answer.

The correct answer is B. max(numcpus). The max() function is the Terraform built-in function that returns the largest value from a list of numbers. When called with a list like numcpus, it evaluates all elements and returns the maximum value, which would be 18 in this case. Now, why are the other options incorrect? Option A is incorrect. top() is not a valid Terraform function. Option C is incorrect. ceil() rounds a number up to the nearest integer but does not select the maximum from a list. Option D is incorrect. high[numcpus] is not valid Terraform syntax; indexing with brackets is for accessing specific elements, not finding the maximum. Therefore, B, max(numcpus), is the correct answer.

Play from 1:02:13 Question 38. Which task does terraform init not perform? Here are the options. Option A. Sources any remote modules and downloads them. Option B. Connects to the configured backend. Option C. Validates that values are set for all required input variables. Option D. Sources all providers used in the configuration and downloads them. Pause the video now if you want time to think about the answer.

The correct answer is C. Validates that values are set for all required input variables. terraform init downloads providers and modules, connects to configured backends, and performs backend initialization. It does not validate that all required input variables have values; that validation occurs during terraform plan or apply. Variable validation is a separate process triggered when configuration is evaluated against actual values, not during initialization. Now, why are the other options incorrect? Option A is incorrect. terraform init explicitly sources and downloads remote modules. Option B is incorrect. terraform init connects to and initializes the configured backend. Option D is incorrect. terraform init downloads all providers specified in the configuration. Therefore, C, Validates that values are set for all required input variables, is the correct answer.

Play from 1:03:53 Question 39. What is the primary purpose of IaC (Infrastructure as Code)? Here are the options. Option A. To define a pipeline to test and deliver software. Option B. To provision infrastructure cheaply. Option C. To programmatically create and configure resources. Option D. To define a vendor-agnostic API. Pause the video now if you want time to think about the answer.

The correct answer is C. To programmatically create and configure resources. The primary purpose of Infrastructure as Code is to programmatically create and configure infrastructure resources. IaC enables infrastructure to be provisioned, modified, and managed through code rather than manual processes, providing repeatability, consistency, and automation. Now, why are the other options incorrect? Option A is incorrect. Defining deployment pipelines is the purpose of CI/CD tools, not the primary purpose of IaC. Option B is incorrect. Cost reduction is a potential benefit but not the primary purpose of IaC. Option D is incorrect. While some IaC tools may support multiple vendors, defining vendor-agnostic APIs is not the primary purpose of IaC. Therefore, C, To programmatically create and configure resources, is the correct answer.

Play from 1:05:29 Question 40. What is an advantage of immutable infrastructure? Here are the options. Option A. Automatic infrastructure upgrades. Option B. In-place infrastructure upgrades. Option C. Quicker infrastructure upgrades. Option D. Less complex infrastructure upgrades. Pause the video now if you want time to think about the answer.

The correct answer is C. Quicker infrastructure upgrades. Immutable infrastructure enables quicker infrastructure upgrades because new instances are created with updated configurations and old instances are replaced rather than modified in-place. This approach reduces deployment time, complexity, and the risk of partial failures since the entire infrastructure is replaced atomically. Now, why are the other options incorrect? Option A is incorrect. Immutable infrastructure does not provide automatic upgrades; upgrades still require intentional deployment. Option B is incorrect. Immutable infrastructure explicitly avoids in-place upgrades by replacing entire instances. Option D is incorrect. While immutable infrastructure can reduce complexity, the primary advantage over mutable approaches is faster deployment speed. Therefore, C, Quicker infrastructure upgrades, is the correct answer.

Play from 1:07:01 Question 41. What does the import block do? Here are the options. Option A. Migrate resources from one Terraform state file to another. Option B. Install a module. Option C. Combine Terraform state files. Option D. Import existing resources into state. Pause the video now if you want time to think about the answer.

The correct answer is D. Import existing resources into state. The import block (or terraform import command) is used to bring existing infrastructure resources into Terraform state management. This allows you to take resources that were created outside of Terraform, such as through a cloud console or API, and add them to your Terraform state so they can be managed by Terraform going forward. Now, why are the other options incorrect? Option A is incorrect. Import does not migrate between state files; state pulling/pushing handles state file transfers. Option B is incorrect. Module installation is handled by the module block or terraform init; import is unrelated. Option C is incorrect. Combining state files is not a feature of import; state merging requires manual state manipulation or backend configuration. Therefore, D, Import existing resources into state, is the correct answer.

Play from 1:08:38 Question 42. You want to create a string that is a combination of a generated random_id and a variable and reuse that string several times in your configuration. What is the simplest correct way to implement this without repeating the random_id and variable? Here are the options. Option A. Add an output value. Option B. Add a local value. Option C. Use a data source. Option D. Use a module. Pause the video now if you want time to think about the answer.

The correct answer is B. Add a local value. A local value is the simplest and most appropriate way to store a computed value that will be reused multiple times within a configuration. Locals are defined using the locals block and can reference other values like random_id and variables, then be referenced anywhere in the configuration without repetition. Now, why are the other options incorrect? Option A is incorrect. Output values are intended for sharing values outside the configuration module, not for internal reuse within a configuration. Option C is incorrect. Data sources retrieve information from external systems; this use case requires storing a computed value locally. Option D is incorrect. Modules add unnecessary complexity for a simple value computation and reuse pattern. Therefore, B, Add a local value, is the correct answer.

Play from 1:10:18 Question 43. Which of the following arguments are required when declaring a Terraform output? Here are the options. Option A. default. Option B. value. Option C. description. Option D. sensitive. Pause the video now if you want time to think about the answer.

The correct answer is B. value. The value argument is the only required argument when declaring a Terraform output. It specifies what value should be exported from the module or configuration. The description, default, and sensitive arguments are all optional and provide additional metadata or behavior for the output. Now, why are the other options incorrect? Option A is incorrect. The default argument is optional for outputs and is not required. Option C is incorrect. The description argument is optional and provides documentation but is not required. Option D is incorrect. The sensitive argument is optional and controls whether the output value is masked in logs but is not required. Therefore, B, value, is the correct answer.

Play from 1:11:38 Question 44. What does terraform apply change after you approve the execution plan? (Choose two.) Here are the options. Option A. The state file. Option B. The cloud infrastructure. Option C. The execution plan. Option D. The Terraform code. Option E. The .terraform directory. Pause the video now if you want time to think about the answer.

The correct answers are A. The state file, and B. The cloud infrastructure. When you approve and run terraform apply, it makes two primary changes: the state file is updated to reflect the current infrastructure, and the cloud infrastructure itself is provisioned or modified according to the execution plan. The execution plan itself is not modified by apply; it is merely followed. The Terraform code remains unchanged unless you edit it separately. The .terraform directory contains cached plugins and does not change as a result of apply. Now, why are the other options incorrect? Option C is incorrect. The execution plan is used by apply but is not changed by it. Option D is incorrect. Your Terraform configuration code is not modified by apply unless you manually edit it. Option E is incorrect. The .terraform directory contains provider plugins and is not modified during apply execution. Therefore, A and B are the correct answers.

Play from 1:13:25 Question 45. Which of these commands makes your code more human-readable? Here are the options. Option A. terraform show. Option B. terraform fmt. Option C. terraform output. Option D. terraform validate. Pause the video now if you want time to think about the answer.

The correct answer is B. terraform fmt. The terraform fmt command rewrites Terraform configuration files to follow a canonical format and style, making the code more human-readable and consistent across the codebase. Now, why are the other options incorrect? Option A is incorrect. terraform show displays the current state or a plan file but does not modify code formatting. Option C is incorrect. terraform output displays output values but does not affect code readability or formatting. Option D is incorrect. terraform validate checks configuration syntax and consistency but does not modify formatting for readability. Therefore, B, terraform fmt, is the correct answer.

Play from 1:14:48 Question 46. What kind of configuration block will manage an infrastructure object with settings specified within the block? Here are the options. Option A. data. Option B. locals. Option C. provider. Option D. resource. Pause the video now if you want time to think about the answer.

The correct answer is D. resource. A resource block declares and manages infrastructure objects with the settings specified within the block. The resource block syntax is resource "type" "name" { settings }, and it tells Terraform to create or manage an actual infrastructure component like an EC2 instance, database, or network resource. Now, why are the other options incorrect? Option A is incorrect. Data blocks retrieve information about existing infrastructure rather than managing new resources. Option B is incorrect. Locals define local values for reuse within a configuration but do not manage infrastructure. Option C is incorrect. Provider blocks configure how Terraform interacts with cloud platforms but do not themselves manage resources. Therefore, D, resource, is the correct answer.

Play from 1:16:14 Question 47. Your configuration contains a module block that references a module from the Terraform registry, and sets the version argument to 1.0. You just published a new version of the module and updated your configuration to point to version 1.1. Which command must be run to install the new version? Here are the options. Option A. terraform apply. Option B. terraform init. Option C. terraform plan. Option D. terraform modules. Pause the video now if you want time to think about the answer.

The correct answer is B. terraform init. terraform init is the command that downloads and installs modules from the Terraform Registry. When you update the version argument in a module block, you must run terraform init to fetch and install the new version of the module. Now, why are the other options incorrect? Option A is incorrect. terraform apply does not download or update module versions; it applies the configuration. Option C is incorrect. terraform plan generates an execution plan but does not download updated modules. Option D is incorrect. terraform modules is not a valid Terraform command. Therefore, B, terraform init, is the correct answer.

Play from 1:17:47 Question 48. What feature stops multiple users from operating on the Terraform state at the same time? Here are the options. Option A. Remote state storage. Option B. Version control. Option C. State locking. Option D. Provider constraints. Pause the video now if you want time to think about the answer.

The correct answer is C. State locking. State locking is the feature that prevents concurrent operations on Terraform state by multiple users or processes. When enabled, it creates a lock that must be acquired before any state modification can occur, ensuring that only one operation modifies state at a time. This prevents race conditions and state corruption from simultaneous operations. Now, why are the other options incorrect? Option A is incorrect. Remote state storage allows centralized state management but does not inherently prevent concurrent access without additional locking mechanisms. Option B is incorrect. Version control tracks changes to files over time but does not prevent simultaneous modifications to the state file. Option D is incorrect. Provider constraints specify which provider versions are compatible with the configuration and have no role in preventing concurrent state access. Therefore, C, State locking, is the correct answer.

Play from 1:19:24 Question 49. Which of the following is not a valid Terraform collection type? Here are the options. Option A. set. Option B. list. Option C. map. Option D. tree. Pause the video now if you want time to think about the answer.

The correct answer is D. tree. Terraform supports three collection types: list, map, and set. The tree type does not exist in Terraform's type system. Lists are ordered collections of values of the same type, maps are key-value pairs, and sets are unordered collections of unique values. Now, why are the other options incorrect? Option A is incorrect. Set is a valid Terraform collection type for storing unique values. Option B is incorrect. List is a valid Terraform collection type for ordered sequences. Option C is incorrect. Map is a valid Terraform collection type for key-value pairs. Therefore, D, tree, is the correct answer.

Play from 1:20:41 Question 50. Which is an advantage of using IaC (Infrastructure as Code) that is not possible when provisioning with a GUI (Graphical User Interface)? Here are the options. Option A. Let’s you version, reuse, and share infrastructure configuration. Option B. Secures your credentials. Option C. Provisions the same resources at a lower cost. Option D. Prevents manual modifications to your resources. Pause the video now if you want time to think about the answer.

The correct answer is A. Let’s you version, reuse, and share infrastructure configuration. The unique advantage of IaC that GUI provisioning cannot provide is the ability to version, reuse, and share infrastructure configuration. IaC allows infrastructure definitions to be treated as code, enabling version control, code reuse across projects, and easy sharing among team members, which are not feasible with GUI-based provisioning. Now, why are the other options incorrect? Option B is incorrect. Both IaC and GUI provisioning can be insecure if credentials are mishandled; this is not an IaC-exclusive advantage. Option C is incorrect. Cost is determined by resource usage, not the provisioning method; both approaches provision identical resources at the same cost. Option D is incorrect. Neither IaC nor GUI provisioning inherently prevents manual modifications; both require additional controls like role-based access to prevent drift. Therefore, A, Let’s you version, reuse, and share infrastructure configuration, is the correct answer.