HashiCorp Terraform Associate 003 Exam  Dumps and Practice Test Questions Set 7 Q 121- 140

Visit here for our full HashiCorp Terraform Associate 003 exam dumps and practice test questions.

Question 121

Which Terraform feature allows you to define backend configuration for storing the state file remotely, enabling collaboration and state locking?

A) Providers

B) Backends

C) Workspaces

D) Locals

ANSWER: B) Backends

EXPLANATION

Backends in Terraform are the mechanism through which Terraform stores its state, either locally or remotely. They are essential for collaboration, enabling multiple team members to manage the same infrastructure safely and reliably.

A) Providers
Providers define the APIs and resource types Terraform can manage, such as AWS, Azure, or GCP. They do not handle state storage, remote collaboration, or locking mechanisms, making A incorrect.

B) Backends
This is the correct answer. Backends manage where and how Terraform’s state file is stored. Local backends store the state on the user’s filesystem, while remote backends store it in centralized locations like S3, Azure Storage, GCS, or Terraform Cloud. Remote backends enable state locking to prevent race conditions during concurrent operations, maintain version history, and support team collaboration. They allow multiple users to work on the same configuration without conflicts. Backends are highly configurable and support encryption, access controls, and automated versioning to ensure security and integrity of infrastructure state. Proper backend configuration is critical for organizations managing large-scale infrastructure, as it ensures predictability, reduces risk of conflicts, and facilitates recovery in case of failures. For instance, using an S3 backend with DynamoDB for locking allows teams to safely apply changes in parallel while avoiding state corruption. Backends also integrate with Terraform Cloud, supporting collaboration features like run triggers, workspace management, and policy enforcement. This feature underpins modern Terraform workflows, ensuring team-oriented, scalable, and secure state management.

C) Workspaces
Workspaces create isolated state files for different environments, but they rely on backends for remote storage. Workspaces alone do not configure remote storage or state locking, making C incorrect.

D) Locals
Locals compute internal values within a module for reuse but do not manage state storage, remote collaboration, or locking mechanisms. D is incorrect.

Backends define remote state storage, support collaboration, and enable state locking, making B the correct choice.

Question 122

Which Terraform construct is used to compute reusable internal values within a module to reduce repetition and improve maintainability?

A) Variables

B) Locals

C) Outputs

D) Providers

ANSWER: B) Locals

EXPLANATION

Locals are Terraform constructs used to define computed values for reuse within a module. They improve readability, reduce redundancy, and simplify complex expressions, making modules more maintainable.

A) Variables
Variables accept external input values to modules or resources, providing customization but not computing internal reusable values. They do not reduce repetition within the module itself, making A incorrect.

B) Locals
This is the correct answer. Locals allow developers to compute intermediate values based on inputs, resource attributes, or other locals. These computed values can be reused across multiple resources in the module, ensuring consistency and reducing repetition. For example, a local could define a standardized naming convention or a combined subnet list for resources to reference. Locals enhance code readability by centralizing complex expressions and improving maintainability. When modifications are required, they can be made in a single location rather than updating multiple resource definitions. Locals also promote modularity by encapsulating internal logic without exposing it externally. In large infrastructure configurations, locals are essential for reducing errors, improving clarity, and supporting best practices in Infrastructure as Code. They enable teams to maintain consistent patterns, enforce naming or tagging standards, and provide derived calculations for resources efficiently. Locals are a fundamental feature for advanced Terraform module design and operational efficiency.

C) Outputs
Outputs expose values from a module to other modules or configurations but do not compute intermediate internal values. C is incorrect.

D) Providers
Providers define the APIs and resources Terraform can manage but do not provide mechanisms for computing reusable internal values. D is incorrect.

Locals are the proper construct for computing internal reusable values, improving maintainability and readability, making B the correct choice.

Question 123

Which Terraform command is used to apply configuration changes to infrastructure and update the state file accordingly?

A) terraform apply

B) terraform plan

C) terraform init

D) terraform validate

ANSWER: A) terraform apply

EXPLANATION

Terraform apply is the primary command for executing changes defined in Terraform configurations. It updates the infrastructure and the corresponding state file to reflect the current deployment.

A) terraform apply
This is the correct answer. Terraform apply reads the configuration, compares it to the current state, and performs the necessary actions to bring the infrastructure into alignment. It can create, update, or destroy resources based on differences between the configuration and the existing state. Terraform apply also updates the state file to reflect the new infrastructure status, ensuring accurate tracking for subsequent operations. Apply supports variable input via CLI or files, can automatically approve changes, and integrates with remote backends and workspaces. This command is essential for deploying infrastructure changes safely and reliably. It ensures that Terraform’s declarative approach is enforced, with resources managed consistently across environments. Apply also supports targeted operations, where specific resources or modules are modified without affecting others, enhancing operational control. Proper use of terraform apply ensures reproducible, predictable, and controlled deployments in both individual and team environments.

B) terraform plan
Terraform plan previews changes but does not modify infrastructure or the state file. It is non-destructive and only provides visibility into pending actions, making B incorrect.

C) terraform init
Terraform init initializes the working directory, installs providers, and configures backends but does not apply changes to infrastructure. C is incorrect.

D) terraform validate
Terraform validate checks syntax and configuration correctness but does not deploy or modify infrastructure. D is incorrect.

Terraform apply executes configuration changes and updates the state file, making A the correct choice.

Question 124

Which Terraform construct allows you to retrieve read-only information from existing resources or external systems for use in your configuration?

A) Variables

B) Data sources

C) Locals

D) Outputs

ANSWER: B) Data sources

EXPLANATION

Data sources provide a mechanism in Terraform to access existing resource information without creating or modifying infrastructure. They are crucial for dynamic and adaptive configurations.

A) Variables
Variables provide input values to resources or modules but cannot fetch existing infrastructure information. They are designed for parameterization rather than querying, making A incorrect.

B) Data sources
This is the correct answer. Data sources allow Terraform to retrieve information from existing resources, whether managed by Terraform or external. Examples include fetching the latest AMI ID, existing VPCs, subnet IDs, or external service attributes. Data sources are read-only and do not create or alter resources. They enable dynamic module and resource configuration, reduce hardcoding, and improve maintainability. By using data sources, teams ensure that infrastructure remains aligned with real-world resources and avoid duplication or conflicts. Data sources also support collaboration and modularity, allowing multiple modules to consume consistent, up-to-date information from shared resources. They are integral to Infrastructure as Code practices, providing flexibility, adaptability, and safety while maintaining declarative, predictable deployments.

C) Locals
Locals compute internal intermediate values for reuse within a module but do not fetch external or existing resource information. C is incorrect.

D) Outputs
Outputs expose values from a module but cannot retrieve data from existing resources or systems. D is incorrect.

Data sources allow Terraform to safely fetch read-only information from external or existing resources, making B the correct choice.

Question 125

Which Terraform feature enables you to reuse a set of resources, input variables, and outputs across multiple configurations?

A) Modules

B) Workspaces

C) Locals

D) Providers

ANSWER: A) Modules

EXPLANATION

Modules are a foundational construct in Terraform that allow developers to package resources, inputs, and outputs into reusable units. They support modular design, maintainability, and consistent deployment across different environments.

A) Modules
This is the correct answer. Modules encapsulate a group of resources, accept input variables for customization, and expose outputs for use in other modules or configurations. They can be local, sourced from the same repository, or remote from Terraform Registry or Git repositories. Modules support standardization, reduce duplication, and promote best practices in infrastructure design. They allow multiple configurations to use the same module with different variable values, facilitating environment-specific deployments such as dev, staging, and production. Nested modules enable the creation of complex infrastructure hierarchies, while input variables allow flexible customization. Outputs expose critical values to other modules or external processes, maintaining modularity and interoperability. Modules also improve maintainability, as changes in a module propagate to all dependent configurations, ensuring consistent and predictable infrastructure. They enhance collaboration, simplify testing, and allow scalable deployments across large teams or organizations. Using modules effectively supports Infrastructure as Code principles, reduces errors, and streamlines operational workflows, making them indispensable for advanced Terraform practices.

B) Workspaces
Workspaces provide isolated state files for different environments but do not encapsulate resources, inputs, or outputs for reuse. B is incorrect.

C) Locals
Locals compute internal values for reuse within a module but do not package resources or provide outputs for other configurations. C is incorrect.

D) Providers
Providers define APIs and resources Terraform can manage but do not support encapsulation, modularity, or reusable inputs and outputs. D is incorrect.

Modules encapsulate resources, support input variables, and provide outputs for reuse across configurations, making A the correct choice.

Question 126

Which Terraform command is used to check the syntax and internal consistency of configuration files without applying changes?

A) terraform plan

B) terraform apply

C) terraform validate

D) terraform init

ANSWER: C) terraform validate

EXPLANATION

Terraform validate is a command designed to ensure that configuration files are syntactically correct and internally consistent. It performs static checks without interacting with infrastructure or state files, providing a safe method for developers to catch errors early.

A) terraform plan
Terraform plan previews the changes Terraform will make to infrastructure but requires a valid configuration and initialized directory. It is used for planning actions rather than validation, making A incorrect.

B) terraform apply
Terraform apply executes configuration changes against infrastructure and updates the state file. It is destructive if not used carefully and does not focus on syntax validation, making B incorrect.

C) terraform validate
This is the correct answer. Terraform validate examines configuration files to confirm they are syntactically valid and consistent with Terraform rules. It checks for undefined variables, invalid resource attributes, missing providers, and misconfigured modules. It does not interact with remote resources or apply changes, making it a safe pre-deployment check. Validate is particularly useful in automated pipelines, where catching configuration errors before planning or applying changes reduces risk. It ensures that Terraform modules are portable, reusable, and adhere to best practices. When combined with other commands like plan and init, validate provides a comprehensive approach to safe and reliable infrastructure management. It allows teams to enforce standards, prevent runtime errors, and maintain high-quality Infrastructure as Code practices across projects.

D) terraform init
Terraform init initializes the working directory, installs providers, and configures backends but does not validate configuration syntax or internal consistency. D is incorrect.

Terraform validate ensures that configuration files are correct and internally consistent before any planning or applying, making C the correct choice.

Question 127

Which Terraform feature allows you to safely manage multiple environments, such as development, staging, and production, using the same configuration?

A) Workspaces

B) Modules

C) Providers

D) Locals

ANSWER: A) Workspaces

EXPLANATION

Workspaces are a core Terraform feature for managing multiple isolated instances of infrastructure state from a single configuration. They enable environment separation while avoiding duplication of configuration files.

A) Workspaces
This is the correct answer. Each workspace maintains its own state file, allowing the same Terraform configuration to be applied to multiple environments without conflicts. For example, dev, staging, and production environments can exist as separate workspaces, each with its own resources and outputs. Switching between workspaces is done with terraform workspace select, and each workspace maintains its own outputs and state. Workspaces support safe experimentation, testing, and deployment without affecting other environments. They integrate with remote backends for state storage, locking, and versioning, which is crucial for team collaboration. By leveraging workspaces, teams can maintain consistent configurations across multiple environments, enforce best practices, and minimize human error. They also allow scalable environment management, automated pipelines, and controlled testing, which are essential in modern Infrastructure as Code workflows. Workspaces provide an effective solution for multi-environment deployments while maintaining operational safety and predictable infrastructure behavior.

B) Modules
Modules encapsulate resources for reuse but do not provide isolated state files for multiple environments. They are used for modularity, not environment separation. B is incorrect.

C) Providers
Providers define APIs and resources Terraform can manage but do not handle multiple environments or state isolation. C is incorrect.

D) Locals
Locals compute internal values for reuse but do not separate environments or manage state files. D is incorrect.

Workspaces enable safe and isolated environment management, making A the correct choice.

Question 128

Which Terraform construct allows you to expose values from a module to be accessed by other modules or configurations?

A) Variables

B) Outputs

C) Locals

D) Providers

ANSWER: B) Outputs

EXPLANATION

Outputs are used in Terraform to expose key information from a module, allowing other modules, configurations, or external tools to reference values such as resource IDs, IP addresses, or computed attributes.

A) Variables
Variables provide input to modules or resources but do not expose internal values to other modules. They are for parameterization, not output, making A incorrect.

B) Outputs
This is the correct answer. Outputs expose important values from a module, such as generated resource identifiers, computed attributes, or configuration details. Outputs are essential for modular design, allowing modules to communicate information without exposing implementation details. They support sensitive flags to protect confidential data, ensuring security and compliance. Outputs can be consumed by other modules using module references or used in automated pipelines and scripts. This promotes reusability, modularity, and maintainability by allowing modules to remain self-contained while still interoperable. Outputs also integrate with Terraform state, ensuring accurate and up-to-date values are available for dependent modules. Proper use of outputs ensures consistent, predictable, and secure sharing of module data, enabling advanced Infrastructure as Code workflows and modular deployments across complex environments.

C) Locals
Locals compute internal values within a module for reuse but cannot expose values externally. They are purely internal and not accessible outside the module, making C incorrect.

D) Providers
Providers define APIs and resource types Terraform can manage but do not provide mechanisms for exposing module values. D is incorrect.

Outputs enable safe sharing of key module values externally, making B the correct choice.

Question 129

Which Terraform command allows you to safely remove a resource from the state file without deleting the actual resource?

A) terraform destroy

B) terraform state rm

C) terraform apply

D) terraform plan

ANSWER: B) terraform state rm

EXPLANATION

Terraform state rm is a command that allows advanced users to manage state files by removing resources without affecting the actual infrastructure. This is critical for modularization, refactoring, or detaching resources from Terraform management.

A) terraform destroy
Terraform destroy removes resources from both the state file and the infrastructure, which is destructive and not suitable for detaching resources safely. A is incorrect.

B) terraform state rm
This is the correct answer. Terraform state rm removes a resource from the state file, effectively detaching it from Terraform management while leaving the actual infrastructure intact. This is useful when moving resources to a different module, reorganizing state, or excluding specific resources from Terraform control. The command maintains other resources and dependencies, ensuring operational safety. Terraform state rm is a critical tool for advanced infrastructure operations, allowing teams to safely manage state files without risking accidental destruction of live resources. Proper usage supports modularization, environment migrations, and infrastructure refactoring while maintaining consistent and predictable management of Terraform state.

C) terraform apply
Terraform apply executes configuration changes and updates the state file but does not remove resources independently from state. C is incorrect.

D) terraform plan
Terraform plan previews changes between configuration and state but does not remove resources or modify state. D is incorrect.

Terraform state rm allows safe detachment of resources without destruction, making B the correct choice.

Question 130

Which Terraform construct allows you to compute reusable internal values within a module for consistency and maintainability?

A) Variables

B) Locals

C) Outputs

D) Providers

ANSWER: B) Locals

EXPLANATION

Locals in Terraform are used to compute values within a module that can be referenced multiple times, improving maintainability, reducing repetition, and simplifying complex configurations.

A) Variables
Variables accept external inputs but do not compute reusable internal values. They are designed for customization rather than internal reuse, making A incorrect.

B) Locals
This is the correct answer. Locals allow developers to define computed values derived from inputs, other locals, or resource attributes. These values can be used multiple times within the module, promoting consistency and reducing code repetition. Locals improve readability by centralizing complex expressions and allow teams to maintain a single source of truth for computed values. They also support modularity, as internal calculations can be abstracted without exposing implementation details. Locals are particularly valuable in large configurations where repeated logic or naming conventions must be applied across multiple resources. They enhance maintainability, reduce errors, and simplify future modifications. For example, a local can define a standardized naming convention combining environment, project, and resource type, which can then be reused across multiple resources. Locals also integrate seamlessly with variables and outputs, supporting clean, readable, and reusable module design in Infrastructure as Code practices.

C) Outputs
Outputs expose values externally but do not compute reusable internal values within a module. C is incorrect.

D) Providers
Providers define APIs and resource types Terraform can manage but do not support computation of reusable internal values. D is incorrect.

Locals provide reusable, maintainable internal computations, making B the correct choice.

Question 131

Which Terraform feature allows you to store and manage the state file in a remote location, supporting collaboration, state locking, and versioning?

A) Modules

B) Backends

C) Workspaces

D) Locals

ANSWER: B) Backends

EXPLANATION

Backends in Terraform are a critical feature for managing the state file. They determine where and how Terraform stores state data and provide capabilities for remote collaboration, versioning, and locking, which are essential for multi-user environments and team-based infrastructure management.

A) Modules
Modules are designed to encapsulate resources, inputs, and outputs for reuse but do not manage state files, remote storage, or collaboration features. Modules facilitate modularity but do not provide mechanisms for storing or locking state. Therefore, A is incorrect.

B) Backends
This is the correct answer. Backends define the storage location of Terraform state files, which can be local or remote. Remote backends such as AWS S3, GCS, Azure Storage, or Terraform Cloud provide team collaboration capabilities, including state locking to prevent concurrent modifications, versioning to maintain historical records, and access controls to secure sensitive infrastructure information. Backends are foundational for reliable Infrastructure as Code operations, as they ensure that the state is consistent, accurate, and shared safely among multiple operators. Proper configuration of backends allows teams to avoid state corruption, manage multiple environments, and integrate automated CI/CD pipelines for controlled deployments. Backends also enhance disaster recovery strategies by maintaining redundant, versioned state storage and enabling quick restoration of infrastructure state if required. By decoupling state management from local machines, backends support scalable, multi-team workflows, providing governance, predictability, and operational efficiency.

C) Workspaces
Workspaces provide isolated state files for managing multiple environments but rely on backends for storage. Workspaces alone do not handle remote storage, locking, or versioning. Therefore, C is incorrect.

D) Locals
Locals are used to compute reusable values internally within modules but do not manage state files, collaboration, or remote storage. D is incorrect.

Backends are essential for managing remote state with collaboration, locking, and versioning, making B the correct choice.

Question 132

Which Terraform command is used to initialize a working directory, download provider plugins, and configure the backend before running other commands?

A) terraform init

B) terraform plan

C) terraform apply

D) terraform validate

ANSWER: A) terraform init

EXPLANATION

Terraform init is the first command that must be run in a new or cloned Terraform working directory. It prepares the environment for further operations by downloading providers, modules, and configuring the backend.

A) terraform init
This is the correct answer. Terraform init sets up the working directory by downloading provider plugins necessary for interacting with cloud APIs, configuring the backend for state storage, and retrieving modules from local or remote sources. Initialization ensures that all dependencies and configurations are available before planning or applying changes. Proper initialization prevents errors caused by missing providers or misconfigured backends, allowing Terraform commands like plan and apply to run smoothly. Init also supports upgrading provider versions, backend configuration overrides, and module dependency management. It is crucial for ensuring that the working environment is consistent, reproducible, and ready for safe Infrastructure as Code operations. By running init, teams can avoid runtime errors, enforce standard configurations, and enable automated workflows that integrate seamlessly with CI/CD pipelines and collaboration platforms.

B) terraform plan
Terraform plan generates a preview of infrastructure changes but requires a previously initialized working directory. It does not download providers or configure the backend. B is incorrect.

C) terraform apply
Terraform apply executes infrastructure changes and updates the state file but depends on prior initialization. It does not handle environment setup. C is incorrect.

D) terraform validate
Terraform validate checks the syntax and consistency of configuration files but does not perform initialization, download providers, or configure backends. D is incorrect.

Terraform init prepares the working directory, installs providers, and configures the backend, making A the correct choice.

Question 133

Which Terraform feature allows you to compute intermediate values within a module for reuse, improving readability and maintainability?

A) Variables

B) Locals

C) Outputs

D) Providers

ANSWER: B) Locals

EXPLANATION

Locals are an essential construct in Terraform for defining reusable, computed values within a module. They enhance maintainability, readability, and reduce duplication in configurations.

A) Variables
Variables provide inputs from external sources but do not compute or store reusable intermediate values. They are designed for parameterization rather than internal computation, making A incorrect.

B) Locals
This is the correct answer. Locals allow developers to define computed values that can be reused throughout a module. These values can be derived from inputs, other locals, or resource attributes. Using locals centralizes complex logic, reduces repetition, and ensures consistency across resources. For instance, a local can compute a standardized naming convention for resources combining project, environment, and resource type, which can then be referenced across multiple resources within the module. Locals are particularly beneficial in large infrastructure deployments, where repeated logic could lead to inconsistencies or errors if manually duplicated. By leveraging locals, teams can enforce uniform patterns, simplify future changes, and improve overall module readability. Locals also support advanced calculations, concatenations, and conditional expressions, enabling dynamic and flexible configurations without exposing internal logic externally. Proper use of locals contributes to modular design, maintainability, and operational efficiency in Terraform-based Infrastructure as Code practices.

C) Outputs
Outputs expose values from a module externally but do not provide reusable internal computations. C is incorrect.

D) Providers
Providers define APIs and resource types Terraform can manage but do not allow internal computation or reuse of intermediate values. D is incorrect.

Locals compute reusable intermediate values, centralize logic, and improve maintainability, making B the correct choice.

Question 134

Which Terraform command is used to preview the changes Terraform will make to infrastructure without applying them?

A) terraform apply

B) terraform plan

C) terraform init

D) terraform validate

ANSWER: B) terraform plan

EXPLANATION

Terraform plan is a non-destructive command that allows developers to see what actions Terraform will take based on the current configuration and state. This ensures predictability, safety, and visibility before applying changes.

A) terraform apply
Terraform apply executes infrastructure changes and updates the state file, which can have destructive effects. It does not merely preview changes. A is incorrect.

B) terraform plan
This is the correct answer. Terraform plan evaluates the differences between the current state and the desired configuration, generating an execution plan that lists resources to be created, updated, or destroyed. It provides detailed information about resource attributes, dependencies, and proposed modifications, allowing developers to verify intended actions before execution. Plan is essential for preventing unintended consequences, ensuring operational safety, and supporting team collaboration. It can also be integrated into CI/CD pipelines, approval workflows, or review processes. Terraform plan is non-destructive, preserving both the current state and infrastructure while providing a comprehensive view of potential changes. This ensures that changes are predictable, auditable, and safe to implement.

C) terraform init
Terraform init initializes the working directory and downloads providers but does not preview infrastructure changes. C is incorrect.

D) terraform validate
Terraform validate checks configuration syntax and internal consistency but does not provide a preview of planned changes. D is incorrect.

Terraform plan previews changes without applying them, ensuring safe and predictable deployments, making B the correct choice.

 

Question 135

Which Terraform construct allows you to access read-only information about existing infrastructure or external resources for dynamic configuration?

A) Variables

B) Data sources

C) Outputs

D) Locals

ANSWER: B) Data sources

EXPLANATION

Data sources in Terraform provide the ability to query existing infrastructure or external resources, returning information in a read-only manner that can be used for dynamic configuration. This is essential for modular, adaptive, and reusable Terraform code.

A) Variables
Variables provide input values to modules or resources but cannot query existing resources or external systems. They are for parameterization, not data retrieval, making A incorrect.

B) Data sources
This is the correct answer. Data sources allow Terraform to access existing resource attributes without modifying the resource. Examples include fetching the latest AMI ID, existing subnet IDs, security groups, or external service parameters. Data sources ensure that configurations can adapt to the current state of the environment, reducing hardcoding and improving maintainability. They are read-only, ensuring safety and consistency when interacting with pre-existing resources. Data sources are crucial for modular designs, as modules can dynamically consume external data while remaining self-contained. They also facilitate collaboration and scaling, allowing teams to reference shared resources without duplication. Data sources support flexible and predictable Infrastructure as Code practices by providing accurate and current information for resource creation, dependency management, and automated workflows.

C) Outputs
Outputs expose values from a module but do not query existing infrastructure or external systems. C is incorrect.

D) Locals
Locals compute internal intermediate values but cannot retrieve read-only information from existing resources or external systems. D is incorrect.

Data sources safely retrieve read-only information about existing infrastructure for dynamic configuration, making B the correct choice.

Question 136

Which Terraform construct allows you to define a reusable infrastructure component with input variables and outputs for modularity?

A) Providers

B) Modules

C) Workspaces

D) Locals

ANSWER: B) Modules

EXPLANATION

Modules in Terraform are a fundamental construct that encapsulates multiple resources, input variables, and outputs into a reusable and shareable package. They are key to promoting modularity, reducing duplication, and ensuring consistent deployments across different environments.

A) Providers
Providers define the APIs and resource types Terraform can manage, such as AWS, Azure, or Google Cloud. They do not encapsulate resources, manage inputs or outputs, or support modular reuse. Providers are essential for interacting with external systems but do not provide modularity or reusability in configurations. A is incorrect.

B) Modules
This is the correct answer. Modules encapsulate resources into self-contained units that can be reused across multiple configurations or environments. Input variables allow customization of module behavior for different contexts, while outputs provide information back to calling configurations. For example, a networking module can provide outputs for subnet IDs and VPC IDs to be consumed by other modules like compute or security modules. Modules can be local (within the same repository), or remote (sourced from Terraform Registry or Git repositories), promoting collaboration and reuse. Nested modules allow complex infrastructure hierarchies to be built efficiently while maintaining readability and manageability. Modules also enable standardization across teams, reduce the risk of errors, and enhance maintainability. Proper use of modules ensures that infrastructure deployments are predictable, scalable, and follow best practices. They are central to advanced Terraform workflows, supporting versioning, testing, and automation while allowing teams to maintain consistency across environments.

C) Workspaces
Workspaces allow multiple isolated state files for the same configuration, typically to manage environments such as dev, staging, and production. Workspaces do not encapsulate resources or provide reusable inputs and outputs. C is incorrect.

D) Locals
Locals are used to compute intermediate values within a module for internal reuse but do not encapsulate resources or provide outputs to other modules. D is incorrect.

Modules provide reusable, customizable, and self-contained infrastructure components, making B the correct choice.

Question 137

Which Terraform command is used to preview changes to infrastructure without applying them, providing a detailed execution plan?

A) terraform apply

B) terraform plan

C) terraform validate

D) terraform init

ANSWER: B) terraform plan

EXPLANATION

Terraform plan is a non-destructive command that shows exactly what changes Terraform will make to reach the desired state based on configuration and the current state file. This ensures predictability and safety before deployment.

A) terraform apply
Terraform apply executes changes and updates the state file, which can be destructive if not reviewed carefully. It is not a preview tool and does not provide a non-destructive plan by itself. A is incorrect.

B) terraform plan
This is the correct answer. Terraform plan calculates the differences between the current infrastructure state and the desired configuration. It lists all resources to be created, updated, or destroyed, along with the changes to resource attributes. Plan does not modify the state file or infrastructure, making it safe to run multiple times for validation and review. It provides visibility into potential changes, which is essential for audits, approvals, and safe deployment practices. Plan can also be used with variable inputs and workspaces to preview environment-specific changes. In CI/CD pipelines, terraform plan is used to generate human-readable or machine-readable output for automated reviews or approvals. By using plan, teams can detect configuration errors, identify unintended changes, and ensure that deployments follow organizational standards and best practices. Proper use of terraform plan reduces risk, enhances operational safety, and enables predictable infrastructure automation.

C) terraform validate
Terraform validate checks the syntax and internal consistency of configuration files but does not calculate or preview resource changes. C is incorrect.

D) terraform init
Terraform init initializes the working directory, downloads providers, and configures the backend, but it does not preview changes. D is incorrect.

Terraform plan provides a safe, detailed preview of changes without applying them, making B the correct choice.

Question 138

Which Terraform feature allows you to create multiple isolated state files for managing different environments using the same configuration?

A) Workspaces

B) Modules

C) Providers

D) Locals

ANSWER: A) Workspaces

EXPLANATION

Workspaces are an essential Terraform feature that allows teams to maintain separate state files for different environments such as development, staging, and production while using the same configuration.

A) Workspaces
This is the correct answer. Each workspace has an independent state file, meaning resources created in one workspace do not interfere with resources in another. For example, the same Terraform configuration can be applied to a “dev” workspace to create testing infrastructure and to a “prod” workspace for production deployment. Switching between workspaces is done with terraform workspace select, and each workspace maintains its own outputs, state, and variables. Workspaces integrate with remote backends, providing team collaboration, state locking, and versioning. This allows multiple team members to work concurrently without conflicting changes. Workspaces also support automated pipelines, environment-specific deployments, and testing workflows. They provide operational safety by isolating infrastructure environments while allowing teams to use the same base configuration. Workspaces are critical in organizations that manage multiple environments, as they reduce duplication, promote consistency, and enhance scalability of infrastructure management.

B) Modules
Modules encapsulate reusable infrastructure resources but do not provide isolated state files for multiple environments. B is incorrect.

C) Providers
Providers define external systems and resource types Terraform can manage but do not handle isolated states or environment separation. C is incorrect.

D) Locals
Locals compute intermediate internal values but do not create isolated states or manage multiple environments. D is incorrect.

Workspaces enable multiple isolated states for different environments, making A the correct choice.

Question 139

Which Terraform construct allows you to retrieve read-only information from existing resources or external systems for dynamic configurations?

A) Variables

B) Data sources

C) Outputs

D) Locals

ANSWER: B) Data sources

EXPLANATION

Data sources are used in Terraform to fetch information from existing infrastructure or external resources without making changes. They allow configurations to be dynamic and adaptable.

A) Variables
Variables provide input values for modules or resources but do not fetch existing resource information. They are for parameterization, not querying infrastructure, making A incorrect.

B) Data sources
This is the correct answer. Data sources enable Terraform to read information from existing resources managed by Terraform or external systems. Examples include retrieving subnet IDs, AMI IDs, security groups, or cloud-specific service attributes. Data sources are read-only, meaning they do not create or modify infrastructure, ensuring safety when integrating with existing environments. They are crucial for modular and dynamic configurations because they allow modules to reference real-world infrastructure without hardcoding values. By using data sources, teams can maintain reusable modules, adapt to changes in the environment, and avoid duplication. Data sources also support automation and CI/CD pipelines by providing accurate, up-to-date information for dependent resources. They are essential for advanced Infrastructure as Code practices, supporting flexibility, maintainability, and safe integration with pre-existing infrastructure.

C) Outputs
Outputs expose values from a module but do not fetch information from existing resources. They provide data externally but cannot retrieve dynamic information. C is incorrect.

D) Locals
Locals compute intermediate values internally but cannot query existing resources or external systems. D is incorrect.

Data sources provide read-only access to existing resources for dynamic and adaptable configurations, making B the correct choice.

Question 140

Which Terraform command is used to remove a resource from the state file without affecting the actual infrastructure?

A) terraform destroy

B) terraform state rm

C) terraform apply

D) terraform plan

ANSWER: B) terraform state rm

EXPLANATION

Terraform state rm is an advanced command that allows safe removal of resources from the state file while leaving the actual infrastructure untouched. This is critical for resource refactoring, migration, or selective management.

A) terraform destroy
Terraform destroy removes resources from both the state file and infrastructure. It is destructive and does not allow safe detachment, making A incorrect.

B) terraform state rm
This is the correct answer. Terraform state rm removes a resource from the state file without deleting the underlying infrastructure. It allows teams to decouple resources from Terraform management, migrate resources between modules, or reorganize state files. The command ensures that dependencies and other resources remain intact, preventing accidental deletion or corruption. It is an essential tool for maintaining large-scale or complex Terraform deployments safely. Proper usage supports refactoring, modularization, and infrastructure evolution without operational risk. Terraform state rm allows advanced users to manage Terraform state efficiently while keeping live resources untouched, ensuring operational safety and predictable outcomes.

C) terraform apply
Terraform apply executes configuration changes but cannot remove a resource from the state independently. C is incorrect.

D) terraform plan
Terraform plan previews infrastructure changes but does not remove resources or modify state. D is incorrect.

Terraform state rm allows safe detachment of resources from state without destruction, making B the correct choice.

img