Skip to content

002 · Domain 5: Terraform Security and Governance · 13% of the exam

Task 5.1: Identify best practices for secrets

Keeping secrets out of state, plans and logs: sensitive values, ephemeral variables and resources, write-only arguments, encrypted state and plan files, and secrets stores in CI/CD.

Study it

Sample questions

Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.

Question 1 · choose 1

A nightly backup job calls the HCP Terraform state versions API for a production workspace, using a team token kept as a masked CI secret. It writes each full API response, including the hosted-state-download-url values, to a build log that every engineer can read. What should the security review conclude?

  1. ANothing leaks, as each download link also needs the masked team token
  2. BThe links never expire, so the logged state stays downloadable for good
  3. CThe links serve state with sensitive values redacted, so only IDs leak
  4. DEach link holds a short-term signed token, so log readers can fetch state
Show the answer and why
  • ANothing leaks, as each download link also needs the masked team token

    Incorrect

    Archivist download links need no bearer token; the authorization travels inside the URL itself.

  • BThe links never expire, so the logged state stays downloadable for good

    Incorrect

    The signed token in each link is short-term, with an expiry that depends on the API endpoint that returned it.

  • CThe links serve state with sensitive values redacted, so only IDs leak

    Incorrect

    hosted-state-download-url returns the raw state data, and state versions can hold sensitive data such as database passwords.

  • DEach link holds a short-term signed token, so log readers can fetch state

    Correct

    Archivist URLs carry a short-term signed authorization token, so HashiCorp says to treat them as secrets and avoid logging or sharing them.

A masked API token does not protect what the API returns. Drop or mask the Archivist URL fields before a job logs a response, and download state only inside the job that needs it.

Question 2 · choose 1

A regulated team runs its workspaces on HCP Terraform Premium. Compliance now requires that HCP Terraform itself cannot read the team's state or plan data and that the team can revoke that access with its own key, while policy checks and cost estimation keep running. What should the team use?

  1. AMark every sensitive variable and output as sensitive and ephemeral
  2. BHold your own key, with HCP Terraform agents encrypting state and plan files using the team's KMS key
  3. CSwitch the workspaces to local execution mode and run every plan on the team's own machines
  4. DMove state to an S3 backend with encrypt = true and keep only runs in HCP Terraform
Show the answer and why
  • AMark every sensitive variable and output as sensitive and ephemeral

    Incorrect

    That keeps some values out of artifacts, but HCP Terraform can still read the rest of the state and plan data with its own key.

  • BHold your own key, with HCP Terraform agents encrypting state and plan files using the team's KMS key

    Correct

    HYOK encrypts state and plan files with a key the team controls, and sanitized copies let policy checks, run tasks and cost estimation keep working.

  • CSwitch the workspaces to local execution mode and run every plan on the team's own machines

    Incorrect

    In local execution mode the workspace still stores state in HCP Terraform, encrypted with HashiCorp's key.

  • DMove state to an S3 backend with encrypt = true and keep only runs in HCP Terraform

    Incorrect

    A workspace's runs use the state stored in HCP Terraform; a backend block is overridden in remote runs.

By default HCP Terraform encrypts artifacts with a HashiCorp-managed key and can read them. Hold your own key (Premium) puts encryption under your KMS, and once enabled on a workspace it cannot be disabled.

Question 3 · choose 1

A reviewer objects that a resource's password_wo argument is set from a normal, non-ephemeral variable. What does the write-only documentation say?

  1. ATerraform rejects any value that is not ephemeral
  2. BThe value is stored in state as it is not ephemeral
  3. CBoth kinds work, though ephemeral values are recommended
  4. DIt works only on Terraform v1.10, before stricter rules arrived
Show the answer and why
  • ATerraform rejects any value that is not ephemeral

    Incorrect

    Unlike other ephemeral constructs, write-only arguments are not limited to ephemeral values.

  • BThe value is stored in state as it is not ephemeral

    Incorrect

    Write-only values are never persisted to state or plan files.

  • CBoth kinds work, though ephemeral values are recommended

    Correct

    Write-only arguments accept ephemeral and non-ephemeral values, and HashiCorp recommends passing ephemeral values to them.

  • DIt works only on Terraform v1.10, before stricter rules arrived

    Incorrect

    Write-only arguments require Terraform v1.11 or later.

Keep the variable itself ephemeral too, or its value may still reach state through other references.

Question 4 · choose 1

A local-exec provisioner passes a sensitive input variable to a command-line tool. Security asks whether the value can appear in Terraform's log output for the run. What does the provisioner documentation say?

  1. AProvisioners print their command lines, values included
  2. BProvisioners reject sensitive values with an error
  3. COnly remote-exec hides them; local-exec prints them as is
  4. DTerraform suppresses sensitive values in all log output
Show the answer and why
  • AProvisioners print their command lines, values included

    Incorrect

    Terraform suppresses sensitive values in the log output of provisioners.

  • BProvisioners reject sensitive values with an error

    Incorrect

    You can use sensitive values in provisioner blocks.

  • COnly remote-exec hides them; local-exec prints them as is

    Incorrect

    The suppression applies to all log output, whichever provisioner runs.

  • DTerraform suppresses sensitive values in all log output

    Correct

    The documentation says you can use sensitive values in provisioner blocks and that Terraform suppresses them in all log output.

Suppression covers Terraform's own log output. The tool may still write the value somewhere else, so check what it logs or stores.

Question 5 · choose 1

An object combines an ephemeral token with ordinary settings, and a non-ephemeral context needs only the ordinary parts. Which function drops the ephemeral parts?

  1. Aephemeralasnull()
  2. Bnonsensitive(), on the whole object
  3. Csensitive(), which hides the token
  4. DA local value that copies the object
Show the answer and why
  • Aephemeralasnull()

    Correct

    ephemeralasnull returns null for ephemeral values, nullifying any ephemeral values nested inside an object.

  • Bnonsensitive(), on the whole object

    Incorrect

    nonsensitive removes sensitive markings, not ephemerality.

  • Csensitive(), which hides the token

    Incorrect

    Sensitive values are still persisted.

  • DA local value that copies the object

    Incorrect

    A local that references an ephemeral value is itself ephemeral.

ephemeralasnull is available in Terraform v1.10 and later.

Question 6 · choose 1

A module's variable validation must confirm that callers pass the API key as a sensitive value. Which function tests that?

  1. Acan(sensitive(var.api_key))
  2. Bissensitive(var.api_key)
  3. Cnonsensitive(var.api_key) != null
  4. Dlength(var.api_key) > 0
Show the answer and why
  • Acan(sensitive(var.api_key))

    Incorrect

    can only reports whether the expression errors.

  • Bissensitive(var.api_key)

    Correct

    issensitive returns true if Terraform treats the value as sensitive and false otherwise.

  • Cnonsensitive(var.api_key) != null

    Incorrect

    nonsensitive only removes a marking, so comparing its result with null says nothing about whether the value was sensitive.

  • Dlength(var.api_key) > 0

    Incorrect

    Length says nothing about sensitivity.

issensitive is available in Terraform v1.8 and later.

Practice domain 5 →Practice all domains →