004 · Domain 4: Terraform configuration · 13% of the exam
Task 4.8: Understand best practices for managing sensitive data, including secrets management with Vault
Sensitive variables and outputs, what still lands in state, ephemeral variables, outputs and resources, write-only arguments, and reading secrets from Vault with the Vault provider.
Study it
Sensitive values, ephemeral values, write-only arguments and Vault
Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.
Question 1 · choose 1
A pipeline passes a short-lived API token into a configuration only to configure a provider. The token must not end up in state or in saved plan files. How should the input variable be declared? (Terraform 1.12)
AWith ephemeral = true, so it is usable during the run but never stored
BWith a default of the token value, so it does not have to be passed on the command line
CWith nullable = false, so Terraform refuses to write the value anywhere
DWith type = string and a validation block that rejects stored values
Show the answer and why
AWith ephemeral = true, so it is usable during the run but never stored
Correct
The ephemeral argument makes a variable available at runtime while Terraform omits it from state and plan files; it can be used in contexts such as provider blocks.
BWith a default of the token value, so it does not have to be passed on the command line
Incorrect
A default puts the secret into the configuration itself.
CWith nullable = false, so Terraform refuses to write the value anywhere
Incorrect
nullable only controls whether null is accepted.
DWith type = string and a validation block that rejects stored values
Incorrect
Validation checks values; it cannot control where Terraform stores them.
Ephemeral variables (Terraform 1.10 and later) exist only for the run; nothing about them is written to state or plans.
A team wants Terraform runs to use short-lived cloud credentials instead of long-lived keys on laptops. It already runs Vault with a cloud secrets engine. What does HashiCorp's tutorial show?
AStore the long-lived keys as the default of a Terraform variable in the configuration
BRead short-lived credentials through the Vault provider and pass them on
CCopy the keys into the state file, which is encrypted by Vault
DUse a provisioner that logs in to Vault on each instance
Show the answer and why
AStore the long-lived keys as the default of a Terraform variable in the configuration
Incorrect
That keeps long-lived keys in configuration.
BRead short-lived credentials through the Vault provider and pass them on
Correct
The tutorial uses the Vault provider to generate short-lived, scoped credentials from the secrets engine and passes them to the cloud provider.
CCopy the keys into the state file, which is encrypted by Vault
Incorrect
State is not a credential store, and Vault does not encrypt local state.
DUse a provisioner that logs in to Vault on each instance
Incorrect
The provider, not provisioners, reads credentials for Terraform itself.
Dynamic secrets shrink the window in which a leaked credential is useful.
A value derived from a sensitive variable is only its character length, which is not secret, but Terraform redacts it in outputs. How can the author show it deliberately?
AWrap it in tostring()
BSet sensitive = false on the variable for one run
CWrap the expression in nonsensitive()
DUse ephemeralasnull() on the expression
Show the answer and why
AWrap it in tostring()
Incorrect
Type conversion keeps the sensitive marking.
BSet sensitive = false on the variable for one run
Incorrect
That would expose the secret itself, not just its length.
CWrap the expression in nonsensitive()
Correct
nonsensitive removes the sensitive marking from a value when the author knows it reveals nothing secret.
DUse ephemeralasnull() on the expression
Incorrect
That function replaces ephemeral values with null; it does not remove sensitivity.
nonsensitive is an explicit, reviewable statement that a derived value is safe to show.