Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ testacc: build
gotestsum --format standard-verbose --jsonfile report.json --post-run-command "./summarize.sh" -- ./... -v -p=1 -timeout=300s; \
popd;

debug: build
et: build
export REPO_ROOT="../../../."; \
export TF_LOG=DEBUG; \
pushd ./test; \
gotestsum --format standard-verbose --jsonfile report.json --post-run-command "./summarize.sh" -- ./... -v -p=1 -timeout=300s; \
gotestsum --format standard-verbose --jsonfile report.json --post-run-command "./summarize.sh" -- ./... -v -p=1 -timeout=300s -run=$(t); \
popd;

.PHONY: fmt lint build install generate test testacc debug
44 changes: 44 additions & 0 deletions docs/data-sources/local_directory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "file_local_directory Data Source - file"
subcategory: ""
description: |-
LocalDirectory File DataSource
---

# file_local_directory (Data Source)

LocalDirectory File DataSource

## Example Usage

```terraform
# tflint-ignore: terraform_unused_declarations
data "file_local_directory" "basic_example" {
path = "example_directory"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `path` (String) Path to directory.

### Read-Only

- `files` (Attributes List) List of information about files in the directory. (see [below for nested schema](#nestedatt--files))
- `id` (String) Identifier derived from sha256 hash of path.
- `permissions` (String) Permissions of the directory.

<a id="nestedatt--files"></a>
### Nested Schema for `files`

Read-Only:

- `is_directory` (String) A string representation of whether or not the item is a directory or a file. This will be 'true' if the item is a directory, or 'false' if it isn't.
- `last_modified` (String) The UTC date of the last time the file was updated.
- `name` (String) The file's name.
- `permissions` (String) The file's permissions mode expressed in string format, eg. '0600'.
- `size` (String) The file's size in bytes.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "file_snapshot Data Source - file"
page_title: "file_local_snapshot Data Source - file"
subcategory: ""
description: |-
File Snapshot data source.
This data source retrieves the contents of a file from the output of a file_snapshot datasource.Warning! Using this resource places the plain text contents of the snapshot in your state file.
File LocalSnapshot data source.
This data source retrieves the contents of a file from the output of a file_local_snapshot datasource.Warning! Using this resource places the plain text contents of the snapshot in your state file.
---

# file_snapshot (Data Source)
# file_local_snapshot (Data Source)

File Snapshot data source.
This data source retrieves the contents of a file from the output of a file_snapshot datasource.Warning! Using this resource places the plain text contents of the snapshot in your state file.
File LocalSnapshot data source.
This data source retrieves the contents of a file from the output of a file_local_snapshot datasource.Warning! Using this resource places the plain text contents of the snapshot in your state file.



Expand Down
49 changes: 49 additions & 0 deletions docs/resources/local_directory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "file_local_directory Resource - file"
subcategory: ""
description: |-
Local Directory resource.
---

# file_local_directory (Resource)

Local Directory resource.

## Example Usage

```terraform
resource "file_local_directory" "basic_example" {
path = "path/to/new/directory"
permissions = "0700"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `path` (String) Directory path, required. All subdirectories will also be created. Changing this forces recreate.

### Optional

- `permissions` (String) The directory permissions to assign to the directory, defaults to '0700'. In order to automatically create subdirectories the owner must have execute access, ie. '0600' or less prevents the provider from creating subdirectories.

### Read-Only

- `created` (String) The top level directory created. eg. if 'path' = '/path/to/new/directory' and '/path/to' already exists, but the rest doesn't, then 'created' will be '/path/to/new'. This path will be recursively removed during destroy and recreate actions.
- `id` (String) Identifier derived from sha256 hash of path.

## 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 "path/to/file" sha256sum | awk '{print $1}')"
terraform import file_local_directory.example "IDENTIFIER"

# after this is run you will need to refine the resource further by setting the path and created properties.
```
24 changes: 12 additions & 12 deletions docs/resources/snapshot.md → docs/resources/local_snapshot.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "file_snapshot Resource - file"
page_title: "file_local_snapshot Resource - file"
subcategory: ""
description: |-
File Snapshot resource.
File LocalSnapshot 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_local_snapshot (Resource)

File Snapshot resource.
File LocalSnapshot 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
Expand All @@ -20,29 +20,29 @@ 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" {
resource "file_local_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
value = file_local_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 create a snapshot of the file using file_local_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
# then we output both the file_local datasource and file_local_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" {
resource "file_local_snapshot" "file_example" {
depends_on = [
file_local.snapshot_file_example,
]
Expand All @@ -52,7 +52,7 @@ resource "file_snapshot" "file_example" {
resource "terraform_data" "update_file" {
depends_on = [
file_local.snapshot_file_example,
file_snapshot.file_example,
file_local_snapshot.file_example,
]
provisioner "local-exec" {
command = <<-EOT
Expand All @@ -63,7 +63,7 @@ resource "terraform_data" "update_file" {
data "file_local" "snapshot_file_example_after_update" {
depends_on = [
file_local.snapshot_file_example,
file_snapshot.file_example,
file_local_snapshot.file_example,
terraform_data.update_file,
]
name = "snapshot_resource_test.txt"
Expand All @@ -75,7 +75,7 @@ output "file" {
# this updates a file that is used to show how snapshots work
}
output "snapshot" {
value = base64decode(file_snapshot.file_example.snapshot)
value = base64decode(file_local_snapshot.file_example.snapshot)
sensitive = true
# this is an example file that is used to show how snapshots work
}
Expand Down
5 changes: 5 additions & 0 deletions examples/data-sources/file_local_directory/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

# tflint-ignore: terraform_unused_declarations
data "file_local_directory" "basic_example" {
path = "example_directory"
}
4 changes: 4 additions & 0 deletions examples/resources/file_local_directory/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# IDENTIFIER="$(echo -n "path/to/file" sha256sum | awk '{print $1}')"
terraform import file_local_directory.example "IDENTIFIER"

# after this is run you will need to refine the resource further by setting the path and created properties.
5 changes: 5 additions & 0 deletions examples/resources/file_local_directory/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

resource "file_local_directory" "basic_example" {
path = "path/to/new/directory"
permissions = "0700"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ 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" {
resource "file_local_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
value = file_local_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 create a snapshot of the file using file_local_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
# then we output both the file_local datasource and file_local_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" {
resource "file_local_snapshot" "file_example" {
depends_on = [
file_local.snapshot_file_example,
]
Expand All @@ -36,7 +36,7 @@ resource "file_snapshot" "file_example" {
resource "terraform_data" "update_file" {
depends_on = [
file_local.snapshot_file_example,
file_snapshot.file_example,
file_local_snapshot.file_example,
]
provisioner "local-exec" {
command = <<-EOT
Expand All @@ -47,7 +47,7 @@ resource "terraform_data" "update_file" {
data "file_local" "snapshot_file_example_after_update" {
depends_on = [
file_local.snapshot_file_example,
file_snapshot.file_example,
file_local_snapshot.file_example,
terraform_data.update_file,
]
name = "snapshot_resource_test.txt"
Expand All @@ -59,7 +59,7 @@ output "file" {
# this updates a file that is used to show how snapshots work
}
output "snapshot" {
value = base64decode(file_snapshot.file_example.snapshot)
value = base64decode(file_local_snapshot.file_example.snapshot)
sensitive = true
# this is an example file that is used to show how snapshots work
}
20 changes: 20 additions & 0 deletions examples/use-cases/local_directory_advanced/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Local Directory Use Case

This is a more advanced use case for adding a directory.

The goal of this use case is to retrieve the files in the directory at a specific point in time.
We don't want the live data because we add files that we don't want included in the output.

These are the steps:
1. we generate a directory
2. add files to it
3. get the directory data
4. save the directory data to a file in the directory
5. snapshot the directory data
6. output the snapshot

The resulting output will always be the files we first placed in the directory excluding the directory data file.

On the initial run the directory data will match the snapshot,
but on subsequent runs the refresh phase will update the directory data to include the directory data file.
Our snapshot data will always exclude this file though, since it only updates when we alter the update trigger.
73 changes: 73 additions & 0 deletions examples/use-cases/local_directory_advanced/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@


provider "file" {}

locals {
path = var.path
}

resource "file_local_directory" "basic" {
path = local.path
}

resource "file_local" "a" {
depends_on = [
file_local_directory.basic,
]
name = "a"
directory = local.path
contents = "An example file to place in the directory."
}
resource "file_local" "b" {
depends_on = [
file_local_directory.basic,
]
name = "b"
directory = local.path
contents = "An example file to place in the directory."
}
resource "file_local" "c" {
depends_on = [
file_local_directory.basic,
]
name = "c"
directory = local.path
contents = "An example file to place in the directory."
}

data "file_local_directory" "basic" {
depends_on = [
file_local_directory.basic,
file_local.a,
file_local.b,
file_local.c,
]
path = local.path
}

resource "file_local" "directory_info" {
depends_on = [
file_local_directory.basic,
file_local.a,
file_local.b,
file_local.c,
data.file_local_directory.basic,
]
name = "directory_info.txt"
directory = local.path
contents = jsonencode(data.file_local_directory.basic)
}

resource "file_local_snapshot" "directory_snapshot" {
depends_on = [
file_local_directory.basic,
file_local.a,
file_local.b,
file_local.c,
data.file_local_directory.basic,
file_local.directory_info,
]
name = "directory_info.txt"
directory = local.path
update_trigger = "manual"
}
Loading