Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider local_files Data Source for Graph Aware Equivalent of fileset() Function #214

Open
1 task done
bflad opened this issue Jun 15, 2023 · 0 comments
Open
1 task done

Comments

@bflad
Copy link
Member

bflad commented Jun 15, 2023

Terraform CLI and Provider Versions

N/A

Use Cases or Problem Statement

The Terraform configuration language has the fileset() function which returns a set of all files matching a glob pattern given a path. As with most configuration language functions, the result is evaluated before the rest of the graph. This can cause issues for practitioners wishing to use a collection of files generated/updated during the graph for purposes such as calculating checksums to explicitly cause resource replacement.

While today we generally rely on the function documentation to warn practitioners about this potential issue, it may make sense to provide a graph-aware solution for the use case.

Proposal

Create a new local_files data source which operates similarly to the fileset() function. As a design sketch of potential usage:

data "local_files" "example" {
  path    = path.module
  pattern = "*" # optional
}

data "local_file" "example" {
  for_each = data.local_files.example.filepaths

  filename = each.value
}

resource "random_uuid" "example" {
  keepers = {
    for file in data.local_file.example[*] :
    file.filename => file.content_md5
  }
}

Another example would be simplifying the uploading S3 objects based on file contents where there is a mixture of Terraform and non-Terraform managed files.

Proposed data source configurable attributes:

  • path - String, required, the starting path for matching
  • pattern - String, optional, defaults to *, the glob pattern (using the same doublestar dependency as Terraform CLI)

Proposed data source computed attributes:

  • file_paths - Set of strings, the paths to all files found by the glob pattern

How much impact is this issue causing?

Medium

Additional Information

As a recently closed example: hashicorp/terraform-provider-random#95

Code of Conduct

  • I agree to follow this project's Code of Conduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant