--- # generated by https://github.com/hashicorp/terraform-plugin-docs page_title: "file_snapshot Resource - file" subcategory: "" description: |- File Snapshot resource. This resource saves some content in state and doesn't update it until the trigger argument changes. The refresh phase doesn't update state, instead the state can only change on create or update and only when the update_trigger argument changes. --- # file_snapshot (Resource) File Snapshot resource. This resource saves some content in state and doesn't update it until the trigger argument changes. The refresh phase doesn't update state, instead the state can only change on create or update and only when the update_trigger argument changes. ## Example Usage ```terraform # basic use case resource "file_local" "snapshot_file_basic_example" { name = "snapshot_resource_basic_example.txt" contents = "this is an example file that is used to show how snapshots work" } resource "file_snapshot" "basic_example" { depends_on = [ file_local.snapshot_file_basic_example, ] name = "snapshot_resource_basic_example.txt" update_trigger = "an arbitrary string" } output "snapshot_basic" { value = file_snapshot.basic_example.snapshot sensitive = true } # A more advanced use case: # We use a file_local resource to write a local file in the current directory # then we create a snapshot of the file using file_snapshot # then we update the file using a terraform_data resource # then we get the contents of the file using a file_local datasource # then we output both the file_local datasource and file_snapshot resource, observing that they are different resource "file_local" "snapshot_file_example" { name = "snapshot_resource_test.txt" contents = "this is an example file that is used to show how snapshots work" } resource "file_snapshot" "file_example" { depends_on = [ file_local.snapshot_file_example, ] name = "snapshot_resource_test.txt" update_trigger = "code-change-necessary" } resource "terraform_data" "update_file" { depends_on = [ file_local.snapshot_file_example, file_snapshot.file_example, ] provisioner "local-exec" { command = <<-EOT printf 'this updates a file that is used to show how snapshots work' > snapshot_resource_test.txt EOT } } data "file_local" "snapshot_file_example_after_update" { depends_on = [ file_local.snapshot_file_example, file_snapshot.file_example, terraform_data.update_file, ] name = "snapshot_resource_test.txt" } output "file" { value = data.file_local.snapshot_file_example_after_update.contents sensitive = true # this updates a file that is used to show how snapshots work } output "snapshot" { value = base64decode(file_snapshot.file_example.snapshot) sensitive = true # this is an example file that is used to show how snapshots work } ``` ## Schema ### Required - `name` (String) Name of the file to save. Changing this forces recreate, moving the file isn't supported. - `update_trigger` (String) When this argument changes the snapshot will be updated. ### Optional - `compress` (Boolean) Whether the provider should compress the contents and snapshot or not. Defaults to 'false'. When set to 'true' the provider will compress the contents and snapshot attributes using the gzip compression algorithm. Changing this attribute forces recreate, compressing snapshots which are already saved in state isn't supported. Warning! To prevent memory errors the provider generates temporary files to facilitate encoding and compression. - `directory` (String) Path of the file to save. Changing this forces recreate, moving the file isn't supported. ### Read-Only - `id` (String) Unique identifier for the resource. The SHA256 hash of the base64 encoded contents. - `snapshot` (String, Sensitive) Base64 encoded contents of the file specified in the name and directory fields. This data will be added on create and only updated when the update_trigger field changes. Warning! To prevent memory errors the provider generates temporary files to facilitate encoding and compression. ## Import Import is supported using the following syntax: The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example: ```shell # IDENTIFIER="$(echo -n "these contents are the default for testing" | base64 -w 0 | sha256sum | awk '{print $1}')" terraform import file_snapshot.example "IDENTIFIER" # after this is run you will need to refine the resource more by defining the contents and update_trigger # admittedly, it doesn't make a lot of sense to import a snapshot since there isn't anything to reconcile ```