Courseiva

HashiCorp Certified: Terraform Authoring and Operations Professional (AWS provider) (AWS provider) (AWS provider) — Questions 226–278

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

Page 3

Page 4 of 4

226
MCQeasy

Which command is used to move a resource from one state file to another, commonly used when refactoring modules?

A.terraform migrate
B.terraform plan -refactor
C.terraform refresh
D.terraform state mv
AnswerD

terraform state mv relocates a resource entry between state files or addresses, updating the state to match refactored configuration without destroying or recreating infrastructure. This satisfies the module-refactoring scenario by preserving existing resources while their configuration addresses change.

Why this answer

terraform state mv moves a resource from one state address to another, and when used with different state files (via -state and -state-out), it can move resources between state files. This is the standard command for refactoring modules without destroying and recreating resources. It updates the state mapping so Terraform associates the existing resource with the new address.

Exam trap

The trap is inventing commands like terraform migrate or plan -refactor — only terraform state mv (and terraform state push/pull for whole files) can move resources between states.

How to eliminate wrong answers

Option A is wrong because terraform migrate is not a real Terraform command. Option B is wrong because terraform plan -refactor does not exist; plan has no refactor flag. Option C is wrong because terraform refresh only reconciles state with real infrastructure, it does not move resources between state files or addresses.

227
MCQhard

You are designing a module that should conditionally create resources based on a boolean input. What feature should you use?

A.Define multiple resources and use 'depends_on' to link them.
B.Use the 'count' meta-argument with a ternary expression.
C.Use an 'if' block around the resource definition.
D.Use the 'module' meta-argument inside the resource.
AnswerB

The count meta-argument combined with a ternary expression evaluates the boolean to either 1 or 0, creating or omitting the resource instances accordingly. This directly satisfies the stem's requirement for conditional resource creation from a boolean input.

Why this answer

The `count` meta-argument accepts a numeric value, and combining it with a ternary expression (e.g., `count = var.enabled ? 1 : 0`) is the canonical Terraform pattern for conditionally creating a resource. When count evaluates to 0, no instances are created; when it evaluates to 1, a single instance is provisioned. This is the idiomatic way to implement conditional resource creation in Terraform.

Exam trap

The trap is assuming Terraform has procedural `if` statements like a general-purpose language — it does not; conditionals must be expressed through expressions such as ternary operators combined with `count` or `for_each`.

How to eliminate wrong answers

Option A is wrong because `depends_on` only establishes explicit ordering between resources — it does not conditionally create or skip resources. Option C is wrong because Terraform's HCL does not have an `if` block construct for wrapping resource definitions; conditionals are expressed through expressions like ternary operators. Option D is wrong because `module` is a top-level block type, not a meta-argument that can be nested inside a resource block.

228
MCQmedium

If you need to share output values between workspaces, what is the best practice in HCP Terraform?

A.Emailing the values
B.Hardcoding the IDs
C.Exporting to a flat file
D.Using the 'terraform_remote_state' data source
AnswerD

The terraform_remote_state data source reads another workspace's stored state outputs at plan time, exposing them as data attributes. This is the documented best practise for cross-workspace output sharing, avoiding hardcoded values or manual copying between configurations.

Why this answer

The `terraform_remote_state` data source is the canonical way to share outputs between workspaces (or separate state files) in HCP Terraform and Terraform OSS. It reads the remote state of another workspace and exposes its root-level outputs as attributes, so consumers always get the latest values without manual copying. This keeps state as the single source of truth and avoids drift.

Exam trap

The trap here is assuming any file- or copy-based mechanism is acceptable for cross-workspace sharing; Terraform exams consistently reward the native `terraform_remote_state` data source over manual or ad-hoc methods.

How to eliminate wrong answers

Option A is wrong because emailing values is manual, insecure, and creates drift the moment the source workspace changes. Option B is wrong because hardcoding IDs breaks the link between workspaces — any change in the source workspace silently invalidates the consumer. Option C is wrong because exporting to a flat file is an out-of-band artifact that Terraform cannot track, version, or refresh, so it is not a supported sharing mechanism.

229
MCQmedium

Your team maintains a shared Terraform configuration in a GitHub repository. A developer opens a pull request that changes the instance type of a production EC2 instance. You want the change to be automatically validated by running a speculative plan before any human reviews the code. Which HCP Terraform feature should you configure to achieve this?

A.CLI-driven runs with remote backend
B.VCS-driven speculative plans
C.Run Triggers
D.Policy as Code with Sentinel
AnswerB

When a workspace is connected to a VCS repository, HCP Terraform automatically queues a speculative plan for every pull request that modifies the working directory. This plan runs without applying changes, giving reviewers a preview of the infrastructure impact. Configuring the workspace with VCS integration is exactly what enables this automatic validation.

Why this answer

VCS-driven speculative plans are automatically queued by HCP Terraform when a pull request is opened against a connected repository, running a plan without applying. This provides early feedback and validation before merge. Run Triggers orchestrate runs between workspaces, CLI-driven runs are manual, and Sentinel policies only enforce rules during an existing run.

Exam trap

The trap here is confusing policy enforcement with automatic validation, assuming that Sentinel or Run Triggers can trigger plans on pull requests.

230
MCQhard

A provider binary is not found in the local Terraform registry cache. What command should you run to force Terraform to download the provider again?

A.terraform plan -refresh-only
B.terraform init -upgrade
C.terraform providers install
D.terraform refresh
AnswerB

terraform init -upgrade re-resolves provider version constraints and downloads the newest permitted versions, bypassing the cached binary. This satisfies the stem's requirement to force a fresh download when the provider binary is missing from the local registry cache.

Why this answer

The 'terraform init -upgrade' command forces Terraform to re-evaluate and download the latest versions of providers that meet the version constraints, even if a provider is already present in the local cache. This is the correct way to update providers or re-download a missing provider binary. It also updates the dependency lock file.

Exam trap

The trap is confusing 'terraform init -upgrade' with other commands like 'terraform refresh' or 'terraform plan -refresh-only', which do not handle provider installation. Candidates might also think 'terraform providers install' exists.

How to eliminate wrong answers

Option A is wrong because 'terraform plan -refresh-only' only refreshes the state to match remote objects and does not install or upgrade providers. Option C is wrong because 'terraform providers install' is not a valid Terraform command; provider installation is done via 'terraform init'. Option D is wrong because 'terraform refresh' updates the state file with real-world resources but does not manage provider installation.

231
Multi-Selectmedium

Which THREE of the following are valid ways to pass data to a module dynamically?

Select 3 answers
A.Using variables
B.Directly editing the state
C.Using a dynamic block for module calling
D.Using for_each on a module block
E.Using complex object types
AnswersA, D, E

Input variables declared in the child module accept values supplied by the calling module's arguments, making data injection dynamic per invocation. This satisfies the requirement because the same module can receive different values on each call.

Why this answer

Option A (Using variables) is correct because Terraform modules accept input values through declared input variables, and callers pass data dynamically via the module block's arguments (e.g., variable_name = value), which is the standard mechanism for parameterizing a module. Option D (Using for_each on a module block) is correct because Terraform supports for_each on module blocks, allowing multiple module instances to be created dynamically from a map or set, with each instance receiving distinct input values derived from the iteration. Option E (Using complex object types) is correct because input variables can be typed as complex types such as object({...}), map, list, or tuple, enabling structured, dynamic data to be passed into a module rather than only simple primitives.

Option B (Directly editing the state) is not a valid way to pass data to a module, since the state file is a record of managed infrastructure and manually editing it is unsupported and does not feed inputs into module configuration. Option C (Using a dynamic block for module calling) is not valid because dynamic blocks only generate repeated nested configuration blocks within a resource, data, or module argument, not the module call itself, so they cannot be used to invoke modules dynamically.

Exam trap

The trap is thinking dynamic blocks can be used to call modules — dynamic blocks only generate nested configuration blocks within resources, not module invocations.

232
MCQeasy

Your team is using HCP Terraform. You need to isolate development, staging, and production environments using the same set of configuration files. Which feature should you implement?

A.Modules
B.Sentinel Policies
C.Workspaces
D.Run Triggers
AnswerC

Workspaces let one configuration directory drive multiple, isolated deployments, each holding its own state, variables and run history. Separate workspaces for development, staging and production therefore reuse the same configuration files while keeping environments fully isolated, satisfying the stated constraint.

Why this answer

HCP Terraform workspaces provide isolated environments for infrastructure management, each with its own state, variables, and run history. By using the same configuration files across multiple workspaces, you can deploy to development, staging, and production with environment-specific variables and separate state, achieving the required isolation. This is the standard pattern for multi-environment deployments in HCP Terraform.

Exam trap

The trap is confusing workspaces with modules or policies; candidates may think modules provide environment isolation, but modules are about code reuse, while workspaces are about state and variable isolation.

How to eliminate wrong answers

Option A is wrong because modules are reusable units of Terraform configuration, not an isolation mechanism for environments; they help organize code but do not separate state or variables per environment. Option B is wrong because Sentinel Policies are policy-as-code guardrails that enforce rules on runs, not a way to isolate environments. Option D is wrong because Run Triggers are used to chain runs across workspaces, not to isolate environments; they actually create dependencies between workspaces.

233
MCQhard

If a developer wants to use a provider that is not in the public registry, can they still use it?

A.Yes, by using a local registry or filesystem mirror.
B.No, only registry providers are supported.
C.Yes, by setting the env var TF_IN_AUTOMATION.
D.Yes, by recompiling Terraform binary.
AnswerA

Terraform resolves providers through installation sources beyond the public registry, including local filesystem mirrors and private registries. Configuring such a source lets the developer install and use the provider normally, so absence from the public registry is not a blocker.

Why this answer

Terraform supports provider installation from local filesystem mirrors or a local registry, not just the public Terraform Registry. A filesystem mirror is a directory containing provider packages in the expected layout, and a local registry can serve providers over HTTP. This allows developers to use custom or private providers without publishing them publicly.

Exam trap

The trap here is assuming that Terraform only supports providers from the public registry, overlooking the provider installation configuration options like filesystem mirrors and local registries.

How to eliminate wrong answers

Option B is wrong because Terraform can install providers from sources other than the public registry, such as filesystem mirrors or network mirrors. Option C is wrong because TF_IN_AUTOMATION is an environment variable that adjusts Terraform's output to be more automation-friendly; it does not enable provider installation from non-public sources. Option D is wrong because recompiling the Terraform binary is not required to use custom providers; Terraform's provider plugin architecture allows external providers to be installed and used without modifying the core binary.

234
MCQmedium

A platform team maintains a shared Terraform child module that contains only a single `aws_s3_bucket` resource and no `provider` block. The module's `versions.tf` declares `required_providers { aws = { source = "hashicorp/aws", version = "~> 5.0" } }`. A consumer root module configures the AWS provider with `region = "us-west-2"` and calls the child module without any `providers` argument. During `terraform plan`, which AWS region will be used to evaluate the bucket resource inside the child module?

A.Terraform fails the plan because a child module that declares required_providers must also declare its own provider block.
B.The child module inherits the root module's default AWS provider configuration, so the bucket is planned in us-west-2.
C.The provider is instantiated independently inside the child module and uses the AWS SDK default region from the execution environment.
D.The bucket is planned in the region declared inside the hashicorp/aws provider's own default configuration.
AnswerB

Because the child module declares no provider block of its own, it automatically inherits the root module's default (unaliased) provider configuration, including region us-west-2. The required_providers entry only constrains source and version, it does not create or isolate a provider instance. This inheritance is the standard behavior for unaliased providers passed implicitly down the module tree.

Why this answer

An unaliased provider configuration in the root module is implicitly inherited by every child module that does not declare its own provider block. Since the child module only constrains source and version through required_providers, the root's region = "us-west-2" configuration applies when Terraform evaluates the bucket. No separate provider instance is created, and no environment fallback occurs.

Exam trap

The trap here is assuming that declaring required_providers inside a child module forces that module to define or isolate its own provider configuration.

235
MCQhard

During a refactor, an engineer renames the Terraform address of an aws_s3_bucket from aws_s3_bucket.logs to aws_s3_bucket.audit_logs in the configuration, keeping every argument identical. The bucket holds production logs. What is the safest way to apply this change without destroying and recreating the bucket?

A.Add lifecycle { prevent_destroy = true } to the renamed resource, then apply so Terraform refuses to delete the original bucket.
B.Run terraform state mv aws_s3_bucket.logs aws_s3_bucket.audit_logs, then run terraform plan to confirm no changes.
C.Use terraform apply -replace=aws_s3_bucket.audit_logs so Terraform rebuilds the bucket under the new name without data loss.
D.Run terraform import aws_s3_bucket.audit_logs with the bucket name, then delete the old resource block from configuration.
AnswerB

terraform state mv rewrites the resource address inside the state file without touching the real S3 bucket, so the renamed configuration block now matches an existing state entry. A subsequent plan should report no changes, proving the bucket is preserved. This is the standard technique for refactoring addresses while avoiding an unnecessary destroy and recreate of production data.

Why this answer

Renaming a resource address changes only the identifier in configuration and state, not the underlying object. terraform state mv updates the state entry to match the new address so no destroy or create is planned, and a follow-up plan verifies the migration. Import creates duplicates, prevent_destroy blocks the apply, and -replace deliberately destroys the bucket.

Exam trap

The trap here is assuming that renaming a resource block is harmless metadata, when Terraform actually plans to destroy the old address and create a new one unless state is moved first.

236
MCQhard

A configuration defines a dynamic block that generates ingress rules for an aws_security_group from a list of objects. Each object has a from_port, to_port, and protocol attribute, and one object also carries an extra cidr_blocks list. You want every generated rule to include the from_port, to_port, and protocol values, and to include cidr_blocks only when it is present, without writing a separate block for the odd entry. Which approach satisfies this?

A.Declare the variable as a list of maps and rely on Terraform to supply empty defaults for any map keys that are absent.
B.Use content with from_port = rule.value.from_port and reference cidr_blocks = rule.value.cidr_blocks inside the same content block.
C.Add a nested dynamic "cidr_blocks" block inside the ingress content, iterating over rule.value.cidr_blocks with for_each and guarding the iteration with a conditional that yields an empty list when the attribute is null.
D.Set the iterator argument to a custom label and reference the custom label inside content for all attributes, including cidr_blocks.
AnswerC

Nested dynamic blocks let you conditionally generate inner arguments, and wrapping the source in a conditional that returns an empty list when the attribute is null means zero inner blocks are produced for entries lacking cidr_blocks. The required scalar arguments remain in the outer content, so every rule is valid.

Why this answer

A nested dynamic block whose for_each source is guarded by a conditional that returns an empty list when the attribute is null produces inner blocks only for entries that actually carry cidr_blocks, while the outer content always emits the required scalar arguments. This keeps one uniform ingress block definition that adapts to heterogeneous input.

Exam trap

The trap here is assuming Terraform silently tolerates references to attributes that some objects lack, when such references actually fail evaluation for the missing entries.

237
MCQmedium

Your team is using HCP Terraform with a workspace that has a remote backend. A developer runs terraform apply from their local CLI, but the apply fails because the state is locked. Which action should the developer take to resolve the lock and proceed with the apply?

A.Check the workspace's run history for an active run and wait for it to complete or cancel it.
B.Run terraform init -reconfigure to reset the backend.
C.Delete the .terraform directory and re-run terraform init.
D.Run terraform force-unlock with the lock ID.
AnswerA

In HCP Terraform, state locks are typically held by active runs. The developer should inspect the workspace's run history to see if a run is currently executing. If so, waiting for it to finish or canceling it will release the lock. This is the safe and recommended way to resolve the lock without risking state corruption.

Why this answer

State locks in HCP Terraform are held by active runs. The correct approach is to check the workspace's run history for an in-progress run and either wait for it to complete or cancel it. Force-unlock, reinit, or deleting local files do not safely resolve the lock and can cause issues.

Exam trap

The trap here is assuming that local CLI commands like force-unlock or reinit can resolve a lock managed by HCP Terraform's remote backend.

238
MCQmedium

What is the effect of running 'terraform init -upgrade' on the '.terraform.lock.hcl' file?

A.It deletes the file.
B.It makes the file read-only.
C.It hides the file.
D.It updates the file to reflect new provider versions.
AnswerD

Running `terraform init -upgrade` re-resolves provider version constraints and rewrites `.terraform.lock.hcl` with the newest versions permitted by your configuration, along with fresh checksums. This satisfies the stem's requirement to reflect upgraded provider selections, whereas a plain `terraform init` installs only the versions already recorded in the lock file.

Why this answer

Running 'terraform init -upgrade' re-resolves provider version constraints against the registry and updates the .terraform.lock.hcl file to record the newly selected provider versions and their hashes. It is the supported way to move to newer provider releases without deleting the lock file manually.

Exam trap

The trap is thinking the lock file is immutable or that init -upgrade deletes it — it actually rewrites the file to capture upgraded provider versions and hashes.

How to eliminate wrong answers

Option A is wrong because init -upgrade rewrites the lock file rather than deleting it. Option B is wrong because the lock file remains writable by Terraform; it is not chmod'd to read-only. Option C is wrong because the file is not hidden — it is a normal dotfile in the working directory.

239
MCQhard

Your organization uses HCP Terraform with the AWS provider. A Sentinel policy set is attached to the 'production' project with a soft-mandatory policy that checks for required tags on all AWS resources. During a run, the policy fails because a developer forgot to add a 'CostCenter' tag to an EC2 instance. What is the outcome of the run, and what can the developer do?

A.The run is paused, and a user with permission to override policies can choose to override the failure and continue the apply.
B.The run continues automatically but logs a warning, and the apply proceeds without any intervention.
C.The run fails immediately and cannot be overridden; the developer must modify the configuration and push a new commit.
D.The run is paused, and an organization owner must approve an override before the apply can proceed.
AnswerA

Soft-mandatory policies pause the run when they fail, allowing a user with the 'manage policy overrides' permission to override the failure. This enables the run to continue to apply after the override, which is the expected behavior for a soft-mandatory policy.

Why this answer

A soft-mandatory Sentinel policy failure pauses the run and requires an authorized user to override the failure before the apply can proceed. This provides a balance between enforcement and flexibility, allowing developers to address issues or override when justified. The developer can override if they have the necessary permissions, and the run will then continue.

Exam trap

The trap here is confusing soft-mandatory with advisory or hard-mandatory policies; soft-mandatory pauses and allows override, while advisory only warns and hard-mandatory blocks without override.

240
MCQmedium

A team defines an aws_instance resource whose instance_type should normally come from a variable, but for one specific workspace named "dr" the value must be forced to t3.micro regardless of the variable. The team wants a single resource block that behaves correctly in every workspace without duplicating the resource. Which expression assigns instance_type appropriately?

A.instance_type = terraform.workspace != "dr" ? "t3.micro" : var.instance_type
B.instance_type = terraform.workspace == "dr" ? var.instance_type : "t3.micro"
C.instance_type = terraform.workspace == "dr" ? "t3.micro" : var.instance_type
D.instance_type = var.instance_type == "dr" ? "t3.micro" : var.instance_type
AnswerC

The conditional operator evaluates the workspace name at plan time and selects the hard-coded type only in the dr workspace, falling back to the variable everywhere else. Both branches produce strings, so the result type is consistent and the single resource block behaves correctly across all workspaces.

Why this answer

The conditional operator compares the current workspace name to the target and chooses the hard-coded instance type only when they match, preserving the variable-driven value elsewhere. Both result branches are strings, so no type inconsistency arises and the single resource block adapts per workspace at plan time.

Exam trap

The trap here is comparing the wrong operand to the workspace name, which silently produces a condition that never matches instead of an obvious error.

241
MCQmedium

A platform team maintains a shared module in a private Terraform registry. They want to ensure that any configuration consuming this module always pulls the exact same version, even if a newer version is published. The module source is specified as "app.terraform.io/example-corp/vpc/aws". Which source argument change should be applied?

A.Use a Git-style ref in the source string, such as ?ref=1.2.0.
B.Add a version argument to the module block, e.g., version = "1.2.0".
C.Append ?version=latest to the source string to pin the latest version.
D.Set the environment variable TF_MODULE_VERSION to 1.2.0 before running terraform init.
AnswerB

For registry modules, Terraform uses the separate version argument to select a specific version. Setting version = "1.2.0" pins the module to that exact release, so even if newer versions are published, the consumer continues to use 1.2.0. This is the documented and supported way to achieve strict version pinning for registry-hosted modules.

Why this answer

Registry modules require a version argument within the module block to select a specific release. By setting version = "1.2.0", the consumer always retrieves that exact version, preventing unintended upgrades. Other methods such as query parameters or environment variables are not supported for registry modules and would not enforce version pinning.

This is the standard practice for reproducible deployments.

Exam trap

The trap here is assuming that version pinning for registry modules can be done via a query string or environment variable, when it actually requires a dedicated version argument.

242
MCQmedium

Your team uses HCP Terraform with a VCS-driven workflow. A pull request modifies a module that three separate workspaces consume from a shared private registry. You want reviewers to see the effect of the module change in each consuming workspace before the PR merges, without any state being written. What should you configure?

A.Create a run trigger on each consuming workspace so a plan is queued whenever the module repository receives a new commit to the default branch.
B.Configure a CLI-driven workflow on each workspace and have a developer run terraform plan locally against every workspace before approving the PR.
C.Add a policy set with a soft-mandatory sentinel policy that blocks applies until the module change is approved in the registry.
D.Enable speculative plans on the workspaces and attach the VCS repository so pull requests queue a plan-only run for each workspace.
AnswerD

Speculative plans run on pull requests without applying or writing state, so reviewers see the planned effect in each consuming workspace before merge. Attaching the repository to each workspace is what triggers those plan-only runs, giving the pre-merge visibility the scenario requires while keeping state untouched.

Why this answer

Speculative plans are the HCP Terraform mechanism that runs terraform plan on pull requests without applying or persisting state. Attaching the shared repository to each consuming workspace causes a plan-only run per workspace when the PR opens or updates, letting reviewers inspect the module's impact everywhere before merge. This satisfies the no-write requirement while keeping the VCS-driven workflow intact.

Exam trap

The trap here is assuming run triggers or policy checks provide pre-merge plan visibility, when only speculative plans on VCS-connected workspaces do.

243
MCQmedium

Your team publishes an internal Terraform module to a private registry. A consumer wants to pin the module to a specific version to avoid unexpected changes. The module source is `app.terraform.io/example-org/vpc/aws`. Which source argument correctly pins the module to version 2.3.0?

A.source = "git::https://app.terraform.io/example-org/vpc/aws.git?ref=v2.3.0"
B.source = "app.terraform.io/example-org/vpc/aws/2.3.0"
C.source = "app.terraform.io/example-org/vpc/aws" version = "2.3.0"
D.source = "app.terraform.io/example-org/vpc/aws?version=2.3.0"
AnswerC

For registry modules, the version argument is specified separately from the source string. Using an exact version constraint like "2.3.0" pins the module to that specific release, ensuring reproducible deployments. This is the documented syntax for private and public Terraform registry modules and is the recommended way to avoid unexpected changes.

Why this answer

Registry modules require the version argument to be set separately from the source string. Pinning to an exact version such as "2.3.0" ensures that the same module code is used across all runs, which is critical for reproducibility and preventing unintended changes. The source format for a registry module is hostname/namespace/name/provider without any version embedded.

Exam trap

The trap here is assuming that the version can be embedded in the source URL, as is done with Git refs, rather than provided as a separate argument.

244
MCQeasy

Your team uses HCP Terraform to manage AWS resources. You need to ensure that all workspaces in a project automatically inherit a set of AWS region and tagging variables. What is the most efficient way to achieve this?

A.Use a Terraform module to set the variables in each workspace.
B.Create a variable set and assign it to the project.
C.Define the variables in each workspace individually.
D.Store the variables in a version control system and reference them via a remote backend.
AnswerB

Variable sets allow you to define variables once and apply them to multiple workspaces or entire projects. Assigning a variable set to a project ensures all current and future workspaces in that project inherit the variables, reducing duplication and manual effort. This is the most efficient method for consistent AWS region and tagging variables.

Why this answer

Variable sets are designed to share variables across multiple workspaces. Assigning a variable set to a project ensures all workspaces in that project inherit the variables, including future ones. This is more efficient than per-workspace definitions and is the recommended practice for organization-wide or project-wide variables.

Exam trap

The trap here is confusing Terraform module variables with HCP Terraform workspace variables, or assuming that version control can directly populate workspace variables.

245
MCQmedium

You are using a module that depends on a specific provider version. Where should this constraint be defined?

A.In the 'required_providers' block within the module's 'terraform' block.
B.In the 'provider' block of the calling root module.
C.In the root module only.
D.In a shell environment variable.
AnswerA

Provider version constraints belong in the required_providers block inside the terraform block, which each module declares independently. Placing it there satisfies the stem's requirement, since module-level constraints are honoured during init alongside the root configuration.

Why this answer

Provider version constraints belong in the 'required_providers' block inside the module's 'terraform' block. This ensures the module declares its own compatibility requirements, which Terraform merges with the root module's constraints during initialization. It makes the module self-contained and portable.

Exam trap

The trap is confusing provider configuration ('provider' block) with provider version declaration ('required_providers'), leading candidates to place constraints in the wrong block.

How to eliminate wrong answers

Option B is wrong because the 'provider' block configures provider behavior (region, credentials) but does not declare version constraints. Option C is wrong because defining constraints only in the root module does not protect the module when reused elsewhere and violates module encapsulation. Option D is wrong because shell environment variables cannot express Terraform provider version constraints; they are used for credentials and feature flags, not dependency resolution.

246
MCQmedium

A team uses the AWS provider to manage resources in three accounts: development, staging, and production. The root module must create an `aws_iam_role` in the production account while all other resources remain in the default development account. The production account's provider configuration is already declared with `alias = "prod"`. Which change to the production `aws_iam_role` resource is required?

A.Declare a second aws provider block without an alias and place it after the default provider block.
B.Add `provider = aws.prod` to the resource block so it uses the aliased production provider configuration.
C.Set `region = "<prod-region>"` directly on the aws_iam_role resource block.
D.Move the aws_iam_role resource into a child module and pass the production provider via the module's providers argument.
AnswerB

A resource selects a non-default provider configuration through the provider meta-argument, written as the provider type followed by the alias, aws.prod. Without it, the resource would use the default configuration and be created in the development account. This is the standard mechanism for directing individual resources to aliased provider instances within the same module.

Why this answer

The provider meta-argument on a resource names the exact provider configuration to use, expressed as the provider type and alias, such as aws.prod. Because the production configuration is already declared with alias = "prod", adding provider = aws.prod to the aws_iam_role routes only that resource to the production account while everything else continues using the default development configuration.

Exam trap

The trap here is assuming that an aliased provider configuration is applied automatically based on proximity or declaration order rather than being explicitly referenced by each resource.

247
MCQmedium

A platform team maintains a shared child module that creates AWS resources in three different regions. The root module calls this child module three times, once per region. The child module currently declares only a default AWS provider configuration. What is the correct way to make each module instance use a distinct region without modifying the child module's resource blocks?

A.Duplicate the child module source into three copies, each with a hardcoded region in its `provider` block.
B.Add a `region` argument to each `module` block in the root module and reference `var.region` inside the child module.
C.Declare multiple aliased AWS provider configurations in the root module and pass the appropriate `providers` map to each `module` block.
D.Set the `AWS_REGION` environment variable to a different value before each `terraform apply` and rely on the child module to pick it up.
AnswerC

Provider configurations are inherited by child modules, and the `providers` meta-argument on a `module` block lets the root map each child's default AWS provider to a specific aliased root provider configuration. This changes the region per module instance without editing the child module's resources, which is exactly the intended mechanism for multi-region reuse of a shared module.

Why this answer

Passing aliased provider configurations into child modules through the `providers` meta-argument is the supported pattern for multi-region module reuse. The root module declares one AWS provider configuration per region with distinct aliases, then each `module` block maps the child's default AWS provider to the matching alias. The child module's resources automatically use the injected provider, so no resource-level changes are needed.

Exam trap

The trap here is assuming a `region` argument can be placed on a `module` block or that a child module can define its own provider block to control region independently.

248
MCQmedium

You want to use a module that is hosted in a private GitHub repository. Which authentication method should Terraform use to access it?

A.Use the same credentials that 'git clone' would use for that repository.
B.The module must be public for Terraform to access it.
C.Terraform requires a special 'git_token' variable in the module block.
D.Embed your GitHub password in the source URL.
AnswerA

Terraform's module downloader shells out to Git, so it inherits whatever credential helper or SSH key 'git clone' already uses. Supplying those same credentials satisfies the private-repository access constraint without configuring a separate Terraform-native authentication mechanism.

Why this answer

Terraform's module source supports Git URLs and delegates authentication to the underlying Git client. For a private GitHub repository, Terraform uses the same credentials that 'git clone' would use, such as SSH keys, a credential helper, or a personal access token configured in '~/.netrc' or Git config.

Exam trap

The trap is assuming Terraform has its own authentication mechanism for private modules; in reality, it relies entirely on the host's Git credential configuration.

How to eliminate wrong answers

Option B is wrong because private repositories are fully supported; Terraform does not require modules to be public. Option C is wrong because there is no 'git_token' variable in the module block; authentication is handled by Git, not Terraform-specific variables. Option D is wrong because embedding a password in the source URL is insecure, exposes credentials in state and logs, and is not the recommended mechanism.

249
Multi-Selecteasy

Which TWO of the following are true about the '.terraform' directory?

Select 2 answers
A.It contains the module source code downloaded from registries.
B.It should be committed to version control.
C.It contains the permanent state file.
D.It is created by 'terraform init'.
E.It is where custom provider binaries are compiled.
AnswersA, D

The `.terraform` directory caches modules fetched from registries into `.terraform/modules`, so remote module source code is available locally without re-downloading during each run. This satisfies the stem's requirement that downloaded module source code resides there, distinct from provider plugins stored under `.terraform/providers`.

Why this answer

Option A is correct because the .terraform directory is where terraform init caches downloaded modules, including module source code fetched from registries or other sources, under .terraform/modules. Option D is correct because terraform init is the command that initializes a working directory and creates/populates the .terraform directory with providers, modules, and backend metadata. Option B is not correct because .terraform is a local cache that should be excluded from version control, typically via .gitignore.

Option C is not correct because the state file (terraform.tfstate) is stored in the working directory or a configured remote backend, not permanently inside .terraform. Option E is not correct because provider binaries are downloaded as precompiled plugins into .terraform/providers, not compiled there.

Exam trap

The trap is confusing the .terraform directory with the state file location — candidates often think the state lives inside .terraform, but it is actually terraform.tfstate or a remote backend.

250
MCQhard

When should you use the 'for_each' meta-argument within a module?

A.To iterate over a list of variables inside a resource block.
B.To replace the 'count' meta-argument when you only need one instance.
C.To instantiate multiple copies of a module based on a map or set.
D.To speed up the execution of the provider.
AnswerC

for_each accepts a map or set and creates one module instance per element, keyed by that element. This satisfies the scenario's need to instantiate multiple module copies from a map or set rather than a fixed count.

Why this answer

The for_each meta-argument is used to instantiate multiple copies of a resource or module based on a map or set of values, giving each instance a stable key. When applied to a module block, it creates one module instance per element in the map or set, and each instance can be referenced by its key. This is the correct use case for for_each within a module.

Exam trap

The trap is conflating for_each with count — candidates often think for_each is just a list iterator, but the exam expects you to know it works on maps/sets and is used for stable, keyed module instantiation.

How to eliminate wrong answers

Option A is wrong because iterating over a list of variables inside a resource block is done with dynamic blocks or count, not for_each on a module; for_each on a module creates module instances, not internal iterations. Option B is wrong because for_each is not a replacement for count when you need one instance — count = 1 is simpler and for_each is specifically for multiple instances keyed by a map or set. Option D is wrong because for_each has no effect on provider execution speed; it is a structural meta-argument, not a performance tuning feature.

251
MCQeasy

You have a root module that calls a child module to create an AWS VPC. The child module defines an output named `vpc_id`. After running `terraform apply`, where can you find the value of `vpc_id`?

A.Only in the child module's source directory as a generated file named `outputs.tfstate`.
B.Automatically in the root module's outputs, because Terraform promotes all child module outputs to the root level.
C.In the AWS provider's response to the `terraform apply` command, which lists all outputs from all modules.
D.In the root module's state file, under the child module's outputs, and accessible via `terraform output` if the root module also declares an output that references it.
AnswerD

Child module outputs are stored in the state file under the module's path. To make them visible at the root level via `terraform output`, the root module must declare its own output that references the child module's output. This is the standard way to expose child module values to the user or to other parts of the configuration.

Why this answer

Child module outputs are stored in the state file under the module's address, but they are only displayed by `terraform output` if the root module declares an output that references them. This explicit referencing is how Terraform maintains a clear contract between modules and the root configuration, and it allows consumers to control what is exposed.

Exam trap

The trap here is assuming that child module outputs are automatically visible at the root level without an explicit output declaration in the root module.

252
MCQmedium

A platform team publishes an internal module that wraps the AWS provider. They want to ensure that consumers cannot use a provider version newer than 5.x but can use any 5.x release. The module's `required_providers` currently specifies `version = "~> 5.0"`. A consumer's root module specifies `version = "~> 4.0"` for the same provider. What happens when the consumer runs `terraform init`?

A.Terraform upgrades the provider to a version that satisfies both constraints automatically.
B.Terraform reports an error because no single provider version satisfies both constraints.
C.Terraform ignores the module's constraint and uses the root module's 4.x constraint.
D.Terraform selects version 4.x for the module and 5.x for the root, allowing both to coexist.
AnswerB

Terraform intersects all provider version constraints from the root module and every child module. The child requires `~> 5.0` and the root requires `~> 4.0`, which have no overlap. During `terraform init`, Terraform fails with an error indicating that no available version meets the combined constraints, and the user must align the constraints before proceeding.

Why this answer

Provider version constraints are combined across the entire configuration. When a child module and the root module specify non-overlapping constraints such as `~> 5.0` and `~> 4.0`, Terraform cannot select any version. `terraform init` fails with a clear error, forcing the team to reconcile the constraints. This ensures a consistent provider version across all modules.

Exam trap

The trap here is assuming Terraform can install different provider versions for different modules or that the root module's constraint always wins, when in fact constraints are intersected and must all be satisfied by one version.

253
MCQhard

You are designing a governance strategy for your HCP Terraform organization. You need to enforce that all AWS resources are tagged with a 'CostCenter' tag. The policy should block any run that creates resources without this tag, but you also want to allow a temporary exception for a migration project. Which combination of Sentinel enforcement level and policy set scoping should you use?

A.Use a hard-mandatory policy set scoped to all workspaces except the migration project, and a separate advisory policy set for the migration project.
B.Use a hard-mandatory policy set scoped to all workspaces, and create a separate policy set with an advisory policy for the migration project.
C.Use a soft-mandatory policy set scoped to all workspaces, and rely on developers to override when necessary.
D.Use a hard-mandatory policy set scoped only to the migration project, and an advisory policy set for all other workspaces.
AnswerA

Scoping the hard-mandatory policy set to exclude the migration project ensures that only the migration project is exempt, while all other workspaces are strictly enforced. The advisory policy set for the migration project logs violations without blocking, providing visibility. This achieves the required exception while maintaining governance elsewhere.

Why this answer

To block non-compliant runs everywhere except the migration project, the hard-mandatory policy set must be scoped to all workspaces except that project. The migration project can then have an advisory policy set to log violations without blocking. This combination enforces the tagging requirement broadly while allowing the migration project to proceed with visibility.

Exam trap

The trap here is assuming that adding a separate advisory policy set can override an existing hard-mandatory policy, or that scoping a hard-mandatory policy to all workspaces can be excepted by another policy set; instead, scoping must exclude the project.

254
MCQmedium

If a user omits the 'version' in 'required_providers', what version does Terraform use?

A.It will fail to initialize.
B.The latest available version.
C.Version 1.0.0.
D.The oldest available version.
AnswerB

Omitting the version constraint lets Terraform select the newest provider release available in the registry, satisfying the stem's scenario where no version is pinned. Terraform resolves this during initialisation, installing the latest matching version and recording it in the dependency lock file.

Why this answer

When the 'version' argument is omitted inside a required_providers block, Terraform does not pin the provider to any specific release and instead resolves to the newest version available in the configured registry (public Terraform Registry or private registry). This is why HashiCorp strongly recommends always pinning versions in production to avoid unexpected breaking changes.

Exam trap

The trap here is assuming Terraform requires an explicit version and will error out — candidates confuse 'recommended' with 'required', but version is optional and defaults to latest.

How to eliminate wrong answers

Option A is wrong because omitting 'version' is perfectly valid syntax — Terraform will still initialize and simply select the latest compatible release. Option C is wrong because Terraform does not default to 1.0.0; there is no implicit baseline version. Option D is wrong because Terraform selects the newest version, not the oldest, since it always prefers the most recent release that satisfies any constraints.

255
MCQmedium

A team wants to ensure that their Terraform configuration always uses a specific version of the AWS provider and that the version constraint is enforced across all modules. They add the following to the root module's terraform block: terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 4.0" } } } A child module declares the AWS provider without a version constraint. What happens when terraform init is run?

A.Terraform selects the newest AWS provider version that satisfies all constraints, including the root module's ~> 4.0.
B.Terraform uses the version from the child module's lock file if present, otherwise it uses the root module's constraint.
C.Terraform selects the latest AWS provider version that satisfies the child module's unconstrained requirement, ignoring the root module's constraint.
D.Terraform fails because the child module does not specify a version constraint.
AnswerA

Terraform collects version constraints from every module's required_providers block and selects the newest provider version that satisfies all of them. The child module's unconstrained declaration imposes no restriction, so the root module's ~> 4.0 constraint determines the upper and lower bounds for selection.

Why this answer

Version constraints from all modules are combined, and Terraform chooses the newest provider version that meets every constraint. Since the child module has no constraint, the root module's ~> 4.0 constraint is the only one, so Terraform picks the latest 4.x release. The lock file then records that selection for reproducibility.

Exam trap

The trap here is thinking that a child module's missing version constraint causes failure or overrides the root constraint, when actually it simply adds no restriction.

256
MCQeasy

A team is using Terraform to manage an aws_s3_bucket. They want Terraform to ignore any changes made to the bucket's tags outside of Terraform, but they still want Terraform to manage the bucket policy and versioning configuration. Which lifecycle configuration should they add?

A.Add lifecycle { ignore_changes = all } to the aws_s3_bucket resource.
B.Add lifecycle { create_before_destroy = true } to the aws_s3_bucket resource.
C.Add lifecycle { ignore_changes = [tags] } to the aws_s3_bucket resource.
D.Add lifecycle { prevent_destroy = true } to the aws_s3_bucket resource.
AnswerC

ignore_changes = [tags] tells Terraform to exclude the tags attribute from diff comparison, so out-of-band tag changes are not reverted. Other attributes such as policy and versioning remain managed, satisfying the requirement to keep controlling those settings while tolerating external tag edits.

Why this answer

ignore_changes = [tags] excludes only the tags attribute from diff evaluation, so external tag edits are tolerated while policy and versioning remain under Terraform management. The other lifecycle meta-arguments address deletion protection, full drift suppression, or replacement ordering, none of which match the stated requirement.

Exam trap

The trap here is reaching for ignore_changes = all or prevent_destroy when only a single attribute needs to be excluded from drift detection.

257
Multi-Selectmedium

What are common reasons to use multiple provider instances? (Select TWO)

Select 2 answers
A.Increasing performance of the Terraform CLI.
B.Installing multiple versions of the same provider.
C.Bypassing the need for a state file.
D.Using different credentials for different resources.
E.Deploying resources to multiple AWS regions.
AnswersD, E

Separate provider instances each carry their own authentication configuration, so distinct credential sets can be applied per instance. Resources referencing the appropriate alias then authenticate with the intended credentials, satisfying the need to isolate access across resources.

Why this answer

Option D is correct because multiple provider instances (created with the alias meta-argument) let you attach distinct credential sets to different resources, for example managing resources in separate AWS accounts or with different IAM roles within one configuration. Option E is correct because aliased provider instances are the standard way to target multiple AWS regions in a single configuration, such as provider "aws" { alias = "us_east" } and provider "aws" { alias = "eu_west" }, then referencing them per resource. Option A is not a reason for multiple provider instances, since Terraform CLI performance is governed by parallelism and graph execution, not by the number of provider configurations.

Option B is incorrect because provider versions are pinned in the required_providers block, not by instantiating multiple provider instances. Option C is incorrect because a state file is always required for tracking real infrastructure; provider aliases do not eliminate it.

258
MCQeasy

What command do you run to view the documentation for a module that has been published to a registry?

A.'terraform view-module'
B.'terraform show'
C.Check the registry website for the module page.
D.'terraform doc <module>'
AnswerC

Checking the registry website displays the module's published documentation, including inputs, outputs and usage examples, directly satisfying the requirement to view docs for a registry-published module. It avoids needing local installation or source access, since the registry page is the authoritative, versioned reference for that module.

Why this answer

Terraform has no CLI subcommand for browsing registry module documentation; the canonical way to read a published module's inputs, outputs, and examples is the registry website page for that module. The registry renders the README and auto-generates the input/output tables from the module's variables.tf and outputs.tf. So checking the registry website is the correct answer.

Exam trap

The trap is inventing a CLI command — candidates assume Terraform must have a 'doc' or 'view-module' subcommand like other tools, when documentation for registry modules lives only on the web.

How to eliminate wrong answers

Option A is wrong because 'terraform view-module' is not a real Terraform command — no such subcommand exists. Option B is wrong because 'terraform show' displays state or a saved plan file, not module documentation. Option D is wrong because 'terraform doc <module>' is not a valid command; Terraform has no built-in documentation browser for registry modules.

259
MCQmedium

Your organization uses HCP Terraform with the AWS provider. You need to ensure that all workspaces in the organization automatically use a specific set of AWS credentials for runs, without manually configuring variables in each workspace. The credentials must be available as environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY) and should be centrally managed. What should you do?

A.Create a Variable Set at the organization level containing the AWS credentials as environment variables, and apply it to all workspaces.
B.Configure the AWS provider to use the default credential chain, which will automatically retrieve credentials from HCP Terraform's environment.
C.Create a Sentinel policy that injects the AWS credentials into each run's environment before execution.
D.Store the AWS credentials in a Terraform Cloud API token and reference it in the provider configuration using var.token.
AnswerA

Variable Sets allow you to define variables once and apply them to multiple workspaces. Organization-level variable sets can be applied to all current and future workspaces, ensuring consistent AWS credentials. This centralizes management and avoids manual per-workspace configuration, directly meeting the requirement.

Why this answer

Organization-level Variable Sets are designed to share variables across multiple workspaces, including sensitive credentials. By defining AWS access keys as environment variables in a variable set and applying it to all workspaces, you ensure every run has the necessary credentials without manual intervention. This approach centralizes management and reduces configuration drift.

Exam trap

The trap here is confusing HCP Terraform's own authentication tokens with cloud provider credentials, or assuming that Sentinel can manage secrets, when in fact variable sets are the correct mechanism for shared credentials.

260
MCQeasy

You are writing a Terraform configuration that uses a dynamic block to generate multiple ingress rules within an aws_security_group resource. The dynamic block iterates over a variable named ingress_rules. Inside the content block, you need to reference the current rule. Which expression correctly accesses the current element?

A.ingress_rules.value
B.rule.value
C.each.value
D.dynamic.value
AnswerB

By default, a dynamic block uses the label of the block as the iterator name. Since the dynamic block is named rule, the iterator object is rule, and rule.value accesses the current element from the collection being iterated. This is the correct way to reference the current rule inside the content block.

Why this answer

Inside a dynamic block, the iterator object is named after the block's label unless an iterator argument is explicitly provided. With a dynamic block labeled rule, the current element is accessed via rule.value. This allows the content block to reference attributes of the current item.

The other options confuse the iterator with other meta-argument contexts or with the variable name.

Exam trap

The trap here is assuming that the iterator name matches the variable being iterated or that each.value is universally available, when dynamic blocks use a label-based iterator.

261
MCQhard

What happens if you set 'ignore_changes = all' in a resource lifecycle block?

A.It disables the prevent_destroy rule.
B.It ignores the resource existence entirely.
C.It causes Terraform to ignore all changes to the resource attributes.
D.It causes a syntax error.
AnswerC

ignore_changes = all tells Terraform to disregard every attribute difference between configuration and real infrastructure during planning, so no updates are proposed for that resource. This matches the stem's description of ignoring all attribute changes.

Why this answer

Setting ignore_changes = all in a lifecycle block tells Terraform to ignore all attribute changes for that resource, so drift or configuration changes to attributes will not trigger updates. Terraform still manages the resource's existence, creating or destroying it as needed, but it will not modify attributes. This is useful for resources managed partly outside Terraform.

Exam trap

The trap is thinking ignore_changes = all makes Terraform ignore the resource entirely — it only ignores attribute changes, not resource existence or lifecycle rules.

How to eliminate wrong answers

Option A is wrong because ignore_changes does not affect prevent_destroy; they are independent lifecycle settings. Option B is wrong because ignore_changes does not ignore the resource's existence — Terraform still creates and destroys the resource based on configuration presence. Option D is wrong because ignore_changes = all is valid syntax and does not cause an error.

262
MCQhard

You are managing an AWS S3 bucket with Terraform. The bucket has versioning enabled and contains critical data. You want to ensure that Terraform never destroys the bucket, even if someone runs terraform destroy. Which lifecycle meta-argument should you use?

A.prevent_destroy = true
B.ignore_changes = all
C.create_before_destroy = true
D.replace_triggered_by = [aws_s3_bucket_versioning.example]
AnswerA

prevent_destroy is a lifecycle meta-argument that prevents Terraform from destroying the resource. When set to true, any plan that includes destruction of the resource will fail, thus protecting the S3 bucket from accidental deletion. This directly meets the requirement to ensure the bucket is never destroyed.

Why this answer

The prevent_destroy meta-argument is specifically designed to protect resources from accidental deletion. When set to true, Terraform will produce an error if any plan attempts to destroy the resource, including during terraform destroy. This ensures the S3 bucket remains intact.

Other meta-arguments either ignore changes, alter replacement order, or trigger replacement, but none prevent destruction.

Exam trap

The trap here is thinking that ignore_changes = all will prevent destruction, when it actually only ignores attribute updates and does not block destroy operations.

263
MCQhard

You are developing a module that creates an AWS Lambda function. The module accepts a variable `environment` and must set the Lambda function's `environment` block with variables `LOG_LEVEL` and `STAGE`. The values for these should be derived from the `environment` variable. How should you define the variable and use it within the module?

A.Define variable "environment" { type = map(string) } and set environment { variables = var.environment }
B.Define variable "environment" { type = object({ log_level = string, stage = string }) } and set environment { variables = { LOG_LEVEL = var.environment.log_level, STAGE = var.environment.stage } }
C.Define variable "environment" { type = string } and inside the resource, set environment { variables = { LOG_LEVEL = var.environment, STAGE = var.environment } }
D.Define variable "environment" { type = string } and set environment { variables = { LOG_LEVEL = "debug", STAGE = var.environment } }
AnswerB

Using an object type allows the caller to pass a structured value containing both log_level and stage. This provides flexibility and clarity, ensuring that each environment variable gets the appropriate value. It also enables validation and documentation of the expected inputs. This is a robust way to handle multiple related settings derived from a single variable.

Why this answer

Using an object type for the environment variable allows the caller to specify both log_level and stage explicitly, ensuring each Lambda environment variable receives the correct value. This approach is type-safe, self-documenting, and flexible. It also enables validation rules if needed.

The other options either hardcode values, use overly permissive types, or incorrectly assign the same value to both settings.

Exam trap

The trap here is assuming that a simple string variable is sufficient when multiple distinct values need to be derived, leading to hardcoded or incorrect assignments.

264
Multi-Selecthard

A platform engineer is preparing a Terraform configuration that will run in an environment where the AWS provider must be pinned to a specific minor version, and the provider must be sourced from the public Terraform Registry. The engineer also wants to ensure that `terraform init` records the selected version and checksums for later verification. Which two actions should the engineer take? (Choose two.)

Select 2 answers
A.Add a `provider "aws"` block with a `version` argument set to the desired minor version.
B.Add a `required_providers` block in the `terraform` block specifying the AWS provider with a `source` of `hashicorp/aws` and a version constraint such as `~> 5.40.0`.
C.Commit the generated `.terraform.lock.hcl` file to version control after running `terraform init`.
D.Set the `TF_CLI_CONFIG_FILE` environment variable to point at a file that contains the provider version constraint.
E.Run `terraform providers lock -platform=linux_amd64` to generate checksums for all platforms.
AnswersB, C

Declaring the AWS provider in `required_providers` with an explicit `source` and a `~>` version constraint pins the provider to the specified minor version range and confirms the public registry as the source. This is the standard way to enforce version discipline and ensure the correct provider is selected during initialization.

Why this answer

Declaring the AWS provider in `required_providers` with a `~>` version constraint pins the minor version and confirms the public registry source, while committing the generated lock file preserves the exact version and checksums for reproducible, verified installs. Together these actions enforce version discipline and integrity across runs.

Exam trap

The trap here is assuming that a `version` argument inside a `provider` block still constrains provider versions, when modern Terraform requires version constraints in `required_providers`.

265
MCQhard

An `aws_instance` resource has `lifecycle { ignore_changes = [ami] }`. A security team updates the AMI ID in the Terraform configuration to a new hardened image. The instance is currently running an older AMI. What does Terraform plan for this resource during the next `terraform apply`?

A.Terraform reports no changes for the `ami` attribute and leaves the instance as-is.
B.Terraform replaces the instance with one built from the new AMI.
C.Terraform updates the instance in place to the new AMI without replacement.
D.Terraform fails the plan with an error because the AMI differs from state.
AnswerA

With ami listed in ignore_changes, Terraform ignores any difference between the configured AMI and the value recorded in state. The plan therefore shows no change for that attribute, and the running instance remains on the older AMI until the ignore_changes entry is removed and an apply is run.

Why this answer

The ignore_changes lifecycle argument filters out differences for the named attributes when Terraform compares configuration to state. When ami is ignored, a new AMI ID in configuration produces no planned change, so the instance is not replaced and no update is attempted. This is useful for attributes managed outside Terraform, but it also means security-driven AMI updates require removing the ignore entry first.

Exam trap

The trap here is expecting ignore_changes to still detect a difference and prompt a replacement, when it actually suppresses the difference and leaves the resource untouched.

266
MCQhard

Your organization has a Sentinel policy with enforcement level 'soft-mandatory' that checks for required tags on AWS resources. During a run, the policy fails because an EC2 instance is missing the 'Environment' tag. The workspace allows users with write access to override policies. What is the immediate outcome of the run?

A.The policy failure is logged as an advisory and the run continues automatically without any intervention.
B.The run is paused and a user with appropriate permissions can choose to override the policy and continue the apply.
C.The run fails immediately and cannot be overridden, requiring the configuration to be fixed and a new run to be queued.
D.The run is canceled and the workspace is locked until the policy is updated to pass.
AnswerB

A soft-mandatory policy failure pauses the run and allows a user with override permissions to bypass the policy. In this scenario, the user can override and proceed with the apply despite the missing tag. This is the designed behavior for soft-mandatory enforcement, balancing governance with flexibility for authorized users.

Why this answer

When a soft-mandatory Sentinel policy fails, the run pauses and users with override permissions can choose to bypass the policy and continue. This allows for exceptions while still enforcing governance. Hard-mandatory policies cannot be overridden, and advisory policies do not block.

The scenario specifies soft-mandatory, so the run is paused for possible override.

Exam trap

The trap here is confusing soft-mandatory with hard-mandatory or advisory enforcement levels; soft-mandatory pauses for override, while hard-mandatory fails and advisory only warns.

267
Multi-Selecthard

Which of the following are true regarding the .terraform.lock.hcl file? (Select TWO)

Select 2 answers
A.It is automatically generated by terraform init.
B.It is used to store the state file.
C.It can only be edited manually.
D.It stores secret credentials.
E.It should be committed to version control.
AnswersA, E

Terraform generates the dependency lock file during `terraform init`, recording the exact provider versions and hashes selected. This satisfies the stem's requirement for a true statement about the file's origin, since initialisation resolves and pins providers before any plan or apply runs.

Why this answer

Option A is correct because the .terraform.lock.hcl dependency lock file is automatically created and updated by the `terraform init` command when it installs providers, recording the exact provider versions and checksums selected. Option E is correct because HashiCorp recommends committing the .terraform.lock.hcl file to version control so that all team members and CI/CD pipelines use the same provider versions and verified checksums, ensuring reproducible runs. Option B is incorrect because Terraform state is stored in the state file (terraform.tfstate or a configured remote backend), not in the lock file.

Option C is incorrect because the lock file is normally generated and updated automatically by Terraform commands such as `terraform init` and `terraform providers lock`, though it can be edited manually if needed. Option D is incorrect because the lock file stores provider version constraints and cryptographic hashes, not secret credentials, which should never be placed in it.

Exam trap

The trap is assuming the lock file stores state or secrets — it stores provider version pins and checksums, and the exam tests whether you know it belongs in version control.

268
MCQhard

You have two resources, A and B. You want B to be replaced whenever A is updated. How do you configure B?

A.In resource B, set lifecycle { create_before_destroy = [resource_a] }
B.In resource A, set lifecycle { triggers = [resource_b] }
C.In resource B, set lifecycle { replace_triggered_by = [resource_a] }
D.In resource B, set depends_on = [resource_a]
AnswerC

Setting `replace_triggered_by` within resource B's lifecycle block forces Terraform to destroy and recreate B whenever the referenced resource A changes, satisfying the stem's requirement that B be replaced on A's update. This differs from `create_before_destroy`, which only alters replacement ordering, not the trigger itself.

Why this answer

The replace_triggered_by meta-argument in resource B's lifecycle block specifies that B should be replaced when resource A changes. This directly ties B's replacement to A's updates, ensuring B is recreated whenever A is updated.

Exam trap

The trap is confusing replace_triggered_by with depends_on or create_before_destroy. Candidates might think depends_on causes replacement, but it only orders operations. The exam tests whether you know the specific meta-argument for triggering replacement.

How to eliminate wrong answers

Option A is wrong because create_before_destroy does not accept a resource reference; it's a boolean. Option B is wrong because triggers is not a valid lifecycle argument for resources (it's for null_resource). Option D is wrong because depends_on only establishes a dependency order, not a replacement trigger.

269
MCQmedium

An engineer is authoring a reusable module that accepts variable "subnets", typed as map(object({ cidr_block = string, public = bool })). The module must create one aws_subnet per entry, attaching an aws_route_table_association only when that entry's public attribute is true. The association resource must not appear at all for private subnets, and its key must match the subnet's map key. Which approach satisfies these requirements with the least waste?

A.Iterate aws_subnet with for_each = var.subnets, and iterate aws_route_table_association with for_each = { for k, v in var.subnets : k => v if v.public }.
B.Use count = length(var.subnets) on both aws_subnet and aws_route_table_association, and set the association's count to the number of entries where public is true.
C.Iterate aws_subnet with count over keys(var.subnets), and use element() lookups inside aws_route_table_association with a dynamic "public" block to skip private entries.
D.Iterate aws_subnet with for_each = var.subnets, then give aws_route_table_association a single instance whose subnet_id is a list built from all public entries via a for expression.
AnswerA

Both resources use map keys as instance keys. The filtered for expression produces a new map containing only entries whose public attribute is true, so the association exists solely for public subnets and its key equals the subnet key, giving clean one-to-one correlation. Adding or removing a private entry never disturbs association addresses, and no separate index bookkeeping is required.

Why this answer

Filtering a map with a for expression that includes an if clause yields a new map containing only the entries that satisfy the predicate, and using that map with for_each gives each association the same stable key as its subnet. This avoids index drift, keeps resource addresses stable across changes, and naturally expresses the conditional existence of the association without count arithmetic.

Exam trap

The trap here is reaching for count plus element() index math to express conditional resource creation, when filtering the map and feeding it to for_each expresses both the condition and the key correlation directly.

270
MCQhard

Why would you use a 'locals' block within a module instead of passing everything through variables?

A.To reduce repetition and perform transformations on inputs.
B.To allow the user to override internal values easily.
C.To bypass input validation.
D.To store state data securely.
AnswerA

A locals block names intermediate expressions once, then reuses them throughout the module, cutting duplication and letting you transform variable inputs. It satisfies the goal of avoiding repeated inline expressions without expanding the module's public variable interface.

Why this answer

A 'locals' block lets you define named expressions that can be reused throughout the module, reducing repetition and enabling transformations (e.g., string concatenation, merging maps, computing tags) on input variables. Locals are computed once per plan and referenced as 'local.name'.

Exam trap

The trap is assuming locals are externally configurable like variables; in fact, locals are internal-only and cannot be overridden by module callers.

How to eliminate wrong answers

Option B is wrong because locals are internal to the module and cannot be overridden by callers; only variables are inputs. Option C is wrong because locals do not bypass input validation; variable validation blocks still run on inputs before locals are evaluated. Option D is wrong because locals are stored in memory during plan/apply and are not a secure storage mechanism; sensitive data should use variables marked 'sensitive' or a secrets manager.

271
MCQmedium

You are creating a custom provider. What is the standard language used to write Terraform providers?

A.Python
B.Ruby
C.HCL
D.Go
AnswerD

Terraform providers are written in Go, using the Terraform Plugin SDK or Plugin Framework. This satisfies the stem's requirement for the standard language: HashiCorp builds and distributes all official providers in Go, and the plugin protocol's libraries are Go-first, making it the only supported choice for custom provider development.

Why this answer

Terraform providers are written in Go, using the Terraform Plugin SDK (or the newer Plugin Framework). Go is the standard because Terraform itself is written in Go, and the plugin architecture relies on Go's support for building shared libraries and gRPC-based plugins. Providers implement CRUD operations for resources and data sources by conforming to the Terraform plugin protocol, which is defined and maintained in Go.

Exam trap

The trap here is confusing the language used to write Terraform configurations (HCL) with the language used to implement Terraform providers (Go), or assuming that because Terraform supports multiple languages via CDKTF, providers can be written in any language.

How to eliminate wrong answers

Option A is wrong because Python is not used to write Terraform providers; while Python can be used with CDK for Terraform (CDKTF) to synthesize Terraform configurations, that is a different abstraction and does not create providers. Option B is wrong because Ruby is not a supported language for provider development; no official Terraform plugin SDK exists for Ruby. Option C is wrong because HCL (HashiCorp Configuration Language) is the declarative language used to write Terraform configurations, not the imperative code that implements provider logic.

272
MCQmedium

What is the impact of using 'sensitive = true' in a module output?

A.It disables the ability to use that output in other modules.
B.It encrypts the data in the state file.
C.It automatically rotates the sensitive credentials.
D.It prevents the value from being printed in the CLI output.
AnswerD

Marking an output sensitive makes Terraform redact its value, displaying "(sensitive value)" in plan and apply output rather than the plaintext. It satisfies the constraint of hiding secrets from CLI display, though the value still exists in state.

Why this answer

Marking an output as 'sensitive = true' tells Terraform to redact the value from CLI output, including plan and apply logs, so credentials are not displayed on screen. The value is still stored in state and can still be consumed by other modules or resources. It is a display-level protection, not an encryption or access-control mechanism.

Exam trap

The trap here is confusing 'sensitive = true' with state encryption or access control — candidates often assume it encrypts the value, when it only redacts CLI display.

How to eliminate wrong answers

Option A is wrong because sensitive outputs can still be referenced by other modules; sensitivity only affects display, not usability. Option B is wrong because 'sensitive = true' does not encrypt state — state encryption requires backend-level encryption (e.g., S3 SSE, Terraform Cloud). Option C is wrong because Terraform does not rotate credentials; rotation is handled by external systems like Vault or AWS Secrets Manager.

273
Multi-Selectmedium

You are designing a reusable Terraform module that will be consumed by multiple teams. To ensure the module is maintainable and follows best practices, which TWO of the following should you implement? (Choose two.)

Select 2 answers
A.Use a consistent naming convention and tag all resources with a module identifier.
B.Hardcode the AWS region and account ID to simplify configuration for consumers.
C.Expose all internal resources as outputs so consumers can reference them directly.
D.Include a `terraform.tfstate` file in the module repository to track state.
E.Provide a README that documents the module's purpose, inputs, outputs, and usage examples.
AnswersA, E

Consistent naming and tagging improve resource organization, cost allocation, and troubleshooting. Tagging with a module identifier helps identify which module created which resources, especially in shared AWS accounts. This practice aids in auditing and automation. It is widely recommended for reusable modules to maintain clarity and operational efficiency.

Why this answer

The correct practices are providing thorough documentation and using consistent naming and tagging. Documentation ensures consumers can use the module effectively, while naming and tagging aid in management and identification. These practices enhance maintainability, reduce errors, and support operational excellence in reusable modules.

Exam trap

The trap here is thinking that exposing all resources as outputs is helpful, when it actually increases coupling and hinders module evolution.

274
Multi-Selecthard

Which TWO of the following are true regarding OPA/Sentinel policies?

Select 2 answers
A.They run after the apply phase
B.They can only be used with AWS
C.They can be set to advisory mode
D.They can be scoped to specific workspaces
E.They replace the need for IAM
AnswersC, D

Advisory mode lets a policy report violations without failing the run, so teams can trial governance rules before enforcing them. This satisfies the requirement that policies need not block, distinguishing advisory from soft-mandatory and hard-mandatory enforcement levels.

Why this answer

Option C is correct because both OPA and Sentinel policies support an advisory (soft-mandatory) enforcement mode, which reports policy violations without blocking the run, unlike hard-mandatory mode that fails the run. Option D is correct because policies can be scoped to specific workspaces, allowing different policy sets to apply only to designated workspaces rather than globally. Option A is incorrect because OPA/Sentinel policies are evaluated during the plan phase (pre-apply), not after apply.

Option B is incorrect because these policies are cloud-agnostic and work with any provider, not just AWS. Option E is incorrect because policies govern Terraform configuration compliance and do not replace IAM, which controls authentication and authorization to cloud resources.

Exam trap

The trap is assuming policies run post-apply or are cloud-specific — candidates conflate policy-as-code with cloud IAM or with runtime enforcement, when in fact Sentinel/OPA gate the plan-to-apply transition and are provider-neutral.

275
MCQmedium

When a module is updated, how do you ensure that all environments using this module get the update?

A.The module updates automatically on every 'apply'.
B.Run 'terraform init -upgrade' to fetch the latest version allowed by the constraints.
C.Delete the state file and re-run apply.
D.Restart the Terraform CLI process.
AnswerB

terraform init -upgrade re-resolves module version constraints and downloads the newest release each constraint permits, refreshing the cached module. This propagates the update to every environment that runs it, satisfying the requirement that all consumers receive the new version.

Why this answer

Terraform modules sourced from a registry or VCS are cached locally after the first 'terraform init'. To pull a newer version that satisfies the version constraint in the module block, you must run 'terraform init -upgrade', which re-resolves the version and downloads the latest allowed release. Without this flag, Terraform reuses the cached module even if a newer version exists, so environments won't pick up the update.

Exam trap

The trap here is assuming that Terraform automatically fetches the latest module version on every apply or that deleting the state file forces a refresh, when in reality module updates require an explicit 'terraform init -upgrade' to bypass the local cache.

How to eliminate wrong answers

Option A is wrong because Terraform does not automatically re-fetch module versions on every 'apply'; it uses the cached module from the last 'init' unless explicitly told to upgrade. Option C is wrong because deleting the state file does not affect module source code retrieval and would destroy tracking of existing resources, causing Terraform to attempt to recreate everything. Option D is wrong because restarting the CLI has no effect on module caching or version resolution; the cache persists on disk and the same version is used.

276
MCQhard

Why might someone use 'prevent_destroy = true' on a database resource while allowing it on smaller web server instances?

A.To increase the speed of the destroy process.
B.To protect critical data from accidental deletion.
C.To ensure create_before_destroy works.
D.To satisfy the AWS provider requirements.
AnswerB

Databases hold irreplaceable state, so prevent_destroy blocks the destroy plan step before Terraform can issue the deletion API call, guarding against accidental loss. Web servers are stateless and rebuildable, so the same guard would only obstruct routine replacement, making the protection disproportionate there.

Why this answer

prevent_destroy = true is used to protect resources whose loss would be catastrophic or unrecoverable, such as databases containing critical data. Web server instances are typically stateless and easily recreated, so the protection is unnecessary there — making option B correct.

Exam trap

The trap is conflating prevent_destroy with create_before_destroy or assuming it applies universally — the exam tests whether you understand it is a targeted safety control for high-value resources.

How to eliminate wrong answers

Option A is wrong because prevent_destroy does not speed up destruction; it actually blocks it entirely for the protected resource. Option C is wrong because create_before_destroy is a separate lifecycle argument that controls replacement ordering, not destruction protection. Option D is wrong because prevent_destroy is a Terraform core feature, not an AWS provider requirement — no provider mandates its use.

277
Multi-Selecthard

Your organization uses HCP Terraform with a private module registry. A platform team publishes a module that provisions an Amazon RDS instance, and several application teams consume it across different workspaces. The platform team must release a backwards-incompatible change to the module's `engine_version` variable, but they do not want existing consumers to break on their next run. Which two actions should the platform team take to safely version and publish this change? (Choose two.)

Select 2 answers
A.Update the module's version constraint in each consuming workspace to reference the new major version.
B.Edit the `engine_version` variable in place and re-tag the existing module version so all consumers receive the update automatically.
C.Delete the previous major version from the registry so consumers are forced to upgrade on their next plan.
D.Publish the change as a new major version of the module in the private registry, following semantic versioning.
E.Change the module source address in the consuming workspaces to point at the platform team's VCS branch directly.
AnswersA, D

After the new major version is published, each consumer must opt in by updating its `version` constraint in the `module` block. This is the deliberate adoption step that prevents accidental breakage. Without changing the constraint, consumers remain on the old major line, so this action is required to move them forward on their own schedule.

Why this answer

A breaking change to a shared module must be released as a new major version so existing consumers are unaffected, and each consumer must explicitly raise its version constraint to adopt it. Together these steps isolate the incompatible change, preserve reproducibility for teams not yet ready to migrate, and keep adoption a deliberate per-workspace decision.

Exam trap

The trap here is assuming that editing a module in place and re-tagging it will propagate updates safely to all consumers.

278
MCQmedium

You have a list of objects representing AWS tags. You need to transform this list into a map for use with a for_each argument. Which function should you use?

A.tolist()
B.flatten()
C.merge()
D.for expression
AnswerD

A for expression iterates the tag list and builds a map keyed by each element, which for_each requires. It satisfies the transformation constraint directly, unlike a for_each meta-argument or lookup, since it produces the map value rather than consuming one.

Why this answer

A for expression is the correct tool to transform a list of objects into a map, using the syntax { for item in list : key => value }, which is exactly what for_each requires (a map or set of strings). Functions like merge() combine existing maps but cannot reshape a list of objects into a map keyed by an attribute. The for expression is the idiomatic Terraform construct for this transformation.

Exam trap

The trap is reaching for a familiar function like merge() or flatten() to reshape data; candidates forget that only a for expression can construct a new map from a list of objects, which is the specific transformation for_each demands.

How to eliminate wrong answers

Option A is wrong because tolist() converts a set or tuple to a list — it does not produce a map and does not restructure objects into key/value pairs. Option B is wrong because flatten() collapses nested lists into a single flat list, which is the opposite of what's needed to build a map. Option C is wrong because merge() combines two or more existing maps into one; it cannot derive a map from a list of objects because it requires maps as inputs.

Page 3

Page 4 of 4

All pages