Courseiva

HashiCorp Certified: Terraform Authoring and Operations Professional (AWS provider) (AWS provider) (AWS provider) — Questions 76–150

278 questions total · 4 pages · All types, answers revealed

Page 1

Page 2 of 4

Page 3
76
Multi-Selecthard

Which THREE actions are best practices when publishing a module to a private registry?

Select 3 answers
A.Use Semantic Versioning (SemVer) for all releases.
B.Include a 'examples/' directory to show usage.
C.Keep all files in the root folder, including tests.
D.Include a README.md file in the root of the module.
E.Prefix the repository name with 'terraform-provider-'.
AnswersA, B, D

Semantic Versioning communicates breaking, feature and patch changes predictably, letting consumers pin safe ranges. Applying SemVer to every release satisfies the stem's best-practice requirement for a private registry, where consumers depend on clear version signals.

Why this answer

Option A is correct because Semantic Versioning (MAJOR.MINOR.PATCH) gives consumers a predictable contract: breaking changes bump MAJOR, backward-compatible features bump MINOR, and fixes bump PATCH, which private registries rely on for version constraints and dependency resolution. Option B is correct because an 'examples/' directory provides runnable usage snippets that document real inputs/outputs and let consumers validate the module before adopting it. Option D is correct because a root-level README.md is the primary documentation surface a private registry renders, explaining purpose, inputs, outputs, and usage.

Option C is not a best practice because mixing tests and all files in the root harms maintainability; tests belong in a 'tests/' or 'test/' directory and modules should be organized into logical subfolders. Option E is not a best practice for a module because the 'terraform-provider-' prefix is a naming convention for Terraform providers, not reusable modules, so it would be misleading.

Exam trap

AWS provider exams often test whether candidates know the reserved naming conventions — the trap is confusing provider repository prefixes (terraform-provider-) with module repository prefixes (terraform-<PROVIDER>-<NAME>), and assuming test files belong at the module root.

77
MCQmedium

Two engineers on your team run `terraform apply` against the same HCP Terraform workspace within seconds of each other. The workspace uses remote execution and has no run triggers configured. What does HCP Terraform do to coordinate these concurrent runs?

A.The second run overwrites the first run's plan file and applies against the latest state snapshot automatically.
B.The second run is queued and can only start after the first run reaches a terminal state, respecting the workspace's run queue.
C.Both runs execute in parallel and Terraform resolves conflicts by last-writer-wins on each resource.
D.The second run fails immediately with a state lock error because DynamoDB locking is not configured.
AnswerB

HCP Terraform places runs in a per-workspace queue and permits only one run to hold the workspace lock at a time. The second run waits until the first finishes, is discarded, or is canceled. This serialization prevents concurrent state mutation and is the platform's built-in coordination mechanism for teams applying to a shared workspace.

Why this answer

HCP Terraform enforces a single active run per workspace by queueing subsequent runs. The queued run begins only after the active run completes, which prevents simultaneous state mutations and keeps the team's changes ordered. Engineers can cancel or discard queued runs if a newer change supersedes them.

Exam trap

The trap here is conflating self-managed S3/DynamoDB state locking with the HCP Terraform hosted run queue.

78
MCQmedium

When a resource is marked as 'tainted', what is the expected outcome of the next 'terraform apply'?

A.It is ignored.
B.It is destroyed and recreated.
C.It is removed from the state file.
D.It is updated in place.
AnswerB

This is the definition of tainting.

Why this answer

A tainted resource is one Terraform has marked as degraded or partially created, so the next 'terraform apply' will destroy the existing object and create a fresh replacement. This is the standard recovery mechanism when a resource is in an unhealthy or unknown state but you want to keep it managed by Terraform.

Exam trap

The trap is confusing 'tainted' with 'removed from state' — candidates think tainting deletes the resource record, but it only flags it for replacement on the next apply.

How to eliminate wrong answers

Option A is wrong because tainting explicitly forces action — Terraform will not ignore a tainted resource during the next apply. Option C is wrong because tainting does not remove the resource from state; the resource remains tracked, just flagged for replacement. Removing from state requires 'terraform state rm'.

Option D is wrong because tainting forces destroy-and-recreate, not an in-place update — in-place updates occur when only mutable attributes change.

79
MCQmedium

What is the purpose of 'Project' in HCP Terraform?

A.To define the Sentinel policies for an environment.
B.To store Terraform state files securely.
C.To group workspaces and manage access control for teams.
D.To define the cloud provider budget.
AnswerC

Projects provide a grouping layer above workspaces, letting teams organise related workspaces and apply team access permissions across the whole collection. This satisfies the scenario by centralising access control instead of managing permissions workspace by workspace.

Why this answer

Projects are used to group workspaces, allowing for easier team permission management and organization.

80
MCQeasy

Which file stores the mapping between your Terraform configuration and the real-world infrastructure?

A.terraform.tfstate
B.terraform.tfvars
C.provider.tf
D.backend.tf
AnswerA

Terraform records each resource's real-world identity and attribute values in terraform.tfstate, the sole artefact binding configuration addresses to actual infrastructure. Without it, Terraform cannot detect drift or determine which objects to update or destroy, so it is the mapping file the question asks for.

Why this answer

The `terraform.tfstate` file is Terraform's state file, which stores the mapping between resources declared in configuration and the real-world infrastructure objects, including their attributes and dependencies. It is the source of truth Terraform uses to plan changes and detect drift.

Exam trap

The trap is confusing the state file with the backend configuration file — `backend.tf` tells Terraform where to store state, but the actual mapping lives in `terraform.tfstate`.

How to eliminate wrong answers

Option B is wrong because `terraform.tfvars` stores variable values, not the resource-to-infrastructure mapping. Option C is wrong because `provider.tf` configures provider plugins and their authentication, not state. Option D is wrong because `backend.tf` configures where state is stored (e.g., S3, HCP Terraform), but the actual mapping is in the state file itself, not the backend configuration file.

81
MCQeasy

What is the correct way to specify a version constraint for a provider that must be at least 3.0 but less than 4.0?

A.version = ">= 3.0"
B.version = "3.0"
C.version = "> 3.0, < 4.0"
D.version = "~> 3.0"
AnswerD

The pessimistic constraint operator ~> 3.0 permits versions from 3.0 upward but below 4.0, since it locks the major version while allowing minor and patch increments. This satisfies the stated range of at least 3.0 and less than 4.0.

Why this answer

The pessimistic constraint operator ~> 3.0 means '>= 3.0 and < 4.0', allowing any 3.x release while preventing upgrades to 4.0. This matches the requirement of at least 3.0 but less than 4.0 exactly. It is the idiomatic Terraform way to pin to a major version while accepting minor and patch updates.

Exam trap

The trap is confusing ~> 3.0 (allows 3.x) with ~> 3.0.0 (allows only 3.0.x), or picking >= 3.0 which lacks the required upper bound.

How to eliminate wrong answers

Option A is wrong because >= 3.0 has no upper bound, so it would allow 4.0 and beyond, violating the less-than-4.0 requirement. Option B is wrong because "3.0" is an exact version pin, not a range — it would reject 3.1, 3.2, etc., which the requirement allows. Option C is wrong because > 3.0 excludes 3.0 itself (the requirement says at least 3.0, i.e. >= 3.0), and while < 4.0 is correct, the combination fails the inclusive lower bound.

82
MCQmedium

You have an AWS Lambda function defined with the aws_lambda_function resource. The function's source code is packaged in an S3 object. You want Terraform to replace the Lambda function whenever the S3 object's ETag changes, indicating a new version of the code. Which configuration should you add to the aws_lambda_function resource?

A.lifecycle { prevent_destroy = true }
B.lifecycle { replace_triggered_by = [aws_s3_object.lambda_package.etag] }
C.lifecycle { ignore_changes = [s3_key] }
D.lifecycle { create_before_destroy = true }
AnswerB

replace_triggered_by with the S3 object's etag attribute will trigger replacement of the Lambda function whenever the ETag changes. This directly ties the function's lifecycle to the code version, ensuring updates when the code changes. It is the precise solution for the scenario.

Why this answer

Using replace_triggered_by with the S3 object's etag attribute ensures the Lambda function is replaced when the code changes, as indicated by the ETag. The other options either ignore changes, control order, or block destruction, none of which trigger replacement based on ETag.

Exam trap

The trap here is thinking that create_before_destroy triggers replacement, but it only controls the order once replacement is already triggered.

83
MCQhard

You are configuring run triggers in HCP Terraform to orchestrate a multi-workspace deployment on AWS. Workspace A provisions a VPC and outputs the VPC ID. Workspace B needs to consume that VPC ID to deploy subnets. You want Workspace B to automatically start a run after Workspace A successfully applies. Which configuration should you implement?

A.In Workspace B, add a run trigger that references Workspace A as the source workspace.
B.In Workspace A, add a run trigger that references Workspace B as the destination workspace.
C.Use a Terraform data source in Workspace B to read the remote state of Workspace A.
D.Configure a webhook in Workspace A that calls the HCP Terraform API to start a run in Workspace B.
AnswerA

Run triggers are configured on the destination workspace. By adding a run trigger in Workspace B that references Workspace A, you ensure that a successful apply in Workspace A automatically queues a run in Workspace B. This is the correct way to set up a dependency between workspaces.

Why this answer

Run triggers are defined on the destination workspace, specifying the source workspace whose successful apply will trigger a run. This enables dependency chains between workspaces. Reading remote state does not trigger runs, and webhooks are for notifications, not native orchestration.

Exam trap

The trap here is thinking that run triggers are configured on the source workspace to push to a destination, when they are actually configured on the destination to pull from a source.

84
MCQmedium

You manage an AWS RDS DB instance with Terraform. During a maintenance window, an operator manually resizes the instance class in the AWS Management Console. You want Terraform to detect this drift on the next plan but NOT automatically revert it, so you can decide later. What should you do?

A.Run `terraform refresh` and then `terraform apply` to bring the instance back to the declared size.
B.Run `terraform plan` normally; the plan will show the drift as an in-place update, and you can defer applying.
C.Import the DB instance again with `terraform import` to update the state with the new instance class.
D.Add `lifecycle { ignore_changes = [instance_class] }` to the DB instance so the drift is ignored.
AnswerB

By default, plan refreshes state against AWS and compares to configuration. The manually changed instance class will appear as an in-place update to restore the declared value. Simply not applying leaves the drift in place for later review, which matches the requirement to detect but not revert automatically.

Why this answer

A standard plan performs a refresh by default, comparing the real AWS resource against the configuration. The manual instance class change appears as an in-place update, so the drift is visible without applying. Deferring apply preserves the drift until you decide whether to accept it or revert it.

Exam trap

The trap here is assuming that ignoring an attribute is the way to handle drift, when ignoring actually suppresses detection rather than surfacing it.

85
MCQeasy

A team wants to prevent any terraform apply from running in a production workspace unless a specific individual has reviewed and approved the plan. Which HCP Terraform capability should they enable?

A.Add a Sentinel policy with the advisory enforcement level to the workspace.
B.Set the workspace's execution mode to Local so each engineer applies from their own machine after review.
C.Enable the organization setting that requires two-factor authentication for all members.
D.Configure the workspace with manual apply and assign a team the run approval permission for that workspace.
AnswerD

Manual apply causes HCP Terraform to pause after a successful plan until someone confirms the apply, and the run approval permission restricts who may confirm. Together they ensure a designated reviewer must approve before production changes proceed, which is precisely the gated workflow the team requires.

Why this answer

Manual apply introduces a pause between plan and apply, and the run approval permission controls who is allowed to confirm. Assigning that permission to the intended reviewers means an apply cannot proceed in the production workspace until one of them approves the plan, giving the enforced human gate the team wants.

Exam trap

The trap here is confusing policy enforcement with human approval, when only manual apply plus run approval permissions gates an apply on a person reviewing the plan.

86
MCQmedium

You are authoring a Terraform module that creates an AWS IAM policy. The policy's Statement blocks must be generated from a list of objects, but each Statement must also conditionally include a Condition block only when the object's condition attribute is non-null. Which approach correctly generates the Statement blocks while conditionally including the nested Condition block?

A.Use a dynamic "statement" block with for_each over the list, and inside each statement block include a Condition block unconditionally, setting its values to null when not needed.
B.Use a dynamic "statement" block with for_each over the list, and inside each statement block use a nested dynamic "condition" block with for_each set to a one-element list when the condition attribute is non-null, or an empty list otherwise.
C.Use a for expression to build a list of statement objects, then pass that list directly to the statement argument of the aws_iam_policy_document data source.
D.Use a count meta-argument on a null_resource to loop over the list, and use provisioners to construct the policy JSON, then pass it to aws_iam_policy.
AnswerB

This is correct because dynamic blocks can be nested, and conditionally including a nested block is best achieved by setting the inner dynamic block's for_each to a one-element list or an empty list based on the condition. This pattern is idiomatic HCL for optional nested blocks and preserves the correct structure.

Why this answer

The correct approach uses nested dynamic blocks with conditional for_each to generate optional nested blocks. This is the standard HCL pattern for conditionally including blocks based on input data. It ensures that the Condition block is only present when needed, avoiding invalid policy documents.

The other options either misuse data sources, create empty blocks, or rely on provisioners, which are not appropriate for this declarative configuration.

Exam trap

The trap here is assuming that setting nested block arguments to null is equivalent to omitting the block entirely, which is not true for many providers including AWS IAM policies.

87
MCQeasy

In HCP Terraform, you have a workspace that uses the CLI-driven workflow. A team member runs terraform apply locally and then pushes the updated state to HCP Terraform. What is the primary benefit of this workflow?

A.It enforces policy checks before every apply.
B.It provides a fully managed remote execution environment for Terraform operations.
C.It automatically runs speculative plans on pull requests.
D.It allows local execution while still leveraging HCP Terraform for state storage and collaboration.
AnswerD

The CLI-driven workflow lets users run Terraform commands on their local machine, but state is stored remotely in HCP Terraform. This provides the benefits of remote state management, such as locking and versioning, while allowing developers to use their local tooling and environment.

Why this answer

The CLI-driven workflow in HCP Terraform is designed for users who prefer to run Terraform locally but want to use HCP Terraform for state storage and team collaboration. It combines local execution flexibility with remote state management, enabling state locking and version history without requiring remote runs.

Exam trap

The trap here is assuming that CLI-driven workflows include remote execution; they do not—Terraform runs locally, and only state is managed remotely.

88
MCQhard

An operations engineer runs terraform init in a CI pipeline and notices the .terraform.lock.hcl file lists hashes for linux_amd64 only. A developer on macOS arm64 runs terraform init in the same repository and Terraform downloads a different provider build. The team wants the lock file to include hashes for both platforms so CI and developer workstations verify the same provider artifacts. Which command should the engineer run?

A.terraform providers schema -json > lock.hcl
B.terraform providers mirror ./vendor -platform=linux_amd64 -platform=darwin_arm64
C.terraform init -upgrade -platform=linux_amd64,darwin_arm64
D.terraform providers lock -platform=linux_amd64 -platform=darwin_arm64
AnswerD

The providers lock command regenerates the dependency lock file and, with repeated -platform flags, records hashes for each specified platform. Including linux_amd64 and darwin_arm64 makes the lock file cover both the CI runner and the Apple Silicon developer workstation, so both environments verify the same provider versions and hashes during init.

Why this answer

The dependency lock file records provider package hashes per platform. Running terraform providers lock with an explicit -platform flag for each target OS and architecture regenerates the lock file so it contains hashes for linux_amd64 and darwin_arm64. Subsequent init runs on either platform then verify the selected provider build against the recorded hashes without conflict.

Exam trap

The trap here is assuming terraform init can add platform hashes, when only terraform providers lock accepts repeated -platform flags to record hashes for multiple operating systems and architectures.

89
MCQeasy

What is the purpose of the 'terraform init' command when working with modules?

A.It compiles the modules into machine code.
B.It pushes your local modules to the registry.
C.It downloads and installs the modules specified in the configuration.
D.It updates the state file to match the modules.
AnswerC

terraform init initialises the working directory by downloading and installing modules declared in module blocks, along with providers and backend configuration. This satisfies the scenario's need to make module source code available locally before plan or apply can reference it.

Why this answer

'terraform init' downloads and installs the modules specified in the configuration into the '.terraform/modules' directory.

90
MCQmedium

You have an aws_instance resource in your Terraform configuration that was created six months ago. The operations team now requires that any future replacement of this instance preserves the existing Elastic Network Interface (ENI) to maintain its private IP address. You add a lifecycle block with create_before_destroy = true to the aws_instance resource. What is the effect of this change when the instance must be replaced?

A.Terraform creates a new instance but reuses the existing ENI, so the private IP address remains the same.
B.Terraform creates a new instance and a new ENI, but it also updates the old ENI to have the same private IP address as the new one.
C.Terraform creates a new instance with a new ENI, then destroys the old instance and its ENI, so the private IP address changes.
D.Terraform destroys the old instance first, then creates a new one, causing a brief outage but preserving the ENI.
AnswerC

With create_before_destroy, Terraform provisions the replacement aws_instance first, but because the ENI is managed by the instance, a new ENI is created for the new instance. The old instance and its ENI are destroyed afterward, so the private IP is not preserved. The ENI's private IP is tied to the ENI itself, and a new ENI gets a new IP. To preserve the IP, the ENI must be a separate resource with its own lifecycle.

Why this answer

The lifecycle meta-argument create_before_destroy changes the order of operations during replacement: Terraform first creates the new resource, then destroys the old one. However, for an aws_instance, the ENI is an integral part that is recreated with the instance. Therefore, the new instance gets a new ENI and a new private IP.

To keep the same private IP, the ENI must be defined as a separate aws_network_interface resource and attached to the instance, allowing it to persist across instance replacements.

Exam trap

The trap here is assuming that create_before_destroy preserves dependent resources like ENIs, when it only changes the order of creation and destruction of the resource itself.

91
Multi-Selecteasy

Which TWO of the following functions are most useful for manipulating lists?

Select 2 answers
A.keys()
B.concat()
C.flatten()
D.lookup()
E.merge()
AnswersB, C

The `concat()` function joins two or more lists into a single combined list, directly satisfying the requirement to manipulate lists. Unlike `join()`, which merges list elements into a string, `concat()` preserves list structure and element order, making it the appropriate choice for combining list values without altering their underlying data type.

Why this answer

In this scenario, concat() (B) is correct because it joins two lists end-to-end into a single list, which is a core list-manipulation operation for combining sequences. flatten() (C) is also correct because it collapses nested lists into a single-level list, directly transforming list structure. The other options do not belong: keys() (A) is used to retrieve the key names of a map/object, not to manipulate lists; lookup() (D) retrieves a value associated with a key in a map or table, not a list operation; and merge() (E) typically combines maps/objects by key, not lists.

Exam trap

The trap is confusing map functions (keys, lookup, merge) with list functions — candidates see 'keys()' and assume it returns list elements, but it operates on maps.

92
Multi-Selecthard

When troubleshooting a failed plan in HCP Terraform, which THREE sources should you check?

Select 3 answers
A.Policy check results
B.Terraform init output
C.The provider source code
D.Run logs
E.Organization billing page
AnswersA, B, D

Policy check results expose Sentinel or OPA enforcement failures that block a run before apply, satisfying the need to identify policy-driven plan failures. HCP Terraform surfaces these under the run's policy evaluations, distinct from configuration or provider errors, so checking them pinpoints whether governance rules, not code, caused the failure.

Why this answer

In HCP Terraform, a failed plan is diagnosed primarily through the run's own telemetry: Policy check results (A) are correct because Sentinel or OPA policy evaluations run as part of the plan phase and can hard-fail or soft-fail a run, so their pass/fail output and violation messages must be reviewed. Terraform init output (B) is correct because provider and module initialization happens before the plan, and errors such as failed provider installation, registry/module download failures, or version constraint conflicts surface there and will abort the plan. Run logs (D) is correct because they contain the full terraform plan execution output, including the exact error messages, resource-level diagnostics, and exit codes needed to identify the failure cause.

The provider source code (C) is not a troubleshooting source for a failed run—providers are consumed as compiled plugins, and you would inspect provider documentation or version changelogs instead. The organization billing page (E) is unrelated to plan execution failures, since billing issues affect account access or run availability, not the plan's diagnostic output.

Exam trap

The trap is selecting 'provider source code' as a troubleshooting source because it sounds technical, when the exam expects you to know the three practical sources: run logs, init output, and policy check results.

93
MCQmedium

You are authoring a Terraform configuration that provisions an aws_autoscaling_group. The desired instance count is stored in a variable named instance_count, and you need to create exactly that many aws_instance resources. Which approach correctly creates the required number of instances while keeping the configuration valid?

A.Use the for_each meta-argument with for_each = var.instance_count on the aws_instance resource.
B.Use the depends_on meta-argument with depends_on = [var.instance_count] on the aws_instance resource.
C.Use the count meta-argument with count = var.instance_count on the aws_instance resource.
D.Use a dynamic block inside the aws_instance resource with for_each = range(var.instance_count).
AnswerC

The count meta-argument accepts a whole number and creates that many instances of the resource. Setting count = var.instance_count directly satisfies the requirement of creating exactly the desired number of aws_instance resources, and each instance is addressable by index. This is the idiomatic Terraform way to provision a fixed quantity of identical resources.

Why this answer

The count meta-argument is designed to create a specified number of identical resource instances. Because the desired quantity is a numeric variable, count = var.instance_count directly produces exactly that many aws_instance resources. The other options either misuse meta-arguments that expect different input types or confuse block-level repetition with resource-level repetition.

Exam trap

The trap here is assuming that any repetition meta-argument can accept a number, when for_each specifically requires a map or set of strings.

94
MCQhard

If an organization wants to allow teams to manage their own workspaces but prevent them from viewing other teams' workspaces, how should they configure HCP Terraform?

A.Assign teams access at the Project level rather than the Organization level.
B.Enable 'Organization-wide' access for all teams.
C.Use individual workspace permissions instead of projects.
D.Create a separate organization for each team.
AnswerA

Project-level permissions in HCP Terraform scope a team's access to only the workspaces within that project, so each team manages its own workspaces without seeing others. Organisation-level access would grant visibility across all projects, violating the isolation requirement. This satisfies the constraint of per-team workspace management with enforced separation.

Why this answer

HCP Terraform projects group workspaces and let you assign team permissions at the project level, so a team can manage its own workspaces without seeing workspaces in other projects. This scopes access narrowly and satisfies the least-privilege requirement. Organization-level access would grant visibility across all projects, which is exactly what must be prevented.

Exam trap

The trap is reaching for the most extreme isolation (separate organizations) or the most granular (per-workspace) when HCP Terraform's project-level permissions are the designed answer for team-scoped workspace management.

How to eliminate wrong answers

Option B is wrong because organization-wide access grants teams visibility and permissions across all workspaces in the organization, directly violating the isolation requirement. Option C is wrong because per-workspace permissions are more granular but do not scale and do not provide the project-level grouping that HCP Terraform recommends for team isolation; projects are the intended abstraction. Option D is wrong because creating a separate organization per team is operationally heavy, breaks centralized governance and billing, and is not the recommended pattern when projects already provide the needed isolation.

95
Multi-Selecthard

Which THREE of these are benefits of using modules in Terraform?

Select 3 answers
A.Increasing the execution speed of API calls.
B.Automatically preventing all resource drift.
C.Enforcing standardized configurations across teams.
D.Reducing code duplication across environments.
E.Encapsulating complexity into simple interfaces.
AnswersC, D, E

Modules encapsulate resource definitions behind typed input variables, so every team instantiates the same reviewed code rather than hand-writing resources. This directly satisfies the stem's standardisation constraint: configuration drift between teams is eliminated because changes propagate from one versioned source, and inputs are validated at plan time.

Why this answer

Option C is correct because modules let platform teams publish a single, versioned implementation of a resource pattern (for example, a standard VPC or S3 bucket baseline) that every team consumes, so required tags, naming conventions, and security settings are applied consistently instead of being re-implemented per team. Option D is correct because a module is written once and then instantiated with different inputs for dev, staging, and production, eliminating the copy-paste of near-identical .tf resource blocks across environments. Option E is correct because a module exposes a small, typed interface of input variables and outputs while hiding the internal resource graph, so callers pass a few values and receive outputs without needing to understand every underlying resource and dependency.

Option A is not a module benefit: Terraform still makes the same provider API calls, and module expansion happens at plan time, so execution speed is not inherently improved. Option B is not a module benefit: drift detection and remediation depend on state refresh and plan/apply behavior, and modules do not automatically prevent out-of-band changes to resources.

Exam trap

The trap here is confusing modules with runtime or governance features — candidates pick 'prevents drift' or 'speeds up API calls' because modules feel like a magic fix, when they are purely a code-organization and reuse mechanism.

96
MCQhard

What happens if you have a provider version conflict in your module dependencies?

A.Terraform will pick the newest version.
B.Terraform will fail to initialize.
C.Terraform will ignore the constraints.
D.Terraform will pick the oldest version.
AnswerB

Terraform resolves a single provider version across all modules during init. If constraints are mutually exclusive, no version satisfies every module, so initialisation aborts before any plan or apply runs, satisfying the conflict scenario described in the stem.

Why this answer

When two modules or the root module declare incompatible version constraints for the same provider, Terraform cannot satisfy both and aborts during 'terraform init' with a provider version conflict error. Terraform does not silently pick a version when constraints are mutually exclusive; it requires the user to reconcile the constraints. This fail-fast behavior prevents unpredictable provider behavior across modules.

Exam trap

The trap is assuming Terraform resolves conflicts by picking a version (newest or oldest) — candidates forget that Terraform fails fast on unsatisfiable constraints rather than guessing.

How to eliminate wrong answers

Option A is wrong because Terraform does not default to the newest version when constraints conflict — it only selects the newest version that satisfies all constraints, and if none exists, it errors. Option C is wrong because Terraform never ignores version constraints; they are enforced during initialization and dependency resolution. Option D is wrong because Terraform does not fall back to the oldest version — there is no such fallback logic in the provider installer.

97
MCQhard

A Terraform module is used by multiple teams. The module requires the AWS provider but should not enforce a specific provider configuration. The module's author wants to ensure that when the module is used, the caller must pass an AWS provider instance with a specific alias. What should the author include in the module's terraform block?

A.required_providers { aws = { source = "hashicorp/aws" } } and a provider "aws" block with alias = "west".
B.required_providers { aws = { source = "hashicorp/aws", configuration_aliases = [aws.west] } }.
C.A terraform block with required_version = ">= 1.0" and a provider "aws" block with region = "us-west-2".
D.A variable named aws_alias with a default value of "west" and a provider "aws" block using alias = var.aws_alias.
AnswerB

The configuration_aliases argument inside required_providers declares that the module expects an additional provider configuration with the alias aws.west. This informs Terraform that the module's resources may use aws.west, and the caller must pass a matching provider instance using the providers meta-argument.

Why this answer

To require a specific provider alias when a module is used, the module author declares configuration_aliases in the required_providers block. This tells Terraform that the module expects a provider instance with that alias. The caller must then pass it using the providers meta-argument in the module block, such as providers = { aws.west = aws.west }.

Exam trap

The trap here is thinking that a module can define its own aliased provider block, when actually aliased providers must be configured in the root module and passed in.

98
MCQeasy

Which of the following can be used to monitor costs in an HCP Terraform workspace?

A.Terraform State inspection.
B.Sentinel Policy sets.
C.Cost Estimation feature.
D.VCS commit logs.
AnswerC

Cost Estimation parses the plan against cloud provider pricing to project monthly spend before apply, satisfying the requirement to monitor costs within an HCP Terraform workspace. It surfaces projected deltas per resource, unlike run notifications or state inspection, which report activity rather than monetary impact.

Why this answer

HCP Terraform's Cost Estimation feature analyzes the planned resources in a run and estimates the monthly cost using cloud pricing data, displaying it in the run's UI. It is the built-in mechanism for monitoring the financial impact of infrastructure changes before they are applied.

Exam trap

The trap is confusing governance features (Sentinel) or state inspection with cost visibility — only the Cost Estimation feature produces per-run spend projections.

How to eliminate wrong answers

Option A is wrong because state inspection shows resource attributes, not cost projections. Option B is wrong because Sentinel policy sets enforce governance rules (e.g., allowed instance types) but do not produce cost estimates. Option D is wrong because VCS commit logs track code changes, not infrastructure spend.

99
Multi-Selecthard

Which THREE of the following represent potential pitfalls when using 'count'?

Select 3 answers
A.Inability to use string keys for identification
B.Complex logic for conditional creation
C.Index shifts when removing list items
D.Performance issues with large collections
E.Type mismatch errors
AnswersA, B, C

count indexes instances numerically, so resources are identified by position rather than meaningful string keys. This satisfies the stem's pitfall about identification: you cannot reference an instance by a stable name, making lookups and references brittle compared with for_each.

Why this answer

Option A is correct because count-based resources are identified by numeric index in the state file, so you cannot use meaningful string keys to reference or target individual instances, making identification and targeting cumbersome. Option B is correct because conditionally creating or excluding specific instances with count requires awkward inline conditional expressions (for example, count = var.enabled ? 1 : 0) rather than clean per-item logic, which complicates configuration. Option C is correct because count indexes are positional, so removing an item from the middle of a list shifts the indexes of all subsequent items, causing Terraform to plan destruction and recreation of resources that should have remained unchanged.

Option D is not correct because count itself does not inherently cause performance problems with large collections; performance depends on provider API calls and plan graph size, not the count meta-argument specifically. Option E is not correct because count is an integer meta-argument and does not introduce type mismatch errors; type mismatches arise from incorrect variable or attribute types, not from using count.

Exam trap

The trap is including plausible-sounding but non-specific issues like 'performance' or 'type mismatch' — the exam tests whether you know the three canonical `count` pitfalls (no string keys, awkward conditionals, index shifts).

100
Multi-Selectmedium

Which TWO of the following are true regarding Private Module Registry versioning?

Select 2 answers
A.Versions can be deleted at any time without restriction.
B.Versions must follow Semantic Versioning (SemVer).
C.You can only have one version per module.
D.Versions are created manually by uploading files.
E.The Registry automatically detects new tags as module versions.
AnswersB, E

Terraform Cloud's private module registry enforces Semantic Versioning, requiring the MAJOR.MINOR.PATCH format for every published module version. This satisfies the stem's versioning constraint directly: the registry rejects tags that deviate from SemVer, so teams must increment versions accordingly when releasing module updates.

Why this answer

Option B is correct because the Private Module Registry enforces Semantic Versioning (SemVer) in the MAJOR.MINOR.PATCH format, so every published module version must be a valid SemVer string. Option E is correct because when a module is connected to a VCS repository, the Registry automatically detects new Git tags that match SemVer and publishes them as module versions without manual upload. Option A is wrong because published versions cannot be freely deleted; deletion is restricted (for example, a version cannot be deleted while it is the only version or is in use).

Option C is wrong because a module can have many versions, each identified by its SemVer tag. Option D is wrong because versions are normally created by tagging the linked VCS repository, not by manually uploading files.

101
MCQeasy

You are writing a module that creates an AWS Security Group. The module accepts a variable `ingress_rules` defined as a list of objects with `from_port`, `to_port`, and `protocol`. You want to ensure that the module's interface is flexible enough to allow callers to add or remove rules without modifying the module code. Which Terraform feature should you use to iterate over the list and create dynamic ingress blocks?

A.A `count` meta-argument on the `aws_security_group` resource with `count = length(var.ingress_rules)`.
B.A `for` expression in the `ingress` argument of the security group resource, returning a list of rule objects.
C.A `for_each` meta-argument on the `aws_security_group` resource, iterating over the list.
D.A `dynamic` block named `ingress` that iterates over `var.ingress_rules` using `for_each`.
AnswerD

A `dynamic` block allows generating nested blocks dynamically based on a collection. By using `dynamic "ingress"` with `for_each = var.ingress_rules`, the module can create one ingress block per rule. This keeps the module flexible and avoids hardcoding rules, enabling callers to pass any number of rules without changing module code.

Why this answer

Dynamic blocks are designed to generate nested blocks from a collection. Using `dynamic "ingress"` with `for_each` over the list of rule objects allows the module to create multiple ingress blocks within a single security group resource. This approach is idiomatic and maintains a clean, flexible interface.

Exam trap

The trap here is confusing resource-level iteration (count/for_each) with nested block generation, which requires a dynamic block.

102
MCQmedium

You maintain a Terraform module that provisions an AWS Application Load Balancer and its target groups. Consumers frequently need to attach additional security groups to the ALB, but the module currently hardcodes a single security group. You want to allow consumers to supply a list of security group IDs without breaking existing module calls. Which change should you make to the module's variables and resource configuration?

A.Add a new variable `security_group_ids` of type `list(string)` with no default, and replace the existing hardcoded security group with this variable.
B.Add a new variable `additional_security_group_ids` of type `list(string)` with a default of `[]`, then merge it with the module's internally created security group ID using `concat()` in the `security_groups` argument.
C.Use the `for_each` meta-argument on the `aws_lb` resource to iterate over a map of security group IDs provided by the consumer.
D.Change the existing `security_group_id` variable to type `list(string)` and update the `security_groups` argument to reference it directly.
AnswerB

This approach preserves backward compatibility because existing callers do not need to set the new variable; the default empty list means no additional groups are attached. Using `concat()` to combine the internally managed security group with consumer-supplied IDs correctly composes the final list. It is the idiomatic way to extend module behavior without forcing a breaking change on existing consumers.

Why this answer

Adding an optional input variable with a sensible default and composing it with the module's internal resource preserves backward compatibility. Existing consumers continue to work unchanged, while new consumers can pass extra security group IDs. Concatenating the internally managed security group with the additional ones ensures the ALB retains its baseline security posture and gains the requested extra groups.

Exam trap

The trap here is assuming that modifying an existing variable's type is backward compatible as long as the underlying resource argument accepts a list.

103
MCQmedium

If you use 'ignore_changes = [tags]', and you manually change the tags in the AWS Console, what will happen during the next 'terraform plan'?

A.Terraform will plan to revert the tags to the configuration state.
B.Terraform will fail with an attribute mismatch error.
C.Terraform will update the state file to match the console tags.
D.Terraform will ignore the difference and perform no action on the tags.
AnswerD

ignore_changes = [tags] instructs Terraform to disregard differences in the tags attribute between configuration and real infrastructure. Manually altered tags in the AWS Console are therefore not detected as drift, so the next plan performs no action on the tags.

Why this answer

The `ignore_changes` lifecycle meta-argument tells Terraform to disregard differences between the desired configuration and the actual remote state for the specified attributes. When `ignore_changes = [tags]` is set, Terraform will not plan any changes to the `tags` attribute even if the real-world resource has been modified outside of Terraform. Therefore, during the next `terraform plan`, Terraform will ignore the tag differences and perform no action on the tags.

Exam trap

The trap here is confusing `ignore_changes` with automatic state reconciliation; candidates often think Terraform will update the state or revert the change, but it simply ignores the difference.

How to eliminate wrong answers

Option A is wrong because `ignore_changes` prevents Terraform from reverting the tags; without it, Terraform would indeed plan to revert, but the lifecycle rule overrides that behavior. Option B is wrong because Terraform does not fail with an attribute mismatch error; it simply ignores the difference for the specified attribute. Option C is wrong because Terraform does not automatically update the state file to match the console tags; the state file remains as it was, and the difference is ignored, not reconciled.

104
MCQhard

When using 'terraform state mv', what is the impact on the collaboration workflow?

A.It changes the state file, which affects subsequent runs
B.It is only possible in local state
C.It requires all team members to re-run init
D.It automatically updates the git repository
AnswerA

terraform state mv rewrites resource addresses inside the shared state file, so every collaborator's subsequent plan and apply reads the altered mapping. Teammates must pull the updated state before running, otherwise their plans reference stale addresses and may propose destructive changes.

Why this answer

terraform state mv rewrites the state file, renaming or moving a resource from one address to another. Because state is the shared source of truth in a team workflow, this change affects every subsequent plan and apply run by any team member — they will see the resource under its new address. This is why state mv must be coordinated carefully in collaborative environments.

Exam trap

The trap is treating terraform state mv as a local-only operation — candidates forget that in a team with remote state, the change is immediately visible to everyone and can cause confusing plans if config is not updated in lockstep.

How to eliminate wrong answers

Option B is wrong because terraform state mv works with both local and remote backends — it operates on whatever state the backend is configured to use, including S3, HCP Terraform, and Consul. Option C is wrong because terraform init does not need to be re-run after a state mv; init handles provider and module installation, not state address changes. Option D is wrong because terraform state mv only modifies the state backend — it does not touch git, and it does not commit anything.

Version control of configuration is a separate concern from state manipulation.

105
MCQmedium

You maintain a Terraform configuration in a GitHub repository that provisions AWS infrastructure. Your organization uses HCP Terraform with VCS-driven workspaces. A teammate pushes a commit that modifies `main.tf` in the `production` branch, but you need the change to be reviewed and approved before any infrastructure is modified. What should you configure to enforce this workflow?

A.Set the workspace's 'Apply method' to 'Manual apply' and enable 'Run triggers' from a separate approval workspace.
B.Enable the 'Remote operations' setting on the workspace and require a successful `terraform plan` before apply.
C.Configure the workspace to use 'Auto-apply' and rely on branch protection rules in GitHub to prevent unauthorized merges.
D.In the workspace settings, set the 'Apply method' to 'Manual apply' and assign a team with 'Write' permissions to review and approve plans.
AnswerD

Setting the apply method to manual ensures that a successful plan does not automatically apply; a user must explicitly approve it. Assigning a team with write permissions allows those users to review the plan output and approve or discard the run. This combination enforces the required review and approval before any infrastructure changes, aligning with collaborative workflows in HCP Terraform.

Why this answer

Manual apply introduces a gate where a run waits for human approval after a successful plan. Combined with team permissions that allow only designated members to approve, this ensures changes are reviewed before apply. Auto-apply or remote operations alone do not enforce review.

Run triggers and branch protection are unrelated to the approval step inside HCP Terraform.

Exam trap

The trap here is assuming that branch protection rules or remote operations provide an approval gate, when only the workspace's apply method and team permissions control who can approve runs.

106
MCQhard

You are writing a Terraform configuration that uses a for expression to transform a map of objects into a new map. The original map has keys that are strings, and each object contains an attribute 'enabled' of type bool. You need to create a new map that includes only the entries where 'enabled' is true, and the new map's keys should be the original keys prefixed with 'prod-'. Which for expression achieves this?

A.[ for k, v in var.input_map : "prod-${k}" => v if v.enabled ]
B.{ for k, v in var.input_map : "prod-${k}" => v.enabled }
C.{ for k, v in var.input_map : "prod-${k}" => v if v.enabled }
D.{ for k, v in var.input_map : k => v if v.enabled }
AnswerC

This for expression correctly iterates over the map, applies a condition to filter only enabled entries, and constructs a new map with keys prefixed by 'prod-'. The syntax is valid: it uses the map form with key and value, includes an if clause for filtering, and the key expression generates the new key.

Why this answer

The correct for expression uses curly braces to produce a map, iterates over the input map, applies an if clause to filter only enabled entries, and transforms the key by prefixing 'prod-'. This meets all requirements: filtering, key transformation, and value preservation. The other options either use incorrect delimiters, omit the key transformation, or alter the value incorrectly.

Exam trap

The trap here is confusing the syntax for map and list for expressions, particularly the use of curly braces versus square brackets and the placement of the if clause.

107
MCQmedium

A platform team publishes a shared networking module to a private Terraform registry. Several consuming teams pin the module using `version = "~> 2.1.0"`. The platform team later adds a new optional input variable to the module and publishes it as version 2.2.0 without changing any existing behavior. What is the effect on the consuming teams' next `terraform init`?

A.terraform init fails because the version constraint does not allow patch-level upgrades.
B.terraform init continues using the newest 2.1.x version satisfying the constraint and does not select 2.2.0.
C.terraform init prompts for confirmation before upgrading across minor versions, then proceeds if approved.
D.terraform init upgrades the module to 2.2.0 because adding an optional variable is a non-breaking change.
AnswerB

The pessimistic constraint `~> 2.1.0` allows only versions greater than or equal to 2.1.0 and less than 2.2.0. Terraform's module installer selects the highest available version within that allowed range, so 2.2.0 is never chosen. Consuming teams remain on the newest 2.1.x release until they update their version constraint.

Why this answer

The pessimistic constraint operator restricts acceptable versions to a defined range. For `~> 2.1.0`, the upper bound is exclusive at 2.2.0, so the newly published 2.2.0 is invisible to consumers. Terraform installs the highest version that still satisfies the constraint, leaving teams on the latest 2.1.x release until they deliberately broaden the constraint.

Exam trap

The trap here is assuming Terraform evaluates semantic versioning compatibility when choosing a module version, when it actually performs a literal constraint match.

108
MCQeasy

Which type of Sentinel policy is used to block a run without possibility of override?

A.Advisory.
B.Policy-Override.
C.Soft-mandatory.
D.Hard-mandatory.
AnswerD

Hard-mandatory policies in HashiCorp Sentinel halt a run immediately and cannot be overridden by any user, satisfying the stem's "without possibility of override" constraint. Soft-mandatory permits privileged override, while advisory only logs warnings. Hard-mandatory is therefore the only policy type enforcing an absolute, non-bypassable block.

Why this answer

Sentinel policies in Terraform Cloud/Enterprise have three enforcement levels: advisory, soft-mandatory, and hard-mandatory. A hard-mandatory policy blocks the run outright and cannot be overridden by any user, including organization owners, making it the correct answer for 'block without possibility of override'.

Exam trap

The trap is confusing 'soft-mandatory' with 'hard-mandatory' — candidates remember that soft-mandatory blocks runs but forget it can be overridden, so they pick it for a question that explicitly says 'without possibility of override'.

How to eliminate wrong answers

Option A is wrong because advisory policies only log a warning and never block a run. Option B is wrong because 'Policy-Override' is not a Sentinel enforcement level — it is a permission that allows certain users to override soft-mandatory policies. Option C is wrong because soft-mandatory policies can be overridden by users with the 'Manage Policy Overrides' permission, so they do not meet the 'without possibility of override' requirement.

109
MCQmedium

Which of these is a valid use case for a dynamic block?

A.Defining nested repeatable blocks
B.Conditional module inclusion
C.Changing the provider configuration dynamically
D.Defining multiple separate resources
AnswerA

Dynamic blocks generate repeated nested configuration blocks from a collection, such as multiple ingress rules inside an aws_security_group. This directly satisfies the requirement for nested repeatable blocks, which count and for_each cannot produce inside a resource argument.

Why this answer

A dynamic block in Terraform generates nested repeatable blocks within a resource, data source, provider, or module — for example, multiple `ingress` blocks in an `aws_security_group` or multiple `tag` blocks. It iterates over a collection and produces one nested block per element, using an iterator to reference each item. This is its sole purpose.

Exam trap

The trap is confusing dynamic blocks with `count`/`for_each` on resources or modules — dynamic blocks only generate nested blocks, never top-level resources or conditional modules.

How to eliminate wrong answers

Option B is wrong because conditional module inclusion is handled with `count` or `for_each` on the `module` block, not dynamic blocks. Option C is wrong because provider configuration is set via `provider` blocks and `alias`, and cannot be dynamically generated per-iteration by a dynamic block. Option D is wrong because defining multiple separate resources is done with `count` or `for_each` on the resource itself, not with a dynamic block, which only produces nested blocks inside a single resource.

110
MCQmedium

You are writing a Terraform configuration that uses a `dynamic` block to generate multiple `ingress` blocks inside an `aws_security_group` resource. The `var.ingress_rules` variable is a list of objects with `from_port`, `to_port`, and `cidr_blocks`. You need to reference the current rule inside the dynamic block's content. Which iterator configuration and reference is correct?

A.dynamic "ingress" { for_each = var.ingress_rules iterator = rule content { from_port = rule.value.from_port } }
B.dynamic "ingress" { for_each = var.ingress_rules iterator = ingress content { from_port = ingress.key.from_port } }
C.dynamic "ingress" { for_each = var.ingress_rules content { from_port = ingress.value.from_port } }
D.dynamic "ingress" { for_each = var.ingress_rules content { from_port = each.value.from_port } }
AnswerA

This explicitly sets the iterator name to rule and references rule.value inside the content block. This is the correct and unambiguous way to access the current element when the default iterator name might conflict or when you want clarity. It correctly iterates over the list of objects and uses the iterator's value attribute.

Why this answer

In a dynamic block, the iterator argument lets you name the temporary variable that represents the current element. The default is the block label, but explicitly setting iterator avoids ambiguity. Inside the content block, you access the current element via <iterator>.value.

Using each.value is incorrect because each is only for resource-level for_each. Referencing key instead of value also fails to access the object's attributes.

Exam trap

The trap here is confusing the dynamic block iterator with the resource-level each object, or mistakenly using key to access the element's attributes.

111
MCQhard

If you want to use a provider that is not published in the Terraform Registry, how do you install it?

A.Use a filesystem mirror in the .terraformrc file.
B.You cannot use private providers.
C.Rename the file to provider.tf.
D.Copy it to the root of the project.
AnswerA

A filesystem mirror lets Terraform install a provider from a local directory instead of the public Terraform Registry, satisfying the constraint that the provider is unpublished. The .terraformrc provider_installation block redirects installation to that mirror, so no registry lookup occurs.

Why this answer

Providers not published in the Terraform Registry are installed by configuring a filesystem mirror in the CLI configuration file (.terraformrc or terraform.rc), which tells Terraform where to find the provider plugin binaries locally. The provider_installation block with a filesystem_mirror directive points Terraform at a directory containing the provider packages, bypassing the default registry lookup. This is the standard approach for air-gapped environments or internal/private providers.

Exam trap

The trap is thinking private providers are unsupported or that dropping a binary in the project directory works — Terraform requires an explicit mirror or registry configuration via the CLI config file.

How to eliminate wrong answers

Option B is wrong because Terraform fully supports private and custom providers — they simply need to be distributed via a mirror, network mirror, or private registry rather than the public Registry. Option C is wrong because renaming a file to provider.tf has no effect on provider installation; provider installation is controlled by required_providers and CLI configuration, not filenames. Option D is wrong because copying a provider binary to the project root does not register it with Terraform's plugin discovery mechanism — Terraform looks in specific cache/mirror directories defined in the CLI config.

112
MCQmedium

You need to manage resources in two different AWS regions using the same provider configuration. How do you achieve this?

A.Define the region twice in a single provider block.
B.Define two separate aws providers in the same file without aliases.
C.Create two separate Terraform projects.
D.Use an alias in the provider block and reference it in the resource using the provider meta-argument.
AnswerD

Provider aliases create distinct configurations within one provider block, each pinned to a different region. Referencing the alias via the provider meta-argument on a resource directs that resource to the aliased instance, satisfying the requirement to manage two regions from a single configuration.

Why this answer

In Terraform, a single provider configuration can only target one region. To manage resources across multiple regions with the same provider type (e.g., AWS), you must define multiple provider blocks, each with a unique alias. The default provider block (without alias) handles the primary region, while additional blocks with aliases (e.g., `alias = "west"`) specify other regions.

Resources then use the `provider` meta-argument to select the appropriate aliased provider, e.g., `provider = aws.west`. This allows a single Terraform configuration to manage resources in multiple regions.

Exam trap

The trap here is assuming that a single provider block can handle multiple regions by specifying the region multiple times, or that separate projects are needed; candidates often overlook the alias and provider meta-argument mechanism.

How to eliminate wrong answers

Option A is wrong because a provider block cannot contain duplicate `region` arguments; Terraform would throw a duplicate argument error. Option B is wrong because defining two provider blocks of the same type without aliases causes a conflict—Terraform requires aliases to distinguish multiple configurations of the same provider. Option C is wrong because separate Terraform projects would not allow managing resources in multiple regions within the same configuration and state; it also increases complexity and prevents cross-region references.

Option D is correct because using aliases and the `provider` meta-argument is the standard, supported way to use multiple provider configurations in a single module.

113
Multi-Selecthard

Which TWO of the following statements are correct regarding 'for_each' and state?

Select 2 answers
A.for_each creates stable identifiers based on keys
B.count is preferred for all resource types
C.count creates stable identifiers based on keys
D.for_each is preferred over count for map-based configurations
E.for_each is only available for cloud resources
AnswersA, D

for_each keys each instance by its map or set key rather than a positional index, so Terraform tracks instances by stable identifiers in state. Adding or removing entries therefore leaves unrelated instances untouched, satisfying the stem's requirement regarding state behaviour.

Why this answer

Option A is correct because for_each keys each instance by a map key or set member, so the resulting resource addresses (for example aws_instance.web["web1"]) remain stable across reordering or insertion of other elements, which keeps state entries tied to the same object. Option D is correct because for_each is the recommended construct for map-based (and set-based) configurations, since it iterates over key/value pairs and avoids the index-shifting problems that count causes when list elements are added or removed. Option B is wrong because count is not preferred for all resource types; it is only suitable when instances are truly identical and index-based addressing is acceptable.

Option C is wrong because count uses numeric indexes (resource[0], resource[1]), which are not key-based and therefore not stable when the list changes. Option E is wrong because for_each is a core Terraform meta-argument available to resources, data sources, and modules, not limited to cloud resources.

Exam trap

The trap is assuming count and for_each are interchangeable — candidates miss that count's positional indices cause cascading destroy/recreate operations, while for_each's key-based addressing is what makes it stable.

114
MCQmedium

Your team uses a GitHub repository as the VCS connection for an HCP Terraform workspace in the AWS provider organization. A developer pushes a commit that modifies a variable value in `terraform.tfvars` and also touches a file inside a subdirectory that is excluded by the workspace's trigger patterns. Only the subdirectory file is in the trigger pattern exclusion list. What will HCP Terraform do?

A.It will trigger a run because the commit includes changes outside the excluded paths.
B.It will trigger a run only if the excluded file is deleted in the same commit.
C.It will trigger a speculative plan but not an apply run.
D.It will not trigger a run because the commit includes a change to an excluded path.
AnswerA

HCP Terraform evaluates each changed file against the trigger patterns. If at least one changed file is not excluded, a run is queued. The change to `terraform.tfvars` is outside the excluded subdirectory, so the run is triggered even though another file in the commit is excluded.

Why this answer

When a VCS commit contains changes to both excluded and non-excluded paths, HCP Terraform checks whether any changed file falls outside the exclusion patterns. Since `terraform.tfvars` is not excluded, the commit triggers a run. Excluded paths only suppress runs when every changed file in the commit matches an exclusion pattern.

Exam trap

The trap here is assuming that any excluded file in a commit disables the entire run, when exclusion is evaluated per file and a single qualifying change is enough to queue a run.

115
Multi-Selectmedium

A platform team is standardizing Terraform provider usage across many AWS accounts. They want to enforce a specific AWS provider version and ensure every root module records the provider source explicitly so that ambiguous provider lookups do not occur. Which two actions should the team take? (Choose two.)

Select 2 answers
A.Rely on the implicit hashicorp/aws lookup by referencing aws in resources without declaring required_providers, since Terraform resolves it automatically.
B.Declare the AWS provider in the terraform block's required_providers with an explicit source = "hashicorp/aws" and a version constraint.
C.Commit the generated .terraform.lock.hcl to version control so all root modules use consistent provider selections.
D.Run terraform providers lock after init to record platform hashes, and rely on that lock file alone to enforce the version.
E.Add a version argument inside the provider "aws" block to lock the provider version.
AnswersB, C

Specifying source and a version constraint in required_providers pins the provider to the intended registry namespace and version range. This removes ambiguity in provider lookup and enforces the standardized version across root modules, directly satisfying both the source-explicitness and version-enforcement goals the platform team defined.

Why this answer

Enforcing a provider version and making source explicit requires declaring source and a version constraint in required_providers, then committing the resulting lock file so selections are reproducible. The provider block cannot carry a version argument, implicit lookup leaves source ambiguous, and the lock file alone does not constrain future resolution without a declared constraint.

Exam trap

The trap here is treating the lock file or an implicit provider lookup as sufficient version enforcement, when the constraint must be declared in required_providers and the lock file committed alongside it.

116
MCQhard

How can you view the detailed breakdown of cost estimates for a specific Terraform plan?

A.Run the 'terraform show' command on the state file.
B.Check the cloud provider's billing dashboard.
C.Use the Sentinel CLI tool.
D.Open the run page in the HCP Terraform UI.
AnswerD

HCP Terraform's run page presents the cost estimate broken down per resource, with monthly and hourly deltas, alongside the plan itself. Opening that page satisfies the requirement to inspect detailed estimate line items rather than a single aggregate figure, which the CLI alone cannot display.

Why this answer

The run details page in the HCP Terraform UI displays the cost estimation summary, which can be expanded for details.

117
Multi-Selecthard

Which THREE items should be included in a well-documented Terraform module?

Select 3 answers
A.A list of all possible provider configurations.
B.Clear documentation for each output.
C.A description for each input variable.
D.The raw state file of the module's resources.
E.An example of how to call the module.
AnswersB, C, E

Documenting each output states what the value represents and how consumers should use it, which is essential when the module is called elsewhere. Without it, callers must read the source to interpret returned values, defeating the stem's requirement for a well-documented module.

Why this answer

Option B is correct because documenting each output (its name, type, and meaning) lets consumers know what values the module returns and how to reference them, which is essential for reusable module interfaces. Option C is correct because every input variable should have a description so users understand its purpose, expected type, default, and whether it is required, making the module self-explanatory. Option E is correct because providing a usage example showing how to call the module with realistic inputs demonstrates correct invocation and accelerates adoption.

Option A is not appropriate because listing all possible provider configurations is impractical and unnecessary; provider requirements should instead be declared via required_providers and documented as constraints. Option D is wrong because raw state files contain sensitive data and environment-specific resource mappings, should be stored remotely with locking, and are never part of module documentation.

Exam trap

The trap is confusing module documentation with operational artifacts like state files or provider configs; candidates may select state file inclusion, not realizing it is a security anti-pattern.

118
MCQhard

You are using a for expression to create a map from a list of objects. Each object has an attribute 'name' that is a string. You want the resulting map's keys to be the 'name' values and the values to be the entire objects. However, you encounter an error because some objects have duplicate 'name' values. How can you modify the for expression to handle duplicates by grouping objects with the same name into a list, so that the map values become lists of objects?

A.{ for obj in var.objects : obj.name => obj }
B.[ for obj in var.objects : obj.name => obj ]
C.{ for obj in var.objects : obj.name => obj... }
D.{ for obj in var.objects : obj.name => [obj] }
AnswerC

This for expression uses the grouping ellipsis (...) after the value expression. The ellipsis groups all values that share the same key into a list. So the resulting map will have keys from obj.name and values as lists of objects. This is the correct way to handle duplicate keys by grouping.

Why this answer

The correct for expression includes the grouping ellipsis (...) after the value expression. This tells Terraform to collect all values that share the same key into a list, thus handling duplicates by grouping. Without the ellipsis, duplicate keys cause an error.

The other options either omit the ellipsis, use the wrong delimiter, or incorrectly attempt to wrap values without grouping.

Exam trap

The trap here is not knowing about the grouping ellipsis and attempting to manually handle duplicates with nested loops or conditional logic.

119
Multi-Selecthard

You are writing a reusable module that creates an AWS S3 bucket and an associated bucket policy. The module will be consumed by multiple teams. Which TWO practices should you follow to make the module robust and maintainable? (Choose two.)

Select 2 answers
A.Define all input variables with explicit types and provide sensible defaults for optional ones.
B.Use the `terraform-aws-modules/s3-bucket/aws` public module internally and wrap it without exposing any of its variables.
C.Expose outputs for the bucket ID and ARN so consumers can reference them in their own configurations.
D.Store the bucket policy as a separate JSON file and load it with `file()` so it can be edited without changing Terraform code.
E.Hardcode the AWS region in the provider configuration inside the module to ensure consistency.
AnswersA, C

Explicit types enable Terraform to validate inputs and provide better error messages, while defaults make optional variables easier to use. This improves the module's usability and reduces the chance of misconfiguration. It also documents the expected input shape, which is essential for a module shared across teams with varying requirements.

Why this answer

Exposing outputs and defining typed variables with defaults are core practices for reusable modules. Outputs allow consumers to integrate the module's resources into their own configurations, while typed variables with defaults make the module predictable and easy to use. Together they form a clear contract between the module and its consumers, which is essential for maintainability across teams.

Exam trap

The trap here is thinking that wrapping a public module or using external files for policies automatically improves maintainability, when in fact it can reduce flexibility and transparency.

120
Multi-Selecthard

Which are characteristics of the Terraform Plugin SDK? (Select TWO)

Select 2 answers
A.It replaces the Terraform CLI.
B.It manages the Terraform state lock.
C.It compiles HCL to Go code.
D.It provides a way to define schema for resources.
E.It handles resource lifecycle methods (Create, Read, Update, Delete).
AnswersD, E

The Plugin SDK exposes schema definition constructs that providers use to declare resource and data source attributes, including their types, optionality and validation. This schema drives Terraform's configuration parsing and state handling, making schema definition a core SDK capability.

Why this answer

Option D is correct because the Terraform Plugin SDK exposes helper packages such as schema.Resource and schema.Schema that let provider developers declaratively define the schema (attributes, types, required/optional/computed flags) for resources and data sources. Option E is correct because the SDK supplies the CRUD lifecycle scaffolding—Create, Read, Update, Delete (and often Import) functions—that Terraform invokes through the provider's gRPC interface to reconcile real infrastructure with configuration. Option A is wrong because the SDK is a library for building providers; the Terraform CLI is a separate binary that talks to providers over the plugin protocol.

Option B is wrong because state locking is handled by the Terraform core/backend (for example, DynamoDB for S3, or the local backend), not by the Plugin SDK. Option C is wrong because HCL is parsed and evaluated by Terraform core's HCL library, not compiled to Go code by the Plugin SDK.

121
MCQeasy

Which meta-argument is best for deploying resources that are strictly dependent on the number of items in a configuration?

A.count
B.for_each
C.provider
D.dynamic
AnswerA

The count meta-argument creates a fixed number of resource instances derived from a whole number, so scaling is tied strictly to the count of items in a configuration. This satisfies the stem's dependency on item quantity, unlike for_each, which iterates over map or set keys.

Why this answer

The `count` meta-argument is best for deploying resources that are strictly dependent on the number of items in a configuration. It takes an integer and creates that many instances of the resource. This is ideal when you need a specific number of identical resources, such as creating three EC2 instances.

Exam trap

AWS provider exams often test the choice between `count` and `for_each`, tricking candidates into selecting `for_each` for simple numeric counts when `count` is more appropriate.

How to eliminate wrong answers

Option B is wrong because `for_each` is used when you need to create resources based on a map or set of items, not strictly on a count. Option C is wrong because `provider` is a meta-argument used to specify which provider configuration to use, not to manage resource instances. Option D is wrong because `dynamic` is a block type for generating nested blocks, not a meta-argument for creating multiple resource instances.

122
MCQmedium

Your team uses HCP Terraform to manage AWS infrastructure. You have a workspace that provisions an Amazon RDS instance. You want to ensure that the RDS instance is not publicly accessible. You have written a Sentinel policy that checks the 'publicly_accessible' attribute. However, after enabling the policy, you notice that runs are not being blocked even when the attribute is set to true. What is the most likely reason for the policy not blocking the run?

A.The policy is written in Sentinel but the workspace is using Terraform 0.11, which does not support Sentinel.
B.The policy is attached to the organization but not to the specific workspace.
C.The Sentinel policy is using the wrong import, such as tfplan/v2 instead of tfplan/v3.
D.The policy set is configured with an enforcement level of advisory.
AnswerD

Advisory enforcement only logs policy failures and does not block or pause runs. If the policy set is advisory, the run will proceed even if the policy fails. To block runs, the policy set must be hard-mandatory or soft-mandatory (with override).

Why this answer

The enforcement level determines whether a failing policy blocks a run. Advisory only logs, soft-mandatory allows override, and hard-mandatory blocks. Since the policy is not blocking, the enforcement level is likely set to advisory.

Exam trap

The trap here is assuming that any policy failure will block a run, when actually the enforcement level controls the behavior.

123
MCQhard

An operations engineer runs terraform init in a CI pipeline that has no outbound internet access but does have a local filesystem mirror of providers. The configuration uses the AWS provider and a custom provider named example. The engineer runs: terraform init -plugin-dir=/opt/terraform/plugins. What is the result?

A.Terraform ignores the plugin directory because the AWS provider is a hashicorp provider and must be downloaded from the registry.
B.Terraform installs both providers from the plugin directory and writes a lock file entry for each.
C.Terraform installs the AWS provider from the plugin directory but still downloads the example provider because it is not a hashicorp provider.
D.Terraform uses the plugin directory as the only source for provider plugins and skips the usual provider installation steps.
AnswerD

When -plugin-dir is specified, Terraform searches only the given directories for provider plugins and does not attempt to install providers from a registry or from other configured sources. This is intended for offline or air-gapped environments where providers are pre-placed in a local directory.

Why this answer

The -plugin-dir option tells Terraform to use only the specified directory as the source of provider plugins. It does not perform normal provider installation or update the lock file. For air-gapped pipelines, all required provider binaries must be pre-populated in that directory, and the lock file should already contain matching checksums.

Exam trap

The trap here is confusing -plugin-dir with provider installation from a filesystem mirror, which does create lock file entries and follows the normal installation workflow.

124
MCQeasy

A teammate accidentally deleted an `aws_security_group` through the AWS Console. The resource is still present in Terraform state, and no configuration changes have been made. What will `terraform plan` report for that resource, and what is the appropriate next step?

A.Plan shows no changes, because state still contains the resource.
B.Plan fails with an error and requires `terraform import` before proceeding.
C.Plan shows the resource will be created, because refresh detects it is missing.
D.Plan shows the resource will be destroyed and recreated.
AnswerC

During plan, Terraform refreshes each resource by reading its current state from AWS. Because the security group was deleted outside Terraform, the refresh marks the resource as missing and the plan proposes to create it again. Running apply then recreates the security group according to the existing configuration, restoring the desired state.

Why this answer

Terraform's refresh step reconciles state with reality before planning. A resource deleted outside Terraform is detected as missing, and the plan proposes to create it so configuration and reality match again. Applying the plan recreates the security group.

No import is needed because the object no longer exists to be adopted.

Exam trap

The trap here is believing that a resource remaining in state means Terraform will see no changes, when refresh actually detects the external deletion and plans a create.

125
MCQeasy

What happens if a Sentinel policy results in an 'advisory' output?

A.The plan is marked as failed.
B.The run logs display a warning, but the process continues.
C.The policy is treated as a hard-mandatory failure.
D.The run is paused for manual intervention.
AnswerB

An advisory result in Sentinel produces a warning in the run logs while allowing the run to proceed, satisfying the requirement that execution continues despite the policy outcome. Unlike soft-mandatory, which blocks and prompts for override, advisory never halts the operation, so the plan or apply completes normally with the warning recorded.

Why this answer

In HashiCorp Sentinel, policies can be configured with different enforcement levels: advisory, soft-mandatory, and hard-mandatory. When a policy is set to advisory, a failed policy check does not block the run; instead, it logs a warning message and allows the run to proceed. This is by design to provide informational feedback without enforcing compliance.

Thus, the correct answer is that the run logs display a warning but the process continues.

Exam trap

The trap here is confusing the three enforcement levels of Sentinel policies—advisory, soft-mandatory, and hard-mandatory—and their respective outcomes. Candidates often mistakenly think any policy failure blocks the run, but advisory only warns.

How to eliminate wrong answers

Option A is wrong because an advisory policy does not mark the plan as failed; that would occur with a hard-mandatory policy. Option C is wrong because advisory is the opposite of hard-mandatory; hard-mandatory blocks the run, while advisory only warns. Option D is wrong because the run is not paused for manual intervention; that behavior is associated with soft-mandatory policies, which require an authorized user to override the failure.

126
MCQhard

When writing a custom provider, what is the 'Schema' used for?

A.To define the attributes of resources.
B.To define the cloud service billing.
C.To define the provider's icon.
D.To store state.
AnswerA

The Schema block declares each resource's attributes, their types, and whether they are required, optional, or computed. This lets Terraform validate configuration and map values to the provider's API calls, satisfying the need to describe resource structure before CRUD operations run.

Why this answer

In the Terraform Plugin SDK, a provider's 'Schema' defines the structure, types, and behaviour of every attribute on a resource or data source — including whether fields are Required, Optional, Computed, their types, defaults, and validation. It is the contract between Terraform configuration and the provider's CRUD functions.

Exam trap

The trap is conflating the Schema with state or provider metadata — candidates who have not written a provider may pick 'to store state' because the Schema is serialized into state, but its actual purpose is to define resource attributes.

How to eliminate wrong answers

Option B is wrong because billing is handled by the cloud provider's APIs and the AWS provider's cost estimation integration, not by the resource Schema. Option C is wrong because the provider's icon/logo is metadata in the registry manifest, not part of the Schema. Option D is wrong because state storage is handled by Terraform's state backend and the SDK's state serialization, not by the Schema definition itself — the Schema describes attributes, while state is the persisted representation of those attributes.

127
Multi-Selecthard

A platform team is preparing a reusable module for internal distribution. They want to ensure that consumers can reliably upgrade the module without unexpected breaking changes. Which TWO practices best support this goal? (Choose two.)

Select 2 answers
A.Publish each change as a new tagged release and expose the version through the module registry so consumers can pin constraints.
B.Avoid using semantic version numbers and instead increment a build counter with each commit to the default branch.
C.Store all module code in a single monolithic file to simplify diffing between releases.
D.Document every input variable and output, including type, description, and default, so consumers understand the interface contract.
E.Require all consumers to use the latest commit hash from the default branch to stay current with fixes.
AnswersA, D

Tagged releases create immutable version identifiers that consumers reference through version constraints. This lets teams adopt changes deliberately and roll back by adjusting constraints. Without tags, the registry cannot resolve versions, and consumers would be forced onto whatever the default branch contains, making controlled upgrades impossible.

Why this answer

Reliable upgrades depend on two things: immutable, semantically versioned releases that consumers can constrain, and a well-documented interface that makes the contract explicit. Tagged releases let teams pin and roll back. Documentation communicates the impact of changes.

Practices like build counters, moving branch references, or file layout do not provide the versioning discipline or contract clarity required for safe upgrades.

Exam trap

The trap here is equating frequent updates with safe upgrades, when controlled versioning and documented interfaces are what actually prevent breaking changes.

128
Multi-Selectmedium

A root module configures the AWS provider with `region = "eu-central-1"` and declares an aliased configuration `aws.dr` pointing at `region = "eu-west-1"`. The team wants a single `aws_route53_record` resource to be created in the DR region while all other AWS resources stay in eu-central-1. Which two statements correctly describe how provider selection works for this resource? (Choose two.)

Select 2 answers
A.The aliased aws.dr configuration applies to the route53 record only if the resource is moved into a child module that receives it through the providers argument.
B.A single module may define only one provider configuration per provider type, so the aliased aws.dr block is invalid.
C.The resource must include the meta-argument `provider = aws.dr` to use the DR region configuration.
D.If the resource omits the provider meta-argument, it uses the default aws configuration in eu-central-1.
E.Declaring a second aws provider block with a different region automatically makes the resource use whichever region is defined last in the file.
AnswersC, D

Provider selection is opt-in per resource. Without the provider meta-argument naming the alias, the resource uses the module's default aws configuration and would be created in eu-central-1. Writing provider = aws.dr explicitly binds the route53 record to the DR configuration, which is the only supported way to target an aliased provider from within the same module.

Why this answer

Provider selection within a module is explicit for aliased configurations and implicit for the default. The route53 record must carry provider = aws.dr to land in eu-west-1, and if that meta-argument is omitted it falls back to the default aws configuration in eu-central-1. Multiple configurations of a provider type are allowed, with only one permitted to be unaliased.

Exam trap

The trap here is thinking that defining an aliased provider block changes the target region for resources automatically rather than requiring each resource to name the alias.

129
MCQeasy

You are writing a module that creates an AWS EC2 instance and an associated security group. The module has a variable `instance_type` with a default of `t3.micro`. A consumer wants to override this default for a production environment. How should the consumer pass a different value when calling the module?

A.Create a `terraform.tfvars` file in the module's source directory containing `instance_type = "m5.large"`.
B.Set an environment variable `TF_VAR_instance_type=m5.large` before running `terraform apply`.
C.Use the `-var` flag with the module path, such as `terraform apply -var 'module.ec2.instance_type=m5.large'`.
D.Add an argument `instance_type = "m5.large"` inside the module block in the root configuration.
AnswerD

Module inputs are set by passing arguments inside the `module` block, using the variable name as the argument name. This directly overrides the default value for that instance of the module. The consumer does not need to edit the module source or use environment variables, making this the correct and standard approach.

Why this answer

Module input variables are configured by passing arguments within the `module` block in the calling configuration. The argument name matches the variable name declared in the module, and the value provided overrides the default. Environment variables and tfvars files inside the module directory do not affect child module inputs.

Exam trap

The trap here is assuming that environment variables or a tfvars file placed in the module directory can set child module inputs, when only arguments in the module block can do so.

130
MCQmedium

When using for_each on a resource, how do you access the value of the current iteration inside the resource configuration?

A.each.value
B.each.key
C.item.value
D.count.index
AnswerA

With for_each over a map or set, Terraform exposes each.key and each.value; each.value yields the current element's value, letting the resource configuration reference per-iteration data. This satisfies the need to access the current iteration's value directly within the resource block.

Why this answer

When a resource uses for_each, Terraform iterates over a map or set and exposes the current element through the each object. each.value returns the value of the current map entry (or the set member itself when iterating a set), which is what you reference inside the resource block to configure per-instance attributes. This is the standard mechanism for deriving unique names, tags, or settings for each instance created by the loop.

Exam trap

The trap here is confusing the count meta-argument with for_each — candidates who habitually use count.index may select option D, forgetting that for_each exposes each.key and each.value instead of a numeric index.

How to eliminate wrong answers

Option B is wrong because each.key returns the map key (or set member used as the key), not the value, so it would give you the identifier rather than the associated configuration data. Option C is wrong because item.value is not a Terraform construct — there is no item object in the for_each iteration scope; the correct object is each. Option D is wrong because count.index only exists when using the count meta-argument, not for_each, and it returns a numeric index rather than a map value.

131
MCQmedium

A resource has an attribute 'tags' that is managed by an external script. You want Terraform to ignore any changes made to 'tags' after the initial creation. How should you configure the 'lifecycle' block?

A.ignore_changes = [tags]
B.lifecycle { tags = ignore }
C.prevent_destroy = [tags]
D.ignore_changes = [all]
AnswerA

ignore_changes with the tags attribute instructs Terraform to disregard drift in that attribute after creation, so external script modifications no longer appear as diffs. This satisfies the requirement to leave post-creation tag changes untouched during planning and apply.

Why this answer

The 'ignore_changes' argument within a lifecycle block tells Terraform to ignore changes to the specified attributes after resource creation. Setting 'ignore_changes = [tags]' ensures that any external modifications to the tags attribute are not detected as drift, preventing Terraform from reverting them. This is the correct way to handle attributes managed outside of Terraform.

Exam trap

The trap is confusing 'ignore_changes' with other lifecycle arguments or using invalid syntax like 'ignore_changes = [all]', which is not a valid list element; candidates may also think 'prevent_destroy' can be used for attributes.

How to eliminate wrong answers

Option B is wrong because 'lifecycle { tags = ignore }' is not valid Terraform syntax; the lifecycle block does not accept a 'tags' argument. Option C is wrong because 'prevent_destroy = [tags]' is invalid; 'prevent_destroy' is a boolean that prevents resource destruction, not an attribute-level setting. Option D is wrong because 'ignore_changes = [all]' is not a valid value; while 'ignore_changes = all' is valid, it ignores all attributes, which is broader than needed and not the best practice for this scenario.

132
MCQhard

Your organization uses HCP Terraform with Sentinel policies. A policy is configured with an enforcement level of 'hard-mandatory' and checks that all AWS S3 buckets have server-side encryption enabled. A developer runs a plan that includes an unencrypted bucket. What happens when the policy fails?

A.The run proceeds to apply, but the policy failure is recorded in the audit log.
B.The run is paused, and an organization owner must manually override the policy to proceed.
C.The run continues, but the policy failure is logged as an advisory warning.
D.The run is halted immediately, and the apply cannot proceed.
AnswerD

Hard-mandatory enforcement blocks the run entirely when a policy fails. No override is possible, and the apply is prevented. This ensures that unencrypted S3 buckets are never provisioned, aligning with strict compliance requirements. The developer must fix the configuration and trigger a new run.

Why this answer

Hard-mandatory Sentinel policies block a run immediately upon failure, preventing any apply. No manual override is possible. Advisory policies only warn, and soft-mandatory allows override by authorized users.

In this scenario, the unencrypted S3 bucket would be blocked, and the developer must remediate the configuration.

Exam trap

The trap here is assuming that any policy failure can be overridden or that hard-mandatory behaves like soft-mandatory.

133
MCQeasy

You are creating a security group in AWS and need to define multiple ingress rules based on a list of port numbers. Which meta-argument is most appropriate to use to create one resource instance per port?

A.instance_count
B.count
C.dynamic
D.for_each
AnswerD

for_each iterates over a map or set of strings, creating one distinct resource instance per element with a stable key. Feeding the port list as a set produces one ingress rule per port, unlike count, which lacks per-item identity.

Why this answer

The for_each meta-argument accepts a map or set of strings and creates one resource instance per element, making it the correct choice when iterating over a list of port numbers (converted to a set or map). Unlike count, for_each produces stable, keyed instance addresses (e.g., aws_security_group_rule.ingress["22"]) so adding or removing a port doesn't cause unrelated rules to be destroyed and recreated. This is the idiomatic Terraform pattern for defining multiple ingress rules from a collection of ports.

Exam trap

The trap here is confusing count with for_each: candidates see 'one instance per element' and reflexively pick count, missing that for_each is the correct meta-argument when stable keyed addressing matters and that instance_count is a fabricated distractor.

How to eliminate wrong answers

Option A is wrong because instance_count is not a valid Terraform meta-argument — the actual meta-argument is count, and this name does not exist in the language. Option B is wrong because count uses numeric indexes (resource[0], resource[1]), so removing a port from the middle of the list shifts all subsequent indexes and forces Terraform to destroy and recreate unrelated rules. Option C is wrong because dynamic is a block-generation construct used inside a resource to produce repeated nested blocks (e.g., multiple ingress blocks), not a meta-argument that creates separate resource instances per port.

134
MCQmedium

A consultant is authoring a module that must support both AWS commercial and AWS China regions. The module needs to create resources in whichever partition the caller selects, and the caller may also want to create resources in a second region within the same partition. The module must not hardcode any region. Which approach best satisfies this?

A.Pass a `region` variable into the module and use the `aws` provider's `default_tags` to set the partition implicitly.
B.Declare two aliased AWS provider configurations in the root with distinct aliases, and have the module declare `configuration_aliases` for both, then reference each alias in the resources that must land in each region.
C.Create the AWS provider configuration inside the module itself with two `provider "aws"` blocks using different aliases and region variables.
D.Use a single default AWS provider configuration in the root and set the `region` argument dynamically inside the module using a variable.
AnswerB

Declaring `configuration_aliases` in the child module for the two aliases lets the caller pass the appropriate commercial or China provider configuration for each alias. Resources then target the correct alias, so the module supports both partitions and multiple regions without hardcoding a region or partition, matching the requirement exactly.

Why this answer

Using `configuration_aliases` in the child module with two aliased provider configurations supplied by the root gives the module the flexibility to place resources in different regions within whichever partition the caller chooses. This keeps provider configuration centralized and avoids hardcoding regions, which is the cleanest way to support both commercial and China partitions.

Exam trap

The trap here is believing that setting a region variable inside the module is sufficient to switch partitions, when partition selection is governed by the provider configuration supplied by the root.

135
MCQmedium

You are defining an input variable for a Terraform module that will accept a map of environment names to configuration objects. The object should have an instance_type string and a min_size number. You want Terraform to validate that any provided value matches this structure. Which type constraint should you use for the variable?

A.type = map(string)
B.type = object({ instance_type = string, min_size = number })
C.type = list(object({ instance_type = string, min_size = number }))
D.type = map(object({ instance_type = string, min_size = number }))
AnswerD

This type constraint defines a map whose values are objects with the specified attributes and types. Terraform will validate that each value in the map is an object containing an instance_type string and a min_size number. This precisely matches the requirement and provides strong type checking for the module input.

Why this answer

The requirement is a map where each key is an environment name and each value is an object with specific attributes. The type constraint map(object({ instance_type = string, min_size = number })) expresses exactly that. Terraform will enforce that the variable is a map and that each value conforms to the object schema, catching configuration errors early.

Exam trap

The trap here is choosing a simple map(string) because it is easy, overlooking that the values must be structured objects with multiple typed attributes.

136
MCQmedium

You are iterating over a map using for_each. You need to access the key of the current map element. Which object do you use?

A.var.key
B.each.key
C.count.key
D.each.value
AnswerB

Within a `for_each` block over a map, Terraform exposes `each.key` as the map key and `each.value` as its corresponding value, satisfying the requirement to reference the current element's key. Using `each.value` would return only the value, so `each.key` is the precise object needed here.

Why this answer

When using for_each with a map, Terraform automatically creates an each object that contains two attributes: each.key and each.value. each.key gives you the map key for the current iteration, while each.value gives the corresponding value. Therefore, to access the key of the current map element, you use each.key.

Exam trap

The trap here is confusing the each object with other iteration constructs like count or var, and mixing up each.key with each.value. Candidates often mistakenly choose each.value when asked for the key, or try to use count.index in a for_each context.

How to eliminate wrong answers

Option A is wrong because var.key is not a valid reference; var is used to access input variables, not iteration metadata. Option C is wrong because count.key is invalid; count is used with count-based loops and only provides count.index, not a key. Option D is wrong because each.value provides the value associated with the current key, not the key itself.

137
MCQeasy

What happens if two team members try to apply changes to the same workspace in HCP Terraform simultaneously?

A.The state file will be corrupted
B.The latest one wins
C.Both runs will fail
D.The second run is queued
AnswerD

HCP Terraform enforces per-workspace run concurrency: only one run may hold the lock at a time. The second apply therefore waits in a queue until the first completes, satisfying the simultaneous-apply constraint without corrupting state.

Why this answer

HCP Terraform (formerly Terraform Cloud) enforces a run queue per workspace. When two team members trigger runs simultaneously, the first run acquires the workspace lock and executes; the second run is placed in a queue and will start only after the first completes (or is canceled). This prevents concurrent state modifications and state corruption.

Exam trap

The trap here is assuming HCP Terraform behaves like local Terraform with no locking, leading candidates to pick 'state file will be corrupted' or 'latest one wins' instead of recognizing the queueing behavior.

How to eliminate wrong answers

Option A is wrong because HCP Terraform's state locking mechanism prevents corruption — the queue ensures only one run modifies state at a time. Option B is wrong because 'latest one wins' implies concurrent execution with the last writer overwriting, which is not how HCP Terraform works; runs are serialized, not raced. Option C is wrong because both runs do not fail — the first succeeds and the second waits, then runs.

138
Multi-Selecthard

Which THREE factors influence the choice of using an HCP Terraform Agent?

Select 3 answers
A.Need for private network connectivity
B.To increase the speed of the provider download
C.Compliance requirements for data locality
D.The need to access internal APIs
E.To remove the need for a VCS
AnswersA, C, D

An HCP Terraform Agent runs inside your own network, so it is chosen when private connectivity is required — reaching internal APIs, databases or services that the hosted run environment cannot route to, and avoiding exposure of those endpoints to the public internet.

Why this answer

Option A is correct because HCP Terraform Agents are self-hosted workers that run inside your own network, allowing Terraform runs to reach private endpoints, private VCS systems, and private module registries that the hosted HCP Terraform workers cannot access. Option C is correct because agents execute the plan and apply operations on infrastructure you control, so sensitive state, variables, and provider credentials never leave your environment, satisfying data residency and compliance mandates. Option D is correct because accessing internal APIs (for example, on-premises or non-internet-facing services) requires an agent that has network line-of-sight to those APIs, which hosted runners lack.

Option B is not a valid factor: provider download speed depends on registry/CDN performance and caching, not on whether an agent is used, and agents can even be slower if their egress is constrained. Option E is not a valid factor: agents do not eliminate the need for a VCS connection; HCP Terraform still requires a linked VCS repository (or CLI/API-driven uploads) to obtain configuration, and the agent only changes where runs execute.

Exam trap

The trap is assuming agents are for performance or VCS replacement; they are primarily for network access, compliance, and internal API connectivity.

139
MCQhard

If a module has a required variable but you do not provide it in the calling configuration, what happens?

A.Terraform uses 'null' for the value.
B.Terraform uses the variable value from the previous state.
C.Terraform fails with an error during the planning phase.
D.Terraform automatically sets the value to an empty string.
AnswerC

Terraform validates required input variables during the plan, so omitting one halts execution with an error before any resources are provisioned. This satisfies the stem's constraint: a required variable has no default, and the calling configuration supplies no value, so planning cannot resolve the reference.

Why this answer

If a module declares a variable without a default and the calling configuration does not supply a value, Terraform raises an error during the planning phase, stating that the required variable has not been set. Terraform does not invent a value or fall back to prior state. This fail-fast behavior ensures module contracts are honored.

Exam trap

The trap is assuming Terraform is lenient with missing inputs — candidates pick null or empty string because those are common defaults in other languages, but Terraform treats missing required variables as a hard error.

How to eliminate wrong answers

Option A is wrong because Terraform does not default missing required variables to null — null is only used when explicitly set or when a variable has a default of null. Option B is wrong because Terraform does not read variable values from previous state; variables are inputs, not state attributes. Option D is wrong because Terraform does not coerce missing values to empty strings — that would silently mask configuration errors.

140
MCQmedium

When configuring team permissions, what does the 'Workspace: Settings' permission allow?

A.Viewing plan and apply logs only.
B.Triggering runs manually.
C.Modifying workspace settings like variable sets and execution modes.
D.Deleting the workspace.
AnswerC

Modifying variable sets and execution modes requires the workspace-level Settings permission, which governs configuration scoped to a single workspace rather than organisation-wide policy. This satisfies the stem's constraint by granting exactly the administrative control needed over workspace-specific variables and run behaviour, without broader access.

Why this answer

The 'Workspace: Settings' permission in HCP Terraform grants the ability to modify workspace-level configuration, including variable sets, execution modes (remote/local/agent), and other workspace settings. It does not grant run execution or deletion rights. This permission is typically assigned to workspace admins who need to tune how runs behave.

Exam trap

The trap is assuming that 'Settings' includes all administrative actions like deletion or run triggering — candidates often conflate workspace settings with full workspace administration.

How to eliminate wrong answers

Option A is wrong because viewing plan and apply logs is covered by read-level permissions, not Settings. Option B is wrong because triggering runs manually is a separate 'Queue Plan' or 'Apply' permission. Option D is wrong because deleting a workspace requires a higher-level administrative permission, not just Settings.

141
MCQhard

You are managing an HCP Terraform organization with multiple workspaces. A security requirement mandates that all workspaces use a specific version of the AWS provider (5.0.0 or later) and that any deviation triggers a notification to the security team. You have configured a Sentinel policy to check the provider version. Which enforcement level should you set for this policy to meet the requirement while allowing developers to proceed with their work if they acknowledge the risk?

A.advisory
B.hard-mandatory
C.disabled
D.soft-mandatory
AnswerD

soft-mandatory allows a run to proceed only if a user with permission to override policies acknowledges the failure. This meets the requirement by allowing developers to continue after acknowledgment. The override action is logged, and notifications can be configured separately. It balances security with flexibility, unlike hard-mandatory which blocks entirely.

Why this answer

soft-mandatory enforcement requires an authorized user to explicitly override a policy failure before the run can continue. This matches the need to allow developers to proceed after acknowledging the risk. The override is recorded, and notifications can be set up via HCP Terraform's notification features. hard-mandatory would block all non-compliant runs, advisory would not require acknowledgment, and disabled would ignore the policy.

Exam trap

The trap here is confusing advisory with soft-mandatory: advisory does not require acknowledgment and does not block the run, while soft-mandatory requires an explicit override by a user with appropriate permissions, which is necessary when acknowledgment is required.

142
MCQeasy

A consultant joins a project and runs `terraform init` on a configuration that references `hashicorp/aws` version `~> 5.0`. The init succeeds, but a teammate later reports that their init fails with a checksum mismatch for the same provider version. The consultant's platform is `linux_amd64` and the teammate's is `darwin_arm64`. What is the most likely explanation and the correct remediation?

A.The teammate must delete `.terraform.lock.hcl` and re-run `terraform init` so Terraform regenerates it locally.
B.The teammate's `.terraform.lock.hcl` lacks an entry for `darwin_arm64`, so `terraform providers lock -platform=darwin_arm64` must be run and the updated lock file committed.
C.The AWS provider version `~> 5.0` is incompatible with `darwin_arm64`, so the teammate must downgrade to version 4.x.
D.The teammate should set `TF_REGISTRY_CLIENT_TIMEOUT` to a larger value so the download of the `darwin_arm64` package completes.
AnswerB

The dependency lock file records checksums per platform. If it was generated only on `linux_amd64`, it contains no hashes for `darwin_arm64`, so init on macOS fails verification. Running `terraform providers lock -platform=linux_amd64 -platform=darwin_arm64` adds the missing hashes, and committing the result lets every platform verify the same provider version.

Why this answer

The dependency lock file stores provider checksums for the platforms on which it was generated. A lock file created only on `linux_amd64` has no hashes for `darwin_arm64`, so init on Apple Silicon cannot verify the download. Running `terraform providers lock` with both `-platform` values records hashes for each platform, and committing the updated file resolves the mismatch for the whole team.

Exam trap

The trap here is treating a checksum mismatch as a corruption or network problem and deleting the lock file instead of adding the missing platform hashes.

143
MCQmedium

Your organization uses HCP Terraform to manage AWS infrastructure. A platform engineer has been assigned the 'Write' permission on a workspace but is still unable to modify the AWS credentials stored as workspace variables. Which HCP Terraform permission level is required to manage sensitive workspace variables?

A.Write
B.Admin
C.Plan
D.Read
AnswerB

Admin permission on a workspace grants full control, including the ability to create, edit, and delete workspace variables, including sensitive ones such as AWS access keys. Write permission allows runs and state operations but does not permit variable management, so the engineer must be elevated to Admin to modify the credentials.

Why this answer

Managing workspace variables, particularly sensitive ones like AWS credentials, requires Admin permission on the workspace. Write permission allows runs and applies but not variable management. Plan and Read are view-only levels.

Therefore, the engineer must be granted Admin to edit the credentials.

Exam trap

The trap here is assuming that Write permission includes the ability to manage all workspace settings, including sensitive variables.

144
MCQmedium

Your team uses HCP Terraform with a VCS-driven workflow. A developer opens a pull request that modifies a Terraform configuration. You want the plan to run automatically and the results to be visible on the pull request before merging. What should you configure?

A.Enable automatic speculative plans on the workspace and connect the workspace to the VCS repository.
B.Set the workspace execution mode to 'Remote' and enable run triggers from the VCS repository.
C.Create a CLI-driven workspace and run terraform plan locally on the pull request branch.
D.Configure a webhook in the VCS provider to call the HCP Terraform API to start a run on every push.
AnswerA

Automatic speculative plans trigger a plan-only run when a pull request is opened or updated, and the results are posted as a commit status check on the pull request. This provides early feedback without applying changes, exactly matching the requirement to see plan results before merging.

Why this answer

Speculative plans are a core feature of HCP Terraform's VCS-driven workflow. They run automatically on pull requests without applying changes, and the plan output is displayed as a status check on the PR. This gives reviewers immediate insight into the proposed infrastructure changes, enabling informed decisions before merge.

Exam trap

The trap here is assuming that any VCS-connected workspace automatically runs speculative plans; they must be explicitly enabled in the workspace settings.

145
MCQeasy

A team defines a variable `allowed_ports` as `list(number)` and wants to validate that every value is between 1 and 65535 before any resources are planned. They add a `validation` block to the variable. Which configuration correctly enforces this constraint?

A.validation { condition = alltrue([for p in var.allowed_ports : p >= 1 && p <= 65535]) error_message = "Ports must be between 1 and 65535." }
B.validation { condition = anytrue([for p in var.allowed_ports : p >= 1 && p <= 65535]) error_message = "Ports must be between 1 and 65535." }
C.validation { condition = contains(var.allowed_ports, 80) error_message = "Ports must be between 1 and 65535." }
D.validation { condition = length(var.allowed_ports) > 0 error_message = "Ports must be between 1 and 65535." }
AnswerA

The `alltrue` function returns true only when every element of the list satisfies the predicate, and the `for` expression maps each port to a boolean. This condition correctly fails if any port is out of range. The `error_message` provides a clear diagnostic, and validation runs before planning, preventing invalid input from reaching resources.

Why this answer

Variable validation conditions must evaluate to a boolean that is true when the input is acceptable. To enforce a per-element range, the condition should reduce the list of per-port checks with `alltrue`, ensuring every element meets the bounds. This catches invalid ports before planning and produces the configured error message.

Exam trap

The trap here is using `anytrue`, which passes when just one port is valid, instead of `alltrue`, which is required to enforce a constraint on every element.

146
MCQhard

An operations engineer maintains a module that creates an AWS RDS instance. The module block in the root configuration includes a `providers` argument mapping the module's `aws` provider to an aliased provider configuration targeting a secondary region. A new resource is added inside the module that uses `aws.global` as an explicit provider. What happens when the engineer runs `terraform plan`?

A.Terraform automatically inherits the root module's `aws.global` provider configuration for the child module.
B.Terraform errors because the module does not declare `aws.global` in its required_providers block.
C.Terraform errors because the module only received a mapping for the default `aws` configuration, so `aws.global` has no configuration passed in.
D.Terraform silently falls back to the default `aws` provider configuration in the child module and plans successfully.
AnswerC

A module can only use provider configurations explicitly passed to it through the `providers` argument. Since the root only mapped the default `aws` provider, the child module has no configuration for the `aws.global` alias. The resource referencing `aws.global` therefore has no valid provider configuration, and Terraform reports an error during plan.

Why this answer

Modules receive provider configurations only through explicit `providers` mappings in the module block. When a resource inside the module references an aliased provider such as `aws.global`, that alias must have been passed in. Because the root only supplied the default `aws` configuration, the alias is undefined inside the module and planning fails with an error about the missing provider configuration.

Exam trap

The trap here is believing aliased provider configurations propagate into child modules automatically, when only explicitly passed configurations are available.

147
Multi-Selecthard

Which TWO of the following are valid ways to pass a provider configuration to a child module?

Select 2 answers
A.Defining the provider inside the module's 'main.tf'.
B.Using the 'providers' meta-argument inside the module block.
C.Passing the provider as a string input variable.
D.Using a global variable for provider credentials.
E.Inheritance from the root module's provider configuration.
AnswersB, E

The providers meta-argument explicitly maps each provider configuration the child module expects to a specific configuration from the calling module, such as aws = aws.usw2. This is the documented explicit passing mechanism, satisfying the requirement for a valid way to supply provider configuration.

Why this answer

Option B is correct because Terraform supports the 'providers' meta-argument inside a module block, which explicitly maps a provider configuration from the parent (root) module to a specific provider alias expected by the child module, e.g. 'providers = { aws = aws.usw2 }'. Option E is correct because Terraform automatically inherits the default (unaliased) provider configurations from the root module into child modules, so a child module using 'aws' without its own provider block receives the root's default AWS provider configuration. Option A is not a way to pass a configuration from the parent; defining a provider inside the module's main.tf creates a separate provider configuration local to the module rather than passing one in.

Option C is invalid because provider configurations are complex objects, not strings, and cannot be supplied via input variables. Option D is invalid because Terraform has no concept of a 'global variable' for provider credentials; credentials belong in provider blocks or environment variables, not a global variable mechanism.

Exam trap

The trap is thinking providers can be passed as string variables or defined freely inside child modules — Terraform treats providers as configuration objects passed via the `providers` meta-argument or inherited from the root, not as ordinary input values.

148
Multi-Selecthard

Which TWO actions can be taken to resolve issues where a resource must be replaced, but 'prevent_destroy' is enabled?

Select 2 answers
A.Use 'terraform apply -auto-approve'.
B.Run 'terraform state rm' to remove the resource from state and re-import.
C.Use 'terraform refresh' to update the constraint.
D.Remove the prevent_destroy block from the configuration.
E.Set the prevent_destroy argument to false in the CLI.
AnswersB, D

Removing the resource from state with `terraform state rm` detaches it from Terraform's management, so the `prevent_destroy` lifecycle guard no longer applies to it. The subsequent re-import brings it back under management, letting the replacement proceed without the guard blocking destruction.

Why this answer

Option B is correct because running 'terraform state rm <resource_address>' removes the resource from Terraform's state file, which detaches it from the 'prevent_destroy' lifecycle meta-argument (that constraint is only enforced when Terraform plans to destroy a resource it manages in state); the resource can then be re-imported with 'terraform import' or recreated without triggering the destroy protection. Option D is correct because 'prevent_destroy' is a lifecycle block setting in the resource configuration, so deleting that lifecycle block (or the specific prevent_destroy argument) from the .tf file removes the constraint and allows Terraform to plan and perform the replacement. Option A is wrong because '-auto-approve' only skips the interactive approval prompt; it does not override lifecycle constraints, and the plan will still fail with an error that the resource has prevent_destroy set.

Option C is wrong because 'terraform refresh' only reconciles state with real infrastructure and has no effect on lifecycle meta-arguments. Option E is wrong because 'prevent_destroy' cannot be set or toggled via a CLI flag or argument; it is defined only in the resource's lifecycle block in configuration.

Exam trap

The trap is assuming that CLI flags like -auto-approve or a hypothetical -prevent-destroy=false can override lifecycle settings; in reality, prevent_destroy is configuration-only and must be removed or bypassed via state manipulation.

149
MCQeasy

Which of the following is an advantage of using HCP Terraform over local state for team collaboration?

A.It provides state locking and run history
B.It converts HCL to JSON
C.It eliminates the need for AWS providers
D.It is always free
AnswerA

HCP Terraform's remote backend serialises runs through state locking and retains historical run records, preventing concurrent applies from corrupting shared state. This satisfies the stem's team-collaboration advantage, which local state files cannot provide without external tooling.

Why this answer

HCP Terraform (formerly Terraform Cloud) provides remote state management with built-in state locking and run history, which are critical for team collaboration. State locking prevents concurrent runs from corrupting the state file, while run history allows teams to audit changes and roll back if needed. These features are not available with local state, making HCP Terraform a superior choice for teams.

Exam trap

The trap here is confusing HCP Terraform's collaboration features with core Terraform capabilities; candidates might think HCL-to-JSON conversion or provider elimination is an advantage, but these are unrelated to state management.

How to eliminate wrong answers

Option B is wrong because HCL to JSON conversion is a function of Terraform core (e.g., `terraform show -json`), not a specific advantage of HCP Terraform; it happens locally as well. Option C is wrong because HCP Terraform does not eliminate the need for AWS providers; providers are still required to interact with AWS APIs, and HCP Terraform merely manages state and runs. Option D is wrong because HCP Terraform is not always free; while it offers a free tier for small teams, advanced features like SSO, policy enforcement, and larger run concurrency require paid plans.

150
MCQeasy

Which of the following is an advantage of using Variable Sets?

A.They centralize variable management to avoid duplication across workspaces.
B.They allow for secret rotation in AWS.
C.They automatically run Terraform plans.
D.They provide encryption for state files.
AnswerA

Variable Sets in Terraform Cloud let you define values once and apply them across multiple workspaces, eliminating per-workspace duplication. This directly satisfies the scenario's requirement for centralised management, since shared credentials, provider tokens, or environment values need updating in only one place rather than being replicated and maintained individually.

Why this answer

Variable Sets allow you to define variables once and apply them across multiple workspaces, eliminating duplication and ensuring consistency. They are ideal for shared credentials, common tags, or provider configurations that many workspaces need. This centralization reduces drift and simplifies updates.

Exam trap

The trap is confusing Variable Sets with other HCP Terraform features like Sentinel policies or run triggers — candidates may think Variable Sets can automate runs or rotate secrets, but they are purely for variable management.

How to eliminate wrong answers

Option B is wrong because secret rotation is handled by Vault or AWS Secrets Manager, not by Terraform Variable Sets. Option C is wrong because Variable Sets do not trigger runs; runs are triggered by VCS commits, CLI, or API calls. Option D is wrong because state file encryption is a backend feature (e.g., S3 SSE, HCP Terraform encryption), not a function of Variable Sets.

Page 1

Page 2 of 4

Page 3

All pages