Files
Lucas Bajolet 5ce9b1867b datasource: add file datasource
The file datasource is meant to be used to pre-create a file that can
then be used elsewhere in the build process by its path.

This is useful for example when building a configuration file from a
template, so then the resulting file can be referenced by components
which only accept file paths.
2024-10-01 11:11:24 -04:00

46 lines
1.3 KiB
Plaintext

---
description: |
The File Data Source writes contents to a file so it can be used
later during Packer builds
page_title: File - Data Sources
---
<BadgesHeader>
<PluginBadge type="official" />
</BadgesHeader>
# File Data Source
Type: `file`
The `file` data source writes the specified contents to a file, creating it in the process if it doesn't exist.
This is particularly useful if you have a file to dynamically generate (with [`templatefile`](/packer/docs/templates/hcl_templates/functions/file/templatefile) for example), and the component you
rely on only accepts files, and not the generated string.
Using this data source, you can use those functions and have the output written to a temporary file that you can
reference in a component afterwards.
Note: being a datasource, the created file is not wiped-out after the build finishes. By default Packer will output
the file into the system's `TEMPDIR` (typically `/tmp` on UNIX systems, or `` on Windows).
You can also change this by specifying a `destination` for the data source.
## Basic Example
```hcl
data "file" "example" {
contents = "this is an example"
}
```
## Configuration Reference
### Not Required:
@include 'datasource/file/Config-not-required.mdx'
## Datasource outputs
The outputs for this datasource are as follows:
@include 'datasource/file/DatasourceOutput.mdx'