CertSafari

    Free HashiCorp Terraform Associate 004 Sample Questions

    35 free sample questions from our bank of 333+, covering every exam domain, with answers and detailed explanations. Updated October 2026.

    Domain 1: Infrastructure as Code (IaC) with Terraform

    Subdomain 1.1: Explain what IaC is

    1.An organization runs workloads across AWS, Azure, and an on-premises VMware cluster, and wants to manage all of them from one consistent workflow. Which characteristic of Terraform makes this possible?

    1. A.Terraform is provider-agnostic, using plugins that let the same core workflow manage resources across many different platforms.
    2. B.Terraform requires a separate installation and configuration language for each cloud platform it needs to provision resources on.
    3. C.Terraform only manages resources hosted in public cloud accounts and cannot interact with on-premises virtualization platforms.
    4. D.Terraform converts each provider's resources into a single shared API that replaces the need for individual provider services.
    Show answer & explanation

    Correct answer: A — Terraform is provider-agnostic, using plugins that let the same core workflow manage resources across many different platforms.

    • A. This is correct because Terraform's provider plugin model lets one consistent workflow and language target AWS, Azure, on-premises VMware, and many other platforms at once.
    • B. Terraform uses a single core workflow and language across providers; it does not require a separate installation or language per platform, which would defeat the purpose of a unified tool.
    • C. Terraform is not limited to public cloud; providers exist for on-premises virtualization platforms like VMware, which is exactly why it fits this multi-environment scenario.
    • D. Terraform does not merge providers into one shared API; each provider still exposes its own resources and behavior, while Terraform standardizes how you configure and apply them.

    Subdomain 1.2: Describe the advantages of IaC patterns

    2.A company runs part of its workloads in AWS and part in an on-premises VMware environment, and wants a single tool and workflow to provision both. Which capability of Terraform makes this possible?

    1. A.Terraform's provider ecosystem lets a single configuration language target AWS, VMware, and other platforms through their respective APIs.
    2. B.Terraform automatically migrates on-premises VMware workloads into AWS so that only one platform needs to be managed going forward.
    3. C.Terraform requires a separate proprietary agent installed on every on-premises server before any cloud resource can be provisioned.
    4. D.Terraform only supports public cloud providers, so the on-premises VMware resources must be managed with a separate tool.
    Show answer & explanation

    Correct answer: A — Terraform's provider ecosystem lets a single configuration language target AWS, VMware, and other platforms through their respective APIs.

    • A. This is correct because Terraform's provider plugins translate the same HashiCorp Configuration Language into calls against each platform's API, letting AWS and VMware resources be managed from one workflow.
    • B. This is incorrect because Terraform provisions and manages infrastructure as described in configuration; it does not automatically migrate workloads between platforms.
    • C. This is incorrect because on-premises resources are managed through a provider that talks to the platform's existing API or SDK, not through a proprietary agent installed on every server.
    • D. This is incorrect because the provider model explicitly extends to on-premises and hybrid platforms such as VMware, not just public cloud vendors.

    Subdomain 1.3: Explain how Terraform manages multi-cloud, hybrid cloud, and service-agnostic workflows

    3.A retailer runs its storefront on AWS, its analytics pipeline on Google Cloud, and its point-of-sale servers on on-premises VMware hosts. The platform team wants to provision and change resources on all three with one tool and one review process. What should they configure in Terraform to achieve this?

    1. A.Declare the aws, google, and vsphere providers in the same configuration so each resource block is managed through its matching platform API.
    2. B.Install only the aws provider and route the Google Cloud and VMware resources through AWS Direct Connect so Terraform treats them as AWS-native.
    3. C.Write three separate Terraform configurations with three separate state backends and coordinate applies manually outside of Terraform's workflow.
    4. D.Export the AWS resources to CloudFormation templates and rely on that tool for the Google Cloud and VMware resources instead.
    Show answer & explanation

    Correct answer: A — Declare the aws, google, and vsphere providers in the same configuration so each resource block is managed through its matching platform API.

    • A. Declaring the aws, google, and vsphere providers together lets one configuration reference resources on all three platforms, with each provider translating its own resource blocks into the right API calls while the team still runs a single plan and apply.
    • B. AWS Direct Connect is a network link between AWS and another data center; it does not make Google Cloud or VMware resources addressable through the aws provider, so Terraform still could not manage them without their own providers.
    • C. Splitting into three configurations with separate state and manual coordination reintroduces exactly the fragmented, inconsistent process Terraform's multi-provider workflow is meant to remove, and it loses the single review and apply step the team wants.
    • D. CloudFormation only manages AWS resources and has no way to provision Google Cloud or VMware infrastructure, so exporting to it would not give the team a single tool covering all three platforms.

    Domain 2: Terraform fundamentals

    Subdomain 2.2: Describe how Terraform uses providers

    4.During `terraform init`, which of the following actions does Terraform take regarding providers? (Select all that apply.)(Select 3)

    1. A.Terraform reads the `required_providers` block to determine which provider plugins the configuration needs and downloads them from the resolved source address.
    2. B.Terraform records the exact installed provider versions and their cryptographic hashes into the `.terraform.lock.hcl` file for future runs.
    3. C.Terraform compiles each provider's source code locally on the machine, since providers are distributed as source files rather than prebuilt binaries.
    4. D.Terraform automatically rewrites the `version` constraints inside `required_providers` to match whatever version it ends up installing.
    5. E.Terraform caches downloaded provider plugins in a local directory so that later `init` runs in the same environment can skip re-downloading them.
    Show answer & explanation

    Correct answers: A, B, E — Terraform reads the `required_providers` block to determine which provider plugins the configuration needs and downloads them from the resolved source address.; Terraform records the exact installed provider versions and their cryptographic hashes into the `.terraform.lock.hcl` file for future runs.; Terraform caches downloaded provider plugins in a local directory so that later `init` runs in the same environment can skip re-downloading them.

    • A. This is correct because provider discovery and installation during `init` starts from the source addresses declared in `required_providers`, which Terraform resolves to locate the matching plugin release.
    • B. This is correct because part of `init`'s provider handling is updating the dependency lock file with the specific versions and hashes that were installed, so future runs can reproduce the same install.
    • C. This is incorrect because providers are distributed as prebuilt binaries for each platform, not as source code that Terraform compiles; `init` downloads a ready-to-run plugin binary.
    • D. This is incorrect because `init` never edits the configuration's `required_providers` version constraints; the constraints are author-controlled, and installed versions are only recorded separately in the lock file.
    • E. This is correct because Terraform maintains a local plugin cache so that provider binaries already downloaded for a given platform can be reused instead of being fetched again on subsequent `init` runs.

    Subdomain 2.1: Install and version Terraform providers

    5.Which of the following statements about the Terraform dependency lock file (`.terraform.lock.hcl`) are accurate?(Select 3)

    1. A.It records the exact provider version selected together with cryptographic hashes used to verify the downloaded plugin package.
    2. B.Terraform generates or updates it automatically as part of running `terraform init`, without any separate manual command.
    3. C.Teams should add it to `.gitignore` because it is only a local cache file that never needs to be shared with collaborators.
    4. D.It replaces the `required_providers` block entirely, so version constraints no longer need to be written in configuration files.
    5. E.HCP Terraform and Terraform Enterprise runs also honor the provider versions recorded in this file when it is present in the workspace.
    6. F.Only the root module's lock file is ever created; provider requirements declared inside child modules cannot affect its contents.
    Show answer & explanation

    Correct answers: A, B, E — It records the exact provider version selected together with cryptographic hashes used to verify the downloaded plugin package.; Terraform generates or updates it automatically as part of running `terraform init`, without any separate manual command.; HCP Terraform and Terraform Enterprise runs also honor the provider versions recorded in this file when it is present in the workspace.

    • A. This is correct. Each provider entry in the file lists the resolved version plus package hashes, letting Terraform verify that a later download matches what was originally installed.
    • B. This is correct. Terraform writes or refreshes this file as a normal part of initialization, with no separate command needed to create or maintain it under ordinary use.
    • C. HashiCorp recommends committing this file to version control precisely so collaborators and CI pipelines resolve identical provider versions; ignoring it defeats that reproducibility guarantee.
    • D. The lock file only records the outcome of a version resolution; the `required_providers` block still must exist in configuration to declare sources and constraints in the first place.
    • E. This is correct. HCP Terraform and Terraform Enterprise runs read this file the same way the CLI does, so remote runs install the same locked provider versions as local ones.
    • F. Provider requirements declared by any child module in the configuration are merged into version resolution, so their constraints absolutely can influence which versions end up recorded in the lock file.

    Subdomain 2.3: Write Terraform configuration using multiple providers

    6.A team manages EC2 instances in two AWS regions from one configuration. They define a default `aws` provider block for `us-east-1` and a second block with `alias = "west"` for `us-west-2`. Which line correctly attaches an `aws_instance` resource to the `us-west-2` configuration?

    1. A.provider = aws.west
    2. B.alias = aws.west
    3. C.provider = "aws.west"
    4. D.region = aws.west
    Show answer & explanation

    Correct answer: A — provider = aws.west

    • A. The `provider` meta-argument on a resource takes an unquoted `<PROVIDER_NAME>.<ALIAS>` reference, so `aws.west` correctly points the resource at the aliased configuration.
    • B. `alias` is only valid inside a `provider` block to name a configuration; it is not a meta-argument that resources use to select a provider.
    • C. The `provider` meta-argument must be an unquoted reference like `aws.west`, not a quoted string; Terraform would treat this as invalid syntax.
    • D. `region` is an argument specific to the AWS provider's own configuration, not the meta-argument Terraform uses to bind a resource to a particular provider configuration.

    Subdomain 2.4: Explain how Terraform uses and manages state

    7.Before making a change, an engineer wants to view the full set of attribute values Terraform currently has recorded for a specific `aws_db_instance` resource, without modifying the state file. Which command should they run?

    1. A.`terraform state show aws_db_instance.main` to print the resource's current recorded attribute values from state.
    2. B.`terraform state list` to print the full set of resource addresses that Terraform is currently tracking, one per line.
    3. C.`terraform refresh` to reconcile state with real infrastructure and print a full diff of every attribute.
    4. D.`terraform plan -target=aws_db_instance.main` to generate an execution plan scoped to just that resource's changes.
    Show answer & explanation

    Correct answer: A — `terraform state show aws_db_instance.main` to print the resource's current recorded attribute values from state.

    • A. `terraform state show` is built for exactly this: it prints the full set of attribute values recorded in state for one named resource, without changing the state file. It is read-only, matching the engineer's goal.
    • B. `terraform state list` only prints resource addresses, one per line, with no attribute detail. It would tell the engineer the resource exists but not show any of its recorded values.
    • C. `terraform refresh` updates the state file to match real infrastructure and does not, by itself, print a readable attribute listing for one resource. It also modifies state rather than just displaying it.
    • D. `terraform plan -target` shows proposed changes for that resource, not the attribute values currently recorded in state. If there are no pending changes, the plan output would show little of what the engineer wants to inspect.

    Domain 3: Core Terraform workflow

    Subdomain 3.3: Validate a Terraform configuration

    8.A developer clones a Terraform module repository for the first time and immediately runs `terraform validate` in the module directory, before running any other Terraform command. What happens?

    1. A.Validation fails with an error because the directory has not been initialized and provider plugins are not yet installed
    2. B.Validation succeeds because it only parses configuration syntax and does not depend on provider plugins being installed locally
    3. C.Validation succeeds but silently skips all resource blocks that reference providers which have not yet been configured
    4. D.Validation fails because Terraform attempts to authenticate with the cloud provider and the developer has not supplied credentials
    Show answer & explanation

    Correct answer: A — Validation fails with an error because the directory has not been initialized and provider plugins are not yet installed

    • A. This is correct: an uninitialized working directory has no downloaded provider plugins or installed modules, and this command needs those to resolve schemas for resource and data blocks. It fails with a clear error pointing at the missing initialization.
    • B. This overstates independence from providers: while the command is a local, static check, it still needs installed provider plugins to know each resource type's expected arguments. Without initialization, that schema information is missing.
    • C. Silently skipping unconfigured blocks is not the behavior of this command; it does not selectively ignore parts of the configuration. An uninitialized directory produces an explicit error rather than a partial, quiet pass.
    • D. This command never attempts to authenticate with a cloud provider, so a missing credential is not the cause of any failure here. The actual failure comes from the missing provider plugins and uninitialized module cache.

    Subdomain 3.2: Initialize a Terraform working directory

    9.Which of the following `terraform init` flags directly affect provider or module installation behavior? (Select all that apply.)(Select 3)

    1. A.`-upgrade`
    2. B.`-lockfile=readonly`
    3. C.`-get=false`
    4. D.`-lock-timeout=30s`
    5. E.`-no-color`
    6. F.`-chdir=DIR`
    Show answer & explanation

    Correct answers: A, B, C — `-upgrade`; `-lockfile=readonly`; `-get=false`

    • A. This is correct. It causes Terraform to disregard existing lock file selections and install the newest provider and module versions permitted by the configured constraints.
    • B. This is correct. It makes Terraform verify installed provider packages against the existing lock file without writing any new selections or checksums to it.
    • C. This is correct. It tells Terraform to skip downloading and installing referenced child modules during initialization.
    • D. This is incorrect. It controls how long Terraform waits to acquire a state lock during operations that touch state, which is unrelated to installing providers or modules.
    • E. This is incorrect. It only suppresses colored output formatting in the terminal and has no effect on what gets downloaded or installed.
    • F. This is incorrect. It is a global CLI option that changes the working directory Terraform operates in before any command runs, rather than a flag that changes what init installs.

    Subdomain 3.4: Generate and review an execution plan for Terraform

    10.A managed instance is reporting as degraded, and its configuration hasn't changed, so a normal `terraform plan` shows no differences. The team wants Terraform to plan destroying and recreating that specific instance on the next apply. Which flag accomplishes this?

    1. A.`-replace=ADDRESS` to mark the specific resource instance for forced replacement in the generated plan
    2. B.`-refresh-only` to update state so the degraded status is reflected before any replacement is considered
    3. C.`-target=ADDRESS` to narrow the plan to that resource so Terraform reevaluates and rebuilds it automatically
    4. D.`-var 'force_recreate=true'` to pass a variable that most provider resource types read to trigger recreation
    Show answer & explanation

    Correct answer: A — `-replace=ADDRESS` to mark the specific resource instance for forced replacement in the generated plan

    • A. This is correct: `-replace` tells Terraform to plan a forced replacement of the named resource instance even when its configuration is unchanged, which is exactly the escape hatch for degraded resources.
    • B. `-refresh-only` reconciles state with the real object's current attributes but has no mechanism for forcing a destroy-and-recreate of a resource that matches its configuration.
    • C. `-target` only restricts which resources are included in the plan; it does not, by itself, force replacement of a resource whose configuration still matches its current state.
    • D. There is no built-in `force_recreate` input variable that providers read to trigger recreation; replacement forcing is a plan-time flag, not a variable convention providers implement.

    Subdomain 3.7: Apply formatting and style adjustments to a configuration

    11.An engineer wants to check the formatting of a single HCL snippet piped from another tool, without having it be a file on disk. Which target value tells `terraform fmt` to read the configuration from standard input?

    1. A.`-` (a single hyphen)
    2. B.`.` (the current directory)
    3. C.`--stdin`
    4. D.An empty string with no target supplied
    Show answer & explanation

    Correct answer: A — `-` (a single hyphen)

    • A. Passing a single hyphen as the target tells `fmt` to read the configuration content from standard input instead of scanning a directory, which matches the documented target syntax.
    • B. A dot targets the current directory on disk and causes `fmt` to scan files there; it does not redirect input from stdin.
    • C. There is no `--stdin` flag defined for `terraform fmt`; the documented mechanism for piped input is the hyphen target, not a named flag.
    • D. Omitting the target entirely makes `fmt` default to scanning the current directory for `.tf` files, not reading from standard input.

    Subdomain 3.6: Destroy Terraform-managed infrastructure

    12.The team decides the production database from the previous scenario genuinely needs to be decommissioned. What is the correct sequence to destroy it?

    1. A.Remove the `prevent_destroy = true` line from the resource's lifecycle block, apply that configuration change, then run `terraform destroy` or a targeted apply.
    2. B.Run `terraform destroy -force` to override the lifecycle protection in a single step without touching the resource configuration.
    3. C.Delete the resource block from the configuration file, then manually edit the state file to remove the matching entry before running any command.
    4. D.Set `prevent_destroy = false` and immediately run `terraform plan -destroy`, since a plan-only command is exempt from the protection either way.
    Show answer & explanation

    Correct answer: A — Remove the `prevent_destroy = true` line from the resource's lifecycle block, apply that configuration change, then run `terraform destroy` or a targeted apply.

    • A. This is correct because removing the protective lifecycle line and applying that change is the documented way to lift the guard, after which a normal destroy or targeted apply can remove the resource.
    • B. This is incorrect because no such flag exists for overriding this specific protection in one step; the configuration itself has to change before the resource can be destroyed.
    • C. This is incorrect because manually editing the state file is unnecessary and risky; once the resource block is removed from configuration, a normal plan and apply reconcile the state without hand-editing it.
    • D. This is incorrect because running a plan does not itself change anything, so the protection is still enforced at apply time; the reasoning that a plan-only command is inherently exempt misstates why the workflow succeeds.

    Subdomain 3.5: Apply changes to infrastructure with Terraform

    13.During `terraform apply`, the provider API returns an error partway through creating one of several resources in the plan. What does Terraform do with the resources that were already successfully created before the error?

    1. A.It records the successfully created resources in the state file and leaves them in place, since Terraform does not automatically roll back a partially completed apply.
    2. B.It automatically destroys the successfully created resources in reverse dependency order to restore the infrastructure to its pre-apply condition before exiting with the error.
    3. C.It discards the state file entirely so that no record of the partial apply remains, and the next terraform apply starts from empty state and recreates every resource.
    4. D.It retries only the resources created before the error, in a loop, until the entire apply either fully succeeds or the provider's configured retry limit is reached.
    Show answer & explanation

    Correct answer: A — It records the successfully created resources in the state file and leaves them in place, since Terraform does not automatically roll back a partially completed apply.

    • A. Correct. When a provider error interrupts an apply, Terraform records the resources it already created in the state file, releases the state lock, and exits with the error. Terraform has no automatic rollback, so those resources stay in place and the infrastructure may be left partially applied until the operator fixes the problem and runs apply again.
    • B. Incorrect. Terraform has no automatic rollback mechanism for a failed apply. Resources that were created successfully stay as they are, and Terraform does not destroy them in reverse dependency order or otherwise restore the pre-apply condition. Removing them requires an explicit action such as `terraform destroy`.
    • C. Incorrect. Terraform writes the partial results to state rather than discarding the state file. If it discarded the state, Terraform would lose track of infrastructure that really exists. The next apply would then try to recreate those resources, causing duplicate-resource errors and drift. The next apply actually compares the configuration to the saved state and creates only what is missing.
    • D. Incorrect. Terraform does not loop over the already-created resources and retry them until the apply succeeds. Those resources are already created and recorded in state, so there is nothing to retry for them. Some providers retry certain transient API calls internally, but Terraform core does not do this. After a failure, the operator must diagnose the error and re-run `terraform apply`.

    Domain 4: Terraform configuration

    Subdomain 4.2: Refer to resource attributes and create cross-resource references

    14.A configuration defines `resource "aws_s3_bucket" "logs" { ... }` and `resource "aws_s3_bucket_policy" "logs_policy" { bucket = aws_s3_bucket.logs.id ... }`. Which statements about this configuration are correct? (Select all that apply)(Select 3)

    1. A.Referencing aws_s3_bucket.logs.id inside the policy resource creates an implicit dependency, so Terraform creates the bucket before applying the policy.
    2. B.Because the reference exists, Terraform automatically includes aws_s3_bucket.logs in the dependency graph for the policy resource, with no separate depends_on argument needed.
    3. C.The bucket argument in the policy resource must reference the bucket's arn attribute instead of its id, or Terraform will refuse to parse the configuration.
    4. D.Replacing the reference with a hardcoded bucket name string would remove the implicit dependency, so Terraform could no longer guarantee the creation order between the two resources.
    5. E.Terraform re-evaluates and applies the policy resource only when a person manually reruns terraform apply after the bucket changes, since references do not trigger automatic replanning.
    6. F.Adding a depends_on = [aws_s3_bucket.logs] argument to the policy resource is required here, because the resource block does not already reference any attribute of the bucket.
    Show answer & explanation

    Correct answers: A, B, D — Referencing aws_s3_bucket.logs.id inside the policy resource creates an implicit dependency, so Terraform creates the bucket before applying the policy.; Because the reference exists, Terraform automatically includes aws_s3_bucket.logs in the dependency graph for the policy resource, with no separate depends_on argument needed.; Replacing the reference with a hardcoded bucket name string would remove the implicit dependency, so Terraform could no longer guarantee the creation order between the two resources.

    • A. The policy resource reads the bucket's id attribute, which only exists once the bucket has been created, so Terraform must order the bucket's creation ahead of the policy. This is a direct example of an implicit dependency inferred from an attribute reference.
    • B. Terraform builds its dependency graph by statically analyzing which resources are referenced in each block's arguments, so the bucket is added to the policy's graph node automatically. No depends_on argument is needed because the reference already conveys the relationship.
    • C. Whether an argument accepts an id, an arn, or another attribute is defined by the resource schema for that specific argument, not by a general rule about references. Using id here is a valid reference as long as it matches what the bucket argument's schema expects.
    • D. A hardcoded string carries no information Terraform can analyze, so removing the reference also removes the graph edge that forced ordering. Terraform would then have no basis for guaranteeing the bucket exists before the policy is applied.
    • E. Terraform's plan and apply cycle recalculates the dependency graph and reevaluates affected resources whenever referenced values change, without needing a human to intervene beyond running the normal apply workflow. Attribute references are exactly what drives that automatic reevaluation.
    • F. depends_on is meant for dependencies that cannot be expressed through an attribute reference; here the policy resource already references aws_s3_bucket.logs.id directly, so the dependency is already captured without adding depends_on.

    Subdomain 4.3: Use variables and outputs

    15.A variable block declares `variable "tags" {}` with no `type` argument and no validation block. During `terraform plan`, a caller passes a string for `tags` in one workspace and a map in another workspace. What happens?

    1. A.Terraform accepts both values because an omitted `type` argument defaults to `any`, so no type constraint is enforced.
    2. B.Terraform rejects the string value because omitting `type` implicitly constrains the variable to the `map` type only.
    3. C.Terraform converts both values to the `list` type automatically since that is the implicit default for untyped variables.
    4. D.Terraform throws an initialization error because every variable must declare an explicit `type` before `terraform plan` runs.
    Show answer & explanation

    Correct answer: A — Terraform accepts both values because an omitted `type` argument defaults to `any`, so no type constraint is enforced.

    • A. When a variable block omits the type argument, Terraform treats the constraint as any, so values of differing types can be passed across workspaces without a type-mismatch error at plan time.
    • B. Omitting type does not implicitly lock the variable to map; without an explicit constraint there is no type Terraform enforces, so a string value would not be rejected on that basis.
    • C. Terraform does not coerce untyped variable values into list form; the any default means whatever type is supplied is accepted as-is, not converted to a specific collection type.
    • D. A missing type argument is valid Terraform syntax and does not cause an initialization failure; type is optional on variable blocks, with any as the implicit constraint.

    Subdomain 4.4: Understand and use complex types

    16.A platform team is writing a root module where a variable must map each environment name (for example `dev`, `staging`, `prod`) to the number of EC2 instances to launch in that environment. Which type constraint should the variable use?

    1. A.map(number)
    2. B.list(number)
    3. C.object({ dev = number })
    4. D.set(number)
    Show answer & explanation

    Correct answer: A — map(number)

    • A. A map associates each environment name key with its own number value, which directly matches the need to look up an instance count by environment name.
    • B. This is incorrect because a list only provides positional, index-based access to numbers and cannot associate each count with an environment name key.
    • C. This is incorrect because it hard-codes a single `dev` attribute into the type itself, so the variable could never accept an arbitrary set of environment names like `staging` or `prod`.
    • D. This is incorrect because a set only stores unique numeric values with no associated key, so there would be no way to tell which count belongs to which environment.

    Subdomain 4.5: Write dynamic configuration using expressions and functions

    17.A team writes the following expression to group server names by their role: ``` { for name, srv in var.servers : srv.role => name... } ``` Which statements about this expression are correct? (Select all that apply.)(Select 3)

    1. A.The trailing ellipsis after name activates grouping mode, which is needed here because the same role value can be produced by more than one iteration.
    2. B.The resulting value is a map whose keys are the distinct role values, and whose values are lists containing every name that produced that role during iteration.
    3. C.Without the trailing ellipsis, this expression would still succeed and silently discard every name after the first one associated with each role.
    4. D.The expression is invalid because grouping mode can only be used inside square-bracket for expressions that produce lists, not inside curly-brace for expressions.
    5. E.The names within each list are stored in the exact order they originally appeared in var.servers, since grouping mode always preserves original iteration order.
    6. F.Replacing srv.role with the ellipsis removed, keeping only name as the value, would raise a duplicate-key error whenever two servers share the same role.
    Show answer & explanation

    Correct answers: A, B, F — The trailing ellipsis after name activates grouping mode, which is needed here because the same role value can be produced by more than one iteration.; The resulting value is a map whose keys are the distinct role values, and whose values are lists containing every name that produced that role during iteration.; Replacing srv.role with the ellipsis removed, keeping only name as the value, would raise a duplicate-key error whenever two servers share the same role.

    • A. Correct: the trailing ellipsis is exactly the syntax that switches an object-producing for expression into grouping mode, which is required whenever the key expression can repeat across iterations.
    • B. Correct: grouping mode produces a map from each distinct key to a list of every value collected under that key during the iteration, matching this expression's structure.
    • C. Incorrect: without grouping mode, an object for expression that produces the same key more than once raises a duplicate-key error rather than silently dropping later names.
    • D. Incorrect: grouping mode with the trailing ellipsis is used specifically inside curly-brace for expressions that produce maps, not inside square-bracket list expressions.
    • E. Incorrect: grouping mode sorts the collected values within each list lexically after grouping, so the order is not guaranteed to match the original iteration order.
    • F. Correct: removing the ellipsis turns the expression back into a plain object for expression, and Terraform raises a duplicate-key error whenever two iterations produce the same key, such as the same role.

    Subdomain 4.7: Validate configuration using custom conditions

    18.A module author adds a `validation` block inside a `variable "image_id"` declaration to require the value to start with `ami-`. When does Terraform run this validation relative to building the plan?

    1. A.Terraform runs variable validation immediately when the value is assigned, before Terraform generates a plan, so an invalid `image_id` stops the run before any resource is evaluated.
    2. B.Terraform runs variable validation only after the plan has been generated and reviewed, so an invalid `image_id` is caught during the apply confirmation step instead.
    3. C.Terraform runs variable validation after every resource has been created, so an invalid `image_id` triggers a rollback of the resources that already depended on it.
    4. D.Terraform runs variable validation only when `terraform destroy` is executed, so an invalid `image_id` blocks teardown but never blocks the initial provisioning apply.
    Show answer & explanation

    Correct answer: A — Terraform runs variable validation immediately when the value is assigned, before Terraform generates a plan, so an invalid `image_id` stops the run before any resource is evaluated.

    • A. Variable validation executes as soon as the value is known, ahead of plan generation, so a bad `image_id` is rejected before Terraform tries to evaluate any resource that depends on it.
    • B. Validation does not wait for the plan to be generated; it runs earlier, so an invalid value never reaches the point where a plan would be produced for review.
    • C. Terraform has no rollback mechanism triggered by variable validation, and validation happens far earlier than resource creation, not after resources already exist.
    • D. Variable validation applies to every operation that resolves the variable's value, including plan and apply, not only `terraform destroy`, so an invalid `image_id` would block provisioning as well.

    Subdomain 4.1: Use and differentiate resource and data blocks

    19.Data sources in Terraform are read-only: evaluating a `data` block never creates, updates, or destroys infrastructure.

    1. A.True
    2. B.False
    Show answer & explanation

    Correct answer: A — True

    • A. Correct. A data block only queries a provider for information about infrastructure that already exists; Terraform never issues create, update, or delete API calls on its behalf.
    • B. Incorrect. Read-only querying is exactly what distinguishes a data block from a resource block, which does create, update, and destroy the object it manages.

    Subdomain 4.6: Define resource dependencies in configuration

    20.Which of the following create a dependency edge in Terraform's resource graph? (Select all that apply.)(Select 3)

    1. A.Referencing another resource's attribute inside an argument expression, such as `aws_instance.web.id`, which Terraform's graph builder automatically detects.
    2. B.Adding an explicit `depends_on = [ ... ]` entry that lists the other resource or module, overriding Terraform's automatic inference.
    3. C.Passing a resource's attribute into a module's input variable, which the module then consumes inside its own resource arguments.
    4. D.Declaring both resources in the same `.tf` file, since Terraform parses all configuration files in a module together before building the graph.
    5. E.Using the same `provider` block or alias for both resources, since provider configuration is unrelated to resource-level dependency edges.
    6. F.Giving both resources a `name` label with the same prefix, since Terraform does not parse resource or attribute names for ordering.
    Show answer & explanation

    Correct answers: A, B, C — Referencing another resource's attribute inside an argument expression, such as `aws_instance.web.id`, which Terraform's graph builder automatically detects.; Adding an explicit `depends_on = [ ... ]` entry that lists the other resource or module, overriding Terraform's automatic inference.; Passing a resource's attribute into a module's input variable, which the module then consumes inside its own resource arguments.

    • A. This is correct: an argument expression that reads another resource's exported attribute is the standard mechanism Terraform uses to infer an implicit dependency and add the corresponding graph edge.
    • B. This is correct: listing a resource or module in `depends_on` explicitly tells Terraform to add a graph edge for a behavioral dependency that isn't otherwise visible through argument references.
    • C. This is correct: when a parent module passes a resource's attribute into a child module's input variable, and that variable is used inside the child module's resource arguments, Terraform's reference tracking still resolves the dependency across the module boundary.
    • D. This is incorrect: file layout has no bearing on dependency inference; all files in a module are parsed together, so co-locating two resources in the same file does not, by itself, create any graph edge between them.
    • E. This is incorrect: sharing a provider block or alias only determines which plugin instance handles API calls for each resource, and it carries no ordering information that would create a dependency edge.
    • F. This is incorrect: Terraform's graph builder analyzes argument expressions, not resource label text, so a shared naming prefix has no effect on dependency inference between two otherwise unrelated resources.

    Subdomain 4.8: Understand best practices for managing sensitive data, including secrets management with Vault

    21.A team migrates from long-lived, hardcoded AWS access keys to Vault's AWS secrets engine combined with the `vault_aws_access_credentials` data source in Terraform. Which of the following are genuine benefits of this migration? (Select all that apply.)(Select 3)

    1. A.Each Terraform run receives a unique, short-lived IAM credential, so a leaked credential from one run becomes worthless once its lease expires.
    2. B.Terraform automatically deletes the AWS resources it created if the Vault lease expires before the next `terraform apply` completes, preventing any manual cleanup.
    3. C.Long-lived static credentials no longer need to be distributed to every developer's machine, reducing the number of secrets an attacker could target.
    4. D.Terraform state files no longer need to be stored remotely, since dynamic Vault credentials replace the need for any backend access controls.
    5. E.Access can be centrally revoked or re-scoped through Vault's role configuration without rotating credentials on every machine that previously held a static key.
    6. F.The `vault_aws_access_credentials` data source removes the requirement to configure an AWS provider block, since Vault directly provisions AWS resources on Terraform's behalf.
    Show answer & explanation

    Correct answers: A, C, E — Each Terraform run receives a unique, short-lived IAM credential, so a leaked credential from one run becomes worthless once its lease expires.; Long-lived static credentials no longer need to be distributed to every developer's machine, reducing the number of secrets an attacker could target.; Access can be centrally revoked or re-scoped through Vault's role configuration without rotating credentials on every machine that previously held a static key.

    • A. This is a real, documented benefit: dynamic credentials are scoped to a short TTL, so a credential that leaks from a single run has a much smaller window of usefulness than a long-lived static key.
    • B. This is incorrect; Vault lease expiry only affects the validity of the credential used to authenticate, not the lifecycle of AWS resources that were already created. Terraform does not tear down infrastructure on lease expiry.
    • C. This is a real benefit; centralizing credential issuance in Vault means fewer static secrets are copied onto individual machines, shrinking the set of places an attacker could compromise to obtain access.
    • D. This is incorrect; dynamic AWS credentials have nothing to do with where or how Terraform state is stored. Remote state storage and backend access controls remain a separate, still-necessary concern.
    • E. This is a real benefit; because access is governed by Vault's role and policy configuration, permissions can be adjusted or revoked centrally without touching every machine that previously held a static credential.
    • F. This is incorrect; an AWS provider block is still required to provision AWS resources. The Vault data source only supplies credentials for that provider — it does not provision resources itself.

    Domain 5: Terraform modules

    Subdomain 5.1: Explain how Terraform sources modules

    22.True or False: The `version` argument in a `module` block can be used to pin a module sourced from a generic Git repository (using the `git::` prefix) to a specific release.

    1. A.True
    2. B.False
    Show answer & explanation

    Correct answer: B — False

    • A. This is incorrect: the `version` argument is only evaluated for sources that implement the module registry protocol, so Terraform silently ignores it when the source uses the `git::` prefix.
    • B. This is correct: generic Git sources are pinned using a `ref` query parameter appended to the source URL rather than the `version` argument, which only applies to registry-protocol sources.

    Subdomain 5.4: Manage module versions

    23.A team is writing the `version` argument for a module block that sources a `vpc` module from the public Terraform Registry. They want to permit any 1.x release from 1.3.0 onward while excluding 2.0.0 and later. Which of the following constraint strings would achieve this? (Select all that apply)(Select 2)

    1. A.version = ">= 1.3.0, < 2.0.0"
    2. B.version = "~> 1.3"
    3. C.version = "~> 1.3.0"
    4. D.version = ">= 1.3.0"
    5. E.version = "= 1.3.0, < 2.0.0"
    Show answer & explanation

    Correct answers: A, B — version = ">= 1.3.0, < 2.0.0"; version = "~> 1.3"

    • A. Correct: an explicit combined range with a floor of 1.3.0 and a ceiling below 2.0.0 admits every 1.x release from 1.3.0 up through the last 1.x version and nothing from the 2.x line.
    • B. Correct: with two segments given, the pessimistic operator locks the major number at 1 and lets the minor and patch digits move freely, which admits every release from 1.3.0 through the end of the 1.x line and excludes 2.0.0.
    • C. With all three segments given, the pessimistic operator locks the major and minor numbers together at 1.3 and only lets the patch digit increase, so releases like 1.4.0 or 1.9.2 would be excluded even though they fall within the desired range.
    • D. This sets only a floor with no ceiling, so it would also admit every 2.x, 3.x, or later release, which the team explicitly wants to exclude.
    • E. Combining an exact-equals operator with a separate upper bound is contradictory; equals pins the constraint to a single version, so no range of releases from 1.3.0 upward can actually be satisfied by this string.

    Subdomain 5.3: Use modules in configuration

    24.A team stores environment names in a map variable keyed by `dev`, `staging`, and `prod`, and wants to create one instance of a `bucket` module per map entry, addressing each instance by its environment key rather than a numeric position. Which meta-argument should they add to the `module` block?

    1. A.for_each
    2. B.count
    3. C.providers
    4. D.depends_on
    Show answer & explanation

    Correct answer: A — for_each

    • A. Correct. This meta-argument accepts a map or set of strings and creates one module instance per entry, addressable by key such as `module.bucket["prod"]`, matching the scenario's requirement to key instances off named environments rather than list position.
    • B. Incorrect. This meta-argument creates instances addressed by numeric index derived from a whole number, which does not preserve the meaningful `dev`/`staging`/`prod` keys the scenario needs to address instances by.
    • C. Incorrect. This meta-argument only maps provider configurations into a module instance; it does not control how many instances are created or how they're keyed.
    • D. Incorrect. This meta-argument only affects the ordering of operations relative to other resources or modules; it has no role in creating one instance per map entry.

    Subdomain 5.2: Describe variable scope within modules

    25.A configuration includes: ``` module "logging" { source = "./modules/logging" version = "~> 2.0" } ``` When this configuration is initialized, what happens?

    1. A.Terraform reports an error, because `version` is only valid when `source` points to a module registry, not a local filesystem path.
    2. B.Terraform ignores the `version` argument silently and initializes the local module using whatever code is currently present at the given path.
    3. C.Terraform searches the public registry for a module matching version `~> 2.0` and substitutes it in place of the local path entirely.
    4. D.Terraform creates a versioned local cache directory and locks the module to whatever revision happens to be currently checked out.
    Show answer & explanation

    Correct answer: A — Terraform reports an error, because `version` is only valid when `source` points to a module registry, not a local filesystem path.

    • A. The `version` argument constrains which release Terraform downloads from a module registry, and it has no meaning for a local path source, so Terraform surfaces an initialization error rather than silently accepting it.
    • B. Terraform does not silently discard an invalid argument here; pairing a `version` argument with a local `source` path causes initialization to fail with an explicit error rather than proceeding.
    • C. A local filesystem path is never resolved against the registry — the two source types are mutually exclusive, so Terraform cannot substitute a registry module in place of a local one.
    • D. Local modules are referenced directly, often via a symlink, rather than downloaded and cached by version number, so no versioned cache directory gets created for a local path.

    Domain 6: Terraform state management

    Subdomain 6.3: Configure remote state using the backend block

    26.Which of the following are genuine benefits teams gain by moving from the default local backend to a fully-featured remote backend? (Select all that apply.)(Select 3)

    1. A.Shared, centralized state lets every team member see the same up-to-date state without manually passing around a state file.
    2. B.Built-in state locking prevents two people from running conflicting writes against the same state at the same time.
    3. C.Sensitive values are kept off contributors' local disks, since state is not persisted locally except on unrecoverable errors.
    4. D.Terraform automatically rewrites `.tf` configuration files to canonical style every time a remote-backed apply completes.
    5. E.Provider plugins no longer need to be downloaded locally, since a remote backend executes all provider API calls on its own infrastructure.
    6. F.Resource dependency graphs are computed by the remote backend instead of the Terraform CLI, reducing local CPU usage during planning.
    Show answer & explanation

    Correct answers: A, B, C — Shared, centralized state lets every team member see the same up-to-date state without manually passing around a state file.; Built-in state locking prevents two people from running conflicting writes against the same state at the same time.; Sensitive values are kept off contributors' local disks, since state is not persisted locally except on unrecoverable errors.

    • A. Centralizing state in a shared backend removes the need to manually copy or email state files around, which is one of the core reasons teams adopt remote state.
    • B. Fully-featured remote backends provide a locking API that serializes writes, directly preventing the concurrent-write corruption risk that plain local state files are exposed to.
    • C. With a non-local backend, Terraform avoids persisting state to disk except in unrecoverable error cases, which keeps sensitive resource attributes off every contributor's machine.
    • D. Canonical formatting of `.tf` files is performed by `terraform fmt`, a separate CLI command that has nothing to do with where state is stored.
    • E. Provider plugins are still downloaded and executed locally by the Terraform CLI in the standard workflow; only HCP Terraform's remote execution mode runs providers elsewhere, and that is a separate feature from state storage.
    • F. The dependency graph is always built and walked by the Terraform CLI itself; a backend's job is limited to storing state and providing locking, not computing the resource graph.

    Subdomain 6.1: Describe the local backend

    27.An engineer sets up a new project with this backend configuration: ``` terraform { backend "local" { path = "state/prod.tfstate" } } ``` After running `terraform init` and then `terraform apply`, where will Terraform write the resulting state?

    1. A.To `state/prod.tfstate`, relative to the directory where Terraform commands are executed
    2. B.To `terraform.tfstate` in the root directory, since `path` only affects a state pull output
    3. C.To a file matching `path` but nested inside the module's provider plugin cache directory
    4. D.To whichever location the last successful `terraform plan` cached, ignoring the `path` argument
    Show answer & explanation

    Correct answer: A — To `state/prod.tfstate`, relative to the directory where Terraform commands are executed

    • A. This is correct. The `path` argument in a `local` backend block sets the exact relative location for the primary state file, so Terraform writes and reads state at `state/prod.tfstate`.
    • B. The `path` argument governs where the primary state file itself lives, not just the output of a pull command, so the default `terraform.tfstate` name would not be used here.
    • C. The local backend stores state alongside the configuration at the given path, not inside the provider plugin cache, which only holds downloaded provider binaries.
    • D. Terraform does not cache a separate write location from a prior plan; the `path` argument in the backend block is what determines where state is persisted on every run.

    Subdomain 6.4: Manage resource drift and Terraform state

    28.A team wants to stop managing an `aws_s3_bucket` resource with Terraform going forward, but the bucket must keep existing in AWS untouched, and the change should be reviewable through a normal pull request rather than run as an ad hoc CLI command. Which approach fits this requirement?

    1. A.Replace the `aws_s3_bucket` resource block with a `removed` block specifying `from = aws_s3_bucket.data` and `lifecycle { destroy = false }`.
    2. B.Delete the `aws_s3_bucket` resource block from the configuration entirely and let the next `terraform apply` reconcile the missing resource.
    3. C.Run `terraform state rm aws_s3_bucket.data` directly against the shared state backend before merging any configuration change.
    4. D.Add a `moved` block redirecting `aws_s3_bucket.data` to a `null_resource` so Terraform treats the bucket as replaced by a placeholder.
    Show answer & explanation

    Correct answer: A — Replace the `aws_s3_bucket` resource block with a `removed` block specifying `from = aws_s3_bucket.data` and `lifecycle { destroy = false }`.

    • A. This is correct. A `removed` block is a version-controlled configuration construct: it goes through review like any other `.tf` change, and setting `destroy = false` tells Terraform to drop the object from state without issuing a delete call against the real bucket.
    • B. Simply deleting the resource block gives Terraform no instruction about intent; by default, Terraform would plan to destroy the bucket to bring real infrastructure back in line with the now-absent configuration, which is the opposite of what's wanted.
    • C. `terraform state rm` achieves the state removal without destroying the bucket, but it is an imperative command run once against the backend, not a change captured in configuration that a pull request can review before it takes effect.
    • D. A `moved` block declares that two addresses represent the same underlying object; redirecting a real S3 bucket's address to an unrelated `null_resource` type is not a supported use and would not achieve the goal of releasing the bucket from management.

    Subdomain 6.2: Describe state locking

    29.Which of the following operations cause Terraform to automatically attempt to acquire the state lock? (Select all that apply)(Select 3)

    1. A.Running `terraform apply` to create, update, or destroy resources according to the current configuration.
    2. B.Running `terraform destroy` to remove every resource that is currently tracked in the Terraform state file.
    3. C.Running `terraform refresh` to reconcile the state file with the real infrastructure's current attributes.
    4. D.Running `terraform fmt` to reformat configuration files according to canonical style conventions.
    5. E.Running `terraform validate` to check configuration syntax without contacting any backend or provider.
    6. F.Running `terraform providers` to list the provider requirements declared by the current configuration.
    Show answer & explanation

    Correct answers: A, B, C — Running `terraform apply` to create, update, or destroy resources according to the current configuration.; Running `terraform destroy` to remove every resource that is currently tracked in the Terraform state file.; Running `terraform refresh` to reconcile the state file with the real infrastructure's current attributes.

    • A. Applying changes writes to state as resources are created, updated, or destroyed, so Terraform acquires the lock automatically before this operation begins.
    • B. Destroying resources removes their records from state, which is a write operation, so the lock is acquired the same way it is for an apply.
    • C. Refreshing updates the state file with the real infrastructure's current attributes, which is a write to state and therefore triggers automatic locking.
    • D. Reformatting configuration files only touches `.tf` files on disk and never reads or writes the state file, so no lock is needed.
    • E. Validating configuration checks syntax and internal consistency locally without contacting a backend, so there is no state file access that would require a lock.
    • F. Listing provider requirements only inspects the configuration's declared providers and does not read or modify the state file, so locking is not involved.

    Domain 7: Maintain infrastructure with Terraform

    Subdomain 7.1: Import existing infrastructure into your Terraform workspace

    30.A team inherited an AWS S3 bucket named `legacy-logs` that was created manually in the console and is not yet tracked in Terraform state. They want to bring it under management without recreating it. What must they do before running `terraform import aws_s3_bucket.legacy_logs legacy-logs`?

    1. A.Write an `aws_s3_bucket` resource block named `legacy_logs` in the configuration so the import command has a matching address to attach the bucket to.
    2. B.Delete the bucket in the AWS console first so Terraform can recreate it cleanly under the new resource address during the import operation.
    3. C.Run `terraform init -upgrade` to refresh the provider schema, since import will automatically create the missing resource block from that schema.
    4. D.Add the bucket's ARN to a `terraform.tfvars` file so the import command can look up the resource address from the variable definitions.
    Show answer & explanation

    Correct answer: A — Write an `aws_s3_bucket` resource block named `legacy_logs` in the configuration so the import command has a matching address to attach the bucket to.

    • A. This is correct. Import needs an existing resource address to attach the object to, so the block must be authored first with a matching type and local name.
    • B. This is wrong and destructive; deleting the bucket loses the real object and its data, which defeats the purpose of importing an existing resource.
    • C. This is wrong because `init -upgrade` only updates provider plugin versions and never inspects real infrastructure to author configuration blocks.
    • D. This is wrong because `terraform.tfvars` supplies values to input variables and has no mechanism for resolving or generating a resource address for import.

    Subdomain 7.3: Describe when and how to use verbose logging

    31.While preparing to file a GitHub issue about a Terraform crash, an engineer has captured extensive TRACE-level logs using TF_LOG_PATH. Given the size of the log file and the possibility it contains sensitive values, what is the recommended way to share it in the bug report?

    1. A.Review the log file for secrets or sensitive values, redact them, and share the resulting file through a paste service such as a GitHub Gist linked from the issue.
    2. B.Paste the entire raw log file directly into the body of the GitHub issue comment so maintainers can search it without opening a separate link.
    3. C.Attach only the crash message from the terminal output and omit the TF_LOG_PATH file entirely, since core maintainers rarely need the detailed trace.
    4. D.Email the raw, unredacted log file to Terraform's engineering team privately instead of referencing it anywhere in the public GitHub issue.
    Show answer & explanation

    Correct answer: A — Review the log file for secrets or sensitive values, redact them, and share the resulting file through a paste service such as a GitHub Gist linked from the issue.

    • A. Correct: because TRACE-level logs can be large and may contain sensitive values like credentials, the recommended practice is to redact secrets first and then share the file via a paste service such as a Gist rather than posting it raw.
    • B. Incorrect: pasting a large raw log directly into an issue comment is unwieldy for maintainers and risks exposing unredacted sensitive values inline.
    • C. Incorrect: omitting the detailed trace log defeats the purpose of capturing it, since the verbose detail is often what helps maintainers diagnose the crash.
    • D. Incorrect: private email bypasses the public issue tracker maintainers use for triage, and sending logs unredacted still risks exposing sensitive values.

    Subdomain 7.2: Use the CLI to inspect state

    32.A team is refactoring configuration and plans to run `terraform state mv` to rebind several existing resources to new addresses inside a module. Which of the following statements about this operation are accurate? (Select all that apply)(Select 3)

    1. A.The team must always pass `-lock=false` when moving resources, because state locking otherwise blocks the rebinding operation from starting.
    2. B.The command only updates Terraform's internal state bindings and does not call any provider API to modify the real infrastructure object.
    3. C.The command can move resources between two separate local and remote state files without needing any additional authentication flags.
    4. D.Terraform automatically writes a backup of the prior state file before completing the move, and this behavior cannot be disabled.
    5. E.The command can only rename resources at the top level of configuration and cannot move resources into or out of modules.
    6. F.Running the command with `-dry-run` previews the source-to-destination match without making any changes to the state file.
    Show answer & explanation

    Correct answers: B, D, F — The command only updates Terraform's internal state bindings and does not call any provider API to modify the real infrastructure object.; Terraform automatically writes a backup of the prior state file before completing the move, and this behavior cannot be disabled.; Running the command with `-dry-run` previews the source-to-destination match without making any changes to the state file.

    • A. State locking is enabled by default and works automatically; `-lock=false` is an optional, discouraged way to skip locking, not a requirement for the move to run.
    • B. This is accurate: rebinding changes which resource address tracks a given remote object entry in state, but it never calls a provider API to create, modify, or destroy the real infrastructure.
    • C. The command operates on a single state's bindings; moving objects between two entirely separate local and remote state files is not something this command performs without additional state-target flags, so this description is not accurate as stated.
    • D. This is accurate: like other state-modifying subcommands, every successful move writes a backup of the prior state first, and this safety behavior has no flag to disable it.
    • E. This is incorrect; moving a resource into a module address or out of one and back to the root is a documented use case, such as nesting a previously top-level resource under a module path.
    • F. This is accurate: this flag reports which existing addresses match the given source pattern without performing the actual rebinding, letting a team confirm scope before committing to the change.

    Domain 8: HCP Terraform

    Subdomain 8.1: Use HCP Terraform to create infrastructure

    33.Which workflow lets a developer trigger an HCP Terraform run directly from their terminal using the standard `terraform plan` and `terraform apply` commands, with execution happening remotely while progress streams back locally?

    1. A.CLI-driven workflow
    2. B.VCS-driven workflow
    3. C.API-driven workflow
    4. D.No-code provisioning workflow
    Show answer & explanation

    Correct answer: A — CLI-driven workflow

    • A. Correct: the CLI-driven workflow lets a developer run familiar `terraform plan` and `apply` commands locally, which HCP Terraform executes remotely while streaming output back to the terminal.
    • B. Incorrect: the VCS-driven workflow triggers runs automatically from commits or pull requests in a connected repository, not from a developer typing CLI commands.
    • C. Incorrect: the API-driven workflow uploads configuration and triggers runs through direct API calls, typically used for custom tooling rather than the standard `terraform` CLI commands.
    • D. Incorrect: no-code provisioning lets users deploy pre-built modules through the HCP Terraform UI without writing or running Terraform commands at all.

    Subdomain 8.3: Describe how to organize and use HCP Terraform workspaces and projects

    34.Which of the following are valid scopes at which an HCP Terraform variable set can be applied? (Select all that apply.)(Select 3)

    1. A.Globally, to all existing and future workspaces in the organization
    2. B.To specific workspaces or Stacks selected individually
    3. C.To all workspaces and Stacks within a specific project
    4. D.To a single Terraform state version, until that run finishes
    5. E.To an individual module call inside a workspace's configuration
    6. F.To a specific git branch, independent of which workspace runs it
    Show answer & explanation

    Correct answers: A, B, C — Globally, to all existing and future workspaces in the organization; To specific workspaces or Stacks selected individually; To all workspaces and Stacks within a specific project

    • A. Global scope is a supported option for an organization-owned variable set: HCP Terraform automatically applies it to every existing and future workspace in the organization.
    • B. Applying a set to individually selected workspaces or Stacks is a supported scope, letting teams share variables only with the resources that need them.
    • C. A project-owned variable set can be scoped to every workspace and Stack inside that specific project, applying automatically to anything created there.
    • D. Variable sets are not scoped to a single state version or run; they persist as configuration attached to workspaces, projects, or the organization, and apply to every subsequent run until removed.
    • E. Variable sets are not attached to individual module calls; they operate at the workspace, project, or organization level, and their values flow into the whole configuration rather than a single module block.
    • F. Variable sets are not scoped by git branch; scoping is based on workspace, project, or organization membership, regardless of which branch a connected repository is on.

    Subdomain 8.4: Configure and use HCP Terraform integration

    35.A workspace is already connected through a `backend "remote"` block, and the platform team wants to switch the configuration to the newer `cloud` block syntax without losing run history or creating a duplicate workspace. What should they do?

    1. A.Replace the `backend "remote"` block with an equivalent `cloud` block referencing the same organization and workspace, then run `terraform init`; Terraform keeps operating against the same workspace.
    2. B.Delete the existing workspace in HCP Terraform first, define a `cloud` block, and run `terraform init -reconfigure` so Terraform creates a fresh workspace and state is re-imported by hand.
    3. C.Keep the `backend "remote"` block unchanged and add a `cloud` block alongside it, so Terraform synchronizes operations across the two configurations automatically.
    4. D.Run `terraform state pull`, remove all backend configuration, and re-upload the exported state file through the HCP Terraform UI into a newly created workspace.
    Show answer & explanation

    Correct answer: A — Replace the `backend "remote"` block with an equivalent `cloud` block referencing the same organization and workspace, then run `terraform init`; Terraform keeps operating against the same workspace.

    • A. This is correct: swapping `backend "remote"` for a `cloud` block that points at the same organization and workspace is the documented upgrade path, and re-running init reconnects to the same workspace with no history loss.
    • B. Deleting the workspace throws away run history and forces a manual state re-import, which is unnecessary risk and extra work compared to simply swapping the block type.
    • C. Terraform does not support having both a `backend` block and a `cloud` block active at once; the configuration would fail validation rather than synchronizing two workspaces.
    • D. Manually exporting and re-uploading state through the UI is unnecessary and risks creating a second, disconnected workspace instead of continuing the existing one.

    Want the full experience?

    These are just samples. Practice the full HashiCorp Terraform Associate 004 question bank in quiz mode — free, no signup, with domain practice and exam simulation.