Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
HashiCorp · Terraform 004

Sensitive data, ephemeral values, and Vault

Terraform 004 · Lesson 11 of 18 · 1:13:44

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the HashiCorp Terraform Associate (004) exam. In this lesson: why secrets end up in state and plan files, sensitive variables and outputs, ephemeral values and write-only arguments, and HashiCorp Vault for short-lived credentials. Includes three original practice questions, with Bluefin Logistics, a fictional parcel delivery company, as the example.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

Secrets in Terraform

Bluefin's database password ended up in plain text, in a state file on a laptop. Secrets in Terraform need care, because state and plans store what the configuration sets. This lesson covers sensitive values, ephemeral values, write-only arguments, and Vault.

Secrets in state

Terraform stores in its state, and in saved plans, the values of the arguments and attributes that it manages, secrets included. A local state file is plain text, so it must never go into Git, and anyone who can read it can read the secrets. A remote backend keeps the state in memory only during an operation, and its storage can encrypt it at rest, as HCP Terraform does. So the first rule is simple: protect the state like a secret, because it can hold secrets.

Sensitive values

Setting sensitive to true on a variable or an output tells Terraform to hide its value in the output of plan and apply, and in the interface of HCP Terraform. The mark follows the value: any expression that uses a sensitive value is shown as sensitive too. But sensitive values are still stored in the state and in plans, so the mark protects the screen, not the file. And terraform output with the json or raw option prints them in clear text.

Ephemeral and write-only

Ephemeral values, since Terraform one point ten, are never written to state or plans. You can set ephemeral to true on an input variable or on an output of a child module, and an ephemeral block declares a resource that exists only during the run, like a temporary password. Ephemeral values can only go to places that do not persist, like provider blocks, other ephemeral values, and write-only arguments. A write-only argument, since Terraform one point eleven, sends a value to the provider without storing it, like the password W O argument of a database. Since Terraform cannot compare a value that it never stored, you change the version argument next to it to send a new value.

Vault

The best place for a long-term secret is a secrets manager such as HashiCorp Vault, not a variable file. The Vault provider reads its address and token from environment variables, and it can ask Vault for dynamic credentials, created for this run and valid for a short time. Careful: a Vault data source stores what it reads in the state, while an ephemeral resource, when the provider offers one, stores nothing. And HCP Terraform adds sensitive workspace variables, which nobody can read back once saved, and dynamic provider credentials, which replace stored keys with short-lived ones.

Recap

Let's recap. State and saved plans store the values of what Terraform manages, so protect the state like a secret. Sensitive hides a value on screen, but the state still stores it. Ephemeral values and write-only arguments never reach the state or plans, and a version argument sends a write-only value again. And Vault keeps long-term secrets and hands out short-lived credentials, while its data sources still write what they read to the state.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. An engineer wants to share Bluefin's configuration on GitHub, with the local state file (terraform.tfstate) that sits next to it. Why is that a problem?

    • Git cannot store files written in JSON
    • Terraform refuses state files from Git
    • The state can hold secrets in plain text
    • The state file holds the provider binaries
    Show the answer

    The state can hold secrets in plain text

    A local state file is plain text, and it holds the values of the resources, passwords included, so it must stay out of Git. “Git cannot store files written in JSON” is wrong, because Git stores any text file. “Terraform refuses state files from Git” is wrong, because the problem is who can read the file, not whether Terraform can. And “The state file holds the provider binaries” is wrong, because providers sit in the dot terraform directory, not in the state.

  2. A database module receives the admin password. Bluefin wants it hidden from plans and never stored in the state. Which approach fits?

    • An ephemeral variable, sent to a write-only argument
    • A variable with sensitive set to true
    • A sensitive output in the root module
    • A local value that reads the password file
    Show the answer

    An ephemeral variable, sent to a write-only argument

    An ephemeral variable is never written to state or plans, and a write-only argument hands it to the provider without storing it. “A variable with sensitive set to true” is a trap: sensitive masks the value on screen, but the state still stores it. “A sensitive output in the root module” is wrong, because root module outputs cannot be ephemeral, and a sensitive output is still stored. And “A local value that reads the password file” only moves the value, which still ends up in the state through the argument that uses it.

  3. A configuration reads a database password with a Vault data source, then passes it to a normal resource argument. Where can that password now be found?

    • Only in Vault, since data sources are read-only
    • Only in memory, for the length of the run
    • In Vault, and in the Git repository
    • In Vault, and in the Terraform state
    Show the answer

    In Vault, and in the Terraform state

    A data source stores the values that it reads in the state, and the normal argument stores the password too. “Only in Vault, since data sources are read-only” is wrong, because Terraform only reading from Vault says nothing about where the value goes next. “Only in memory, for the length of the run” is a description of an ephemeral resource, not a data source. And “In Vault, and in the Git repository” is wrong, because nothing writes the value to the Git repository, unless someone commits the state.