terraform-provider-file/docs/resources/local.md

2.2 KiB

page_title subcategory description
file_local Resource - file Local File resource

file_local (Resource)

Local File resource

Example Usage

# Copyright (c) HashiCorp, Inc.

resource "file_local" "example" {
  name     = "example.txt"
  contents = "An example implementation writing a local file."
}

Schema

Required

  • contents (String) File contents, required.
  • name (String) File name, required.

Optional

  • directory (String) The directory where the file will be placed, defaults to the current working directory.
  • hmac_secret_key (String, Sensitive) A string used to generate the file identifier, you can pass this value in the environment variable TF_FILE_HMAC_SECRET_KEY.The provider will use a hard coded value as the secret key for unprotected files.
  • id (String) Identifier derived from sha256+HMAC hash of file contents. When setting 'protected' to true this argument is required. However, when 'protected' is false then this should be left empty (computed by the provider).
  • mode (String) The file permissions to assign to the file, defaults to '0600'.
  • protected (Boolean) Whether or not to fail update or create if the calculated id doesn't match the given id.When this is true, the 'id' field is required and must match what we calculate as the hash at both create and update times.If the 'id' configured doesn't match what we calculate then the provider will error rather than updating or creating the file.When setting this to true, you will need to either set the TF_FILE_HMAC_SECRET_KEY environment variable or set the hmac_secret_key argument.

Import

Import is supported using the following syntax:

The terraform import command can be used, for example:

# Copyright (c) HashiCorp, Inc.

# echo "Test data" > data.txt
# FILEPATH="./data.txt"
# TF_FILE_HMAC_SECRET_KEY="super-secret-key"
# IDENTIFIER="$(openssl dgst -sha256 -hmac "$TF_FILE_HMAC_SECRET_KEY" "$FILE" | awk '{print $2}')"

terraform import file_local "IDENTIFIER"