-
Notifications
You must be signed in to change notification settings - Fork 63
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
Exclude #18
Exclude #18
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems legit, but I'd like @paultyng to review as well, I think he may have more context/experience here than I do
I also need to exclude some files from directory before zipping it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a great addition, but I wonder if this really needs to be a TypeList
if its also a regexp? Can't you just a|b|c
?
May be simpler to just flatten this to a TypeString
and use the regexp validation: https://github.com/hashicorp/terraform/blob/2dc7241df0245b2be005946b4bc903dfab496c71/helper/validation/validation.go#L254-L259
If you would prefer to use a list of strings I'd rather drop the regexp support then and just use explicit relative path names for exclusion. That would also simplify a lot of the checking logic and remove some of the regexp magic with the appending of the anchors.
data "archive_file" "foo" { | ||
type = "zip" | ||
source_dir = "../archive/test-fixtures/../test-fixtures/test-dir" | ||
excludes = ["test-fixtures/test-dir/file2.txt"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some whitespace weirdness in here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can fix this
archive/zip_archiver.go
Outdated
@@ -83,12 +98,25 @@ func (a *ZipArchiver) ArchiveDir(indirname string) error { | |||
defer a.close() | |||
|
|||
return filepath.Walk(indirname, func(path string, info os.FileInfo, err error) error { | |||
tmpFilePath, _ := filepath.Abs(path) | |||
tmpLongFileName, _ := filepath.Abs(indirname) | |||
shortFileName := strings.TrimPrefix(tmpFilePath, tmpLongFileName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use filepath.Rel
(it's already used below, you could just move that line up)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will test this
archive/zip_archiver.go
Outdated
if info.IsDir() { | ||
if isMatch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you probably still want to walk all the dirs and match against the full relative paths? You may want to add a test case that covers this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you match on a directory you are excluding the directory why match after that?
i.e.
/hi/
/hello/world
/hello/i/am/here
if you exclude hello/ you should exclude everything in the hello path why still walk?
I have updated this to use relative path for exact match removing globing on anything except dirs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good, just one minor thing to prevent spurious diff.
archive/data_source_archive_file.go
Outdated
@@ -77,6 +77,15 @@ func dataSourceFile() *schema.Resource { | |||
ForceNew: true, | |||
ConflictsWith: []string{"source_content", "source_content_filename", "source_file"}, | |||
}, | |||
"excludes": &schema.Schema{ | |||
Type: schema.TypeList, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be a TypeSet
as it's order does not matter I think? https://www.terraform.io/docs/extend/schemas/schema-types.html#typeset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah typeSet works
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
This allows a user to exclude files when using dir archive.