World map

 

BM: Baca dalam Bahasa Melayu

World T2: Inputs & Outputs

Data sources: read what exists

You will learn: to read something that already exists with a data source, without owning it.

Checked with OpenTofu 1.13 on 1 Nov 2026

The problem

The chef writes today’s recipe in recipe.txt by hand. Your blueprint needs its words for the menu. Should OpenTofu build recipe.txt?

Pick one answer.

Watch

A data source: A data block that reads something that already exists. OpenTofu never changes or destroys it. reads something that already exists. Resource or data?

Drag a card into a box. Or tap the card, then tap the box.

      Try it

      The menu copies the recipe. Type tofu apply, then yes. Then cat menu.txt.

      Blueprint (your .tf files)init done

      • local_file.menunot built yet

      Built (the state file)

      Nothing built yet.

      Blueprint: 1 resources. Built: 0.

      Change a file, then run tofu plan to see what it means.

      data "local_file" "recipe" {
        filename = "recipe.txt"
      }

      Predict

      The chef changes recipe.txt to Roti canai. You run a plan. What happens to menu.txt?

      Pick one answer.

      Try it

      Be the chef: echo "Roti canai with dhal" > recipe.txt. Then tofu apply, and yes.

      Blueprint (your .tf files)init done

      • local_file.menu

      Built (the state file)state #1

      • local_file.menu
      recipe
      Nasi lemak with sambal
      Blueprint: 1 resources. Built: 1.

      Change a file, then run tofu plan to see what it means.

      Check

      The chef deleted recipe.txt. Plan stops. Tap the line that says why.

      Tap the lines that match.

      0 of 1 found

      You did it!

      You can now read existing things with a data source.

      Go deeper (optional)

      In the cloud, data sources look up things like an existing network. The plan shows them as Reading.... A resource that must wait for another can add depends_on. Usually a reference is enough.