Skip to content

Commit cb36702

Browse files
SBGoodsaustinvalle
andauthored
Add glob file pattern matching support for the excludes attribute. (#354)
* Add glob pattern matching support for the `excludes` attribute. * Regenerate provider documentation * Switch from `Match()` to `PathMatch()` to be OS agnostic. * Add changelog entries * Add missing punctuation. * Regenerate provider documentation. * Update internal/provider/zip_archiver.go Co-authored-by: Austin Valle <[email protected]> * Add acceptance tests --------- Co-authored-by: Austin Valle <[email protected]>
1 parent e82378d commit cb36702

12 files changed

+130
-13
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: ENHANCEMENTS
2+
body: 'data-source/archive_file: Add glob pattern matching support to the `excludes` attribute.'
3+
time: 2024-07-24T16:07:24.058378-04:00
4+
custom:
5+
Issue: "354"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: ENHANCEMENTS
2+
body: 'resource/archive_file: Add glob pattern matching support to the `excludes` attribute.'
3+
time: 2024-07-24T16:08:30.211413-04:00
4+
custom:
5+
Issue: "354"

docs/data-sources/file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ data "archive_file" "lambda_my_function" {
6363
### Optional
6464

6565
- `exclude_symlink_directories` (Boolean) Boolean flag indicating whether symbolically linked directories should be excluded during the creation of the archive. Defaults to `false`.
66-
- `excludes` (Set of String) Specify files to ignore when reading the `source_dir`.
66+
- `excludes` (Set of String) Specify files/directories to ignore when reading the `source_dir`. Supports glob file matching patterns including doublestar/globstar (`**`) patterns.
6767
- `output_file_mode` (String) String that specifies the octal file mode for all archived files. For example: `"0666"`. Setting this will ensure that cross platform usage of this module will not vary the modes of archived files (and ultimately checksums) resulting in more deterministic behavior.
6868
- `source` (Block Set) Specifies attributes of a single source file to include into the archive. One and only one of `source`, `source_content_filename` (with `source_content`), `source_file`, or `source_dir` must be specified. (see [below for nested schema](#nestedblock--source))
6969
- `source_content` (String) Add only this content to the archive with `source_content_filename` as the filename. One and only one of `source`, `source_content_filename` (with `source_content`), `source_file`, or `source_dir` must be specified.

docs/resources/file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ description: |-
2323
### Optional
2424

2525
- `exclude_symlink_directories` (Boolean) Boolean flag indicating whether symbolically linked directories should be excluded during the creation of the archive. Defaults to `false`.
26-
- `excludes` (Set of String) Specify files to ignore when reading the `source_dir`.
26+
- `excludes` (Set of String) Specify files/directories to ignore when reading the `source_dir`. Supports glob file matching patterns including doublestar/globstar (`**`) patterns.
2727
- `output_file_mode` (String) String that specifies the octal file mode for all archived files. For example: `"0666"`. Setting this will ensure that cross platform usage of this module will not vary the modes of archived files (and ultimately checksums) resulting in more deterministic behavior.
2828
- `source` (Block Set) Specifies attributes of a single source file to include into the archive. One and only one of `source`, `source_content_filename` (with `source_content`), `source_file`, or `source_dir` must be specified. (see [below for nested schema](#nestedblock--source))
2929
- `source_content` (String) Add only this content to the archive with `source_content_filename` as the filename. One and only one of `source`, `source_content_filename` (with `source_content`), `source_file`, or `source_dir` must be specified.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.21
55
toolchain go1.21.3
66

77
require (
8+
github.com/bmatcuk/doublestar/v4 v4.6.1
89
github.com/hashicorp/terraform-plugin-framework v1.10.0
910
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0
1011
github.com/hashicorp/terraform-plugin-go v0.23.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki
99
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
1010
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
1111
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
12+
github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I=
13+
github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
1214
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
1315
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
1416
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=

internal/provider/data_source_archive_file.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ func (d *archiveFileDataSource) Schema(ctx context.Context, req datasource.Schem
134134
},
135135
},
136136
"excludes": schema.SetAttribute{
137-
Description: "Specify files to ignore when reading the `source_dir`.",
137+
Description: "Specify files/directories to ignore when reading the `source_dir`. " +
138+
"Supports glob file matching patterns including doublestar/globstar (`**`) patterns.",
138139
ElementType: types.StringType,
139140
Optional: true,
140141
Validators: []validator.Set{

internal/provider/data_source_archive_file_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ func TestAccArchiveFile_Basic(t *testing.T) {
105105
r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize),
106106
),
107107
},
108+
{
109+
Config: testAccArchiveFileDirExcludesGlobConfig(f),
110+
Check: r.ComposeTestCheckFunc(
111+
testAccArchiveFileSize(f, &fileSize),
112+
r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize),
113+
),
114+
},
108115
{
109116
Config: testAccArchiveFileMultiSourceConfig(f),
110117
Check: r.ComposeTestCheckFunc(
@@ -1389,6 +1396,17 @@ data "archive_file" "foo" {
13891396
`, filepath.ToSlash(outputPath))
13901397
}
13911398

1399+
func testAccArchiveFileDirExcludesGlobConfig(outputPath string) string {
1400+
return fmt.Sprintf(`
1401+
data "archive_file" "foo" {
1402+
type = "zip"
1403+
source_dir = "test-fixtures/test-dir/test-dir1"
1404+
excludes = ["test-fixtures/test-dir/test-dir1/file2.txt", "**/file[2-3].txt"]
1405+
output_path = "%s"
1406+
}
1407+
`, filepath.ToSlash(outputPath))
1408+
}
1409+
13921410
func testAccArchiveFileMultiSourceConfig(outputPath string) string {
13931411
return fmt.Sprintf(`
13941412
data "archive_file" "foo" {

internal/provider/resource_archive_file.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ func (d *archiveFileResource) Schema(ctx context.Context, req resource.SchemaReq
154154
},
155155
},
156156
"excludes": schema.SetAttribute{
157-
Description: "Specify files to ignore when reading the `source_dir`.",
157+
Description: "Specify files/directories to ignore when reading the `source_dir`. " +
158+
"Supports glob file matching patterns including doublestar/globstar (`**`) patterns.",
158159
ElementType: types.StringType,
159160
Optional: true,
160161
Validators: []validator.Set{

internal/provider/resource_archive_file_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ func TestAccArchiveFile_Resource_Basic(t *testing.T) {
104104
r.TestCheckResourceAttrPtr("archive_file.foo", "output_size", &fileSize),
105105
),
106106
},
107+
{
108+
Config: testAccArchiveFileResourceDirExcludesGlobConfig(f),
109+
Check: r.ComposeTestCheckFunc(
110+
testAccArchiveFileSize(f, &fileSize),
111+
r.TestCheckResourceAttrPtr("archive_file.foo", "output_size", &fileSize),
112+
),
113+
},
107114
{
108115
Config: testAccArchiveFileResourceMultiSourceConfig(f),
109116
Check: r.ComposeTestCheckFunc(
@@ -1485,6 +1492,17 @@ resource "archive_file" "foo" {
14851492
`, filepath.ToSlash(outputPath))
14861493
}
14871494

1495+
func testAccArchiveFileResourceDirExcludesGlobConfig(outputPath string) string {
1496+
return fmt.Sprintf(`
1497+
resource "archive_file" "foo" {
1498+
type = "zip"
1499+
source_dir = "test-fixtures/test-dir"
1500+
excludes = ["test-fixtures/test-dir/file2.txt", "**/file[2-3].txt"]
1501+
output_path = "%s"
1502+
}
1503+
`, filepath.ToSlash(outputPath))
1504+
}
1505+
14881506
func testAccArchiveFileResourceMultiSourceConfig(outputPath string) string {
14891507
return fmt.Sprintf(`
14901508
resource "archive_file" "foo" {

0 commit comments

Comments
 (0)