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

Source_dir conflicts with source #162

Open
1 task done
mr-miles opened this issue Sep 3, 2022 · 1 comment
Open
1 task done

Source_dir conflicts with source #162

mr-miles opened this issue Sep 3, 2022 · 1 comment

Comments

@mr-miles
Copy link

mr-miles commented Sep 3, 2022

Terraform CLI and Provider Versions

Terraform 0.14.6
hashicorp/archive v2.2.0

Use Cases or Problem Statement

I wanted to zip a folder and add a single extra file to the archive which is a config file created using the templatefile function. If I can add the content directly to the zip then I don't need to use the local_file resource, which creates churn at plan time.

I got the error message from

ConflictsWith: []string{"source_file", "source_dir", "source_content", "source_content_filename"},

about source_dir and source conflicting.

I was wondering what the conflict was as I couldn't think what the conflict could be (duplicate filenames seem possible with source too).

Proposal

Adjust validation so source_dir and source can be specified at the same time.

I could imagine it's desirable to create a "source_file" block attribute that contains file include/excludes, and they could be mixed with the current source blocks. That sounds like a lot more work though.

How much impact is this issue causing?

Low

Additional Information

Big benefit of this would be removal of plan churn because the only current way to make this work is to use local_file provider

Code of Conduct

  • I agree to follow this project's Code of Conduct
@rhynix
Copy link

rhynix commented Nov 29, 2022

One workaround for this is to use a combination of a dynamic block and the fileset function. This method works without using the local_file resource.

For instance, the following code creates an archive that contains both the content of the local.source_path folder, as well as the contents of local.config in the config file.

data "archive_file" "this" {
  type             = "zip"
  output_path      = "${path.module}/archive.zip"
  output_file_mode = "0644"

  source {
    content  = local.config
    filename = "config"
  }

  dynamic "source" {
    for_each = fileset(local.source_path, "**")

    content {
      filename = source.key
      content  = file("${local.source_path}/${source.key}")
    }
  }
}

Performance should be similar to using source_dir. Looking at zip_archiver.go both methods fully read every file into memory first. Note that using source_dir stores the file mode and modification date in the archive, while source does not.

In any case, I agree being able to use both source_dir and source together would be nice!

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

2 participants