• HashiCorp Developer

  • HashiCorp Cloud Platform
  • Terraform
  • Packer
  • Consul
  • Vault
  • Boundary
  • Nomad
  • Waypoint
  • Vagrant
Packer
  • Install
  • Tutorials
  • Documentation
  • Guides
  • Plugins
  • Try Cloud(opens in new tab)
  • Sign up
Packer Home

Documentation

Skip to main contentOverview
  • HCP Packer

  • Terminology
    • Overview
      • Overview
        • Overview
          • abspath
          • basename
          • dirname
          • file
          • fileexists
          • fileset
          • pathexpand
          • templatefile
      • Variables
      • Locals
      • Contextual Variables
      • Data Sources
      • Path Variables
      • Syntax
      • Only Except
      • Expressions
      • JSON Syntax


  • Installing Packer
  • Configuring Packer

  • Integration Program

  • Debugging

  • Resources

  • Tutorial Library
  • Community Forum
    (opens in new tab)
  • Support
    (opens in new tab)
  • GitHub
    (opens in new tab)
  1. Developer
  2. Packer
  3. Documentation
  4. Templates
  5. HCL Templates
  6. Functions
  7. Filesystem Functions
  8. file
  • Packer
  • v1.7.x
  • v1.6.x
  • v1.5.x

ยปfile Function

file reads the contents of a file at the given path and returns them as a string.

file(path)

Strings in the Packer language are sequences of Unicode characters, so this function will interpret the file contents as UTF-8 encoded text and return the resulting Unicode characters. If the file contains invalid UTF-8 sequences then this function will produce an error.

This function can be used only with files that already exist on disk at the beginning of a Packer run. Functions do not participate in the dependency graph, so this function cannot be used with files that are generated dynamically during a Packer operation.

Examples

> file("${path.folder}/hello.txt")
Hello World

Related Functions

  • fileexists determines whether a file exists at a given path.
Edit this page on GitHub

On this page

  1. file Function
  2. Examples
  3. Related Functions
Give Feedback(opens in new tab)
  • Certifications
  • System Status
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
  • Trade Controls
  • Give Feedback(opens in new tab)