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
Secrets in Terraform: sensitive, ephemeral and write-only values
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?
ANothing leaks, as each download link also needs the masked team token
BThe links never expire, so the logged state stays downloadable for good
CThe links serve state with sensitive values redacted, so only IDs leak
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.
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?
AMark every sensitive variable and output as sensitive and ephemeral
BHold your own key, with HCP Terraform agents encrypting state and plan files using the team's KMS key
CSwitch the workspaces to local execution mode and run every plan on the team's own machines
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.
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?
AProvisioners print their command lines, values included
BProvisioners reject sensitive values with an error
COnly remote-exec hides them; local-exec prints them as is
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.
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?
Aephemeralasnull()
Bnonsensitive(), on the whole object
Csensitive(), which hides the token
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.