Skip to content

Commit 7708696

Browse files
jkroepkeSBGoods
andauthored
Add format tar.gz (hashicorp#277)
* Add format tar.gz * add doc note Signed-off-by: Jan-Otto Kröpke <[email protected]> * fix: inconsistent output with multiple files Signed-off-by: Jan-Otto Kröpke <[email protected]> * fix lint issues Signed-off-by: Jan-Otto Kröpke <[email protected]> * Regenerate provider documentation * fix: stabilize checksum in data resource for directories Signed-off-by: Jan-Otto Kröpke <[email protected]> * fix: nil pointer in tests Signed-off-by: Jan-Otto Kröpke <[email protected]> * fix: tests Signed-off-by: Jan-Otto Kröpke <[email protected]> * fix: tests Signed-off-by: Jan-Otto Kröpke <[email protected]> * Close gzip reader * fix windows issues * fix: conflicts Signed-off-by: Jan-Otto Kröpke <[email protected]> * Update internal/provider/tar_archiver_test.go Co-authored-by: Selena Goods <[email protected]> * test: move assert out of loop * test: remove unused var * Update internal/provider/tar_archiver_test.go Co-authored-by: Selena Goods <[email protected]> * test: add ensureTarContents to TestTarArchiver_Dir_Exclude_ExcludeSymlinkDirectories and TestTarArchiver_Dir_ExcludeSymlinkDirectories * rebase from main * split tests * remove duplicate tests * Fix `TestAccTarGzArchiveFile_SourceConfigConflicting()` acceptance test * Add changelog entries * Update documentation --------- Signed-off-by: Jan-Otto Kröpke <[email protected]> Co-authored-by: Selena Goods <[email protected]>
1 parent 13311ad commit 7708696

19 files changed

+5587
-2459
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: FEATURES
2+
body: 'data-source/archive_file: Add support for creating `tar.gz` archive files.'
3+
time: 2024-08-06T14:23:03.200664-04:00
4+
custom:
5+
Issue: "277"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: FEATURES
2+
body: 'resource/archive_file: Add support for creating `tar.gz` archive files.'
3+
time: 2024-08-06T14:25:29.318873-04:00
4+
custom:
5+
Issue: "277"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Terraform Provider: Archive
22

33
The Archive provider interacts with files.
4-
It provides a data source that can create zip archives for individual files or
4+
It provides a data source that can create zip or tar.gz archives for individual files or
55
collections of files.
66

77
## Documentation, questions and discussions

docs/data-sources/file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ data "archive_file" "lambda_my_function" {
5858
### Required
5959

6060
- `output_path` (String) The output of the archive file.
61-
- `type` (String) The type of archive to generate. NOTE: `zip` is supported.
61+
- `type` (String) The type of archive to generate. NOTE: `zip` and `tar.gz` is supported.
6262

6363
### Optional
6464

docs/resources/file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ description: |-
1818
### Required
1919

2020
- `output_path` (String) The output of the archive file.
21-
- `type` (String) The type of archive to generate. NOTE: `zip` is supported.
21+
- `type` (String) The type of archive to generate. NOTE: `zip` and `tar.gz` is supported.
2222

2323
### Optional
2424

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0
1111
github.com/hashicorp/terraform-plugin-go v0.23.0
1212
github.com/hashicorp/terraform-plugin-testing v1.9.0
13+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
1314
)
1415

1516
require (
@@ -54,12 +55,12 @@ require (
5455
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
5556
github.com/zclconf/go-cty v1.14.4 // indirect
5657
golang.org/x/crypto v0.25.0 // indirect
57-
golang.org/x/mod v0.17.0 // indirect
58-
golang.org/x/net v0.25.0 // indirect
58+
golang.org/x/mod v0.19.0 // indirect
59+
golang.org/x/net v0.27.0 // indirect
5960
golang.org/x/sync v0.7.0 // indirect
6061
golang.org/x/sys v0.22.0 // indirect
6162
golang.org/x/text v0.16.0 // indirect
62-
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
63+
golang.org/x/tools v0.23.0 // indirect
6364
google.golang.org/appengine v1.6.8 // indirect
6465
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
6566
google.golang.org/grpc v1.63.2 // indirect

go.sum

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,17 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
164164
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
165165
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
166166
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
167+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
168+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
167169
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
168-
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
169-
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
170+
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
171+
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
170172
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
171173
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
172174
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
173175
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
174-
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
175-
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
176+
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
177+
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
176178
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
177179
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
178180
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -204,8 +206,8 @@ golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
204206
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
205207
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
206208
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
207-
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
208-
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
209+
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
210+
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
209211
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
210212
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
211213
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=

internal/provider/archiver.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ type Archiver interface {
2424
type ArchiverBuilder func(outputPath string) Archiver
2525

2626
var archiverBuilders = map[string]ArchiverBuilder{
27-
"zip": NewZipArchiver,
27+
"zip": NewZipArchiver,
28+
"tar.gz": NewTarGzArchiver,
2829
}
2930

3031
func getArchiver(archiveType string, outputPath string) Archiver {
@@ -42,16 +43,18 @@ func assertValidFile(infilename string) (os.FileInfo, error) {
4243
return fi, err
4344
}
4445

45-
func assertValidDir(indirname string) (os.FileInfo, error) {
46+
func assertValidDir(indirname string) error {
4647
fi, err := os.Stat(indirname)
4748
if err != nil {
4849
if os.IsNotExist(err) {
49-
return fi, fmt.Errorf("could not archive missing directory: %s", indirname)
50+
return fmt.Errorf("could not archive missing directory: %s", indirname)
5051
}
51-
return fi, err
52+
return err
5253
}
54+
5355
if !fi.IsDir() {
54-
return fi, fmt.Errorf("could not archive directory that is a file: %s", indirname)
56+
return fmt.Errorf("could not archive directory that is a file: %s", indirname)
5557
}
56-
return fi, nil
58+
59+
return nil
5760
}

internal/provider/data_source_archive_file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (d *archiveFileDataSource) Schema(ctx context.Context, req datasource.Schem
8080
Computed: true,
8181
},
8282
"type": schema.StringAttribute{
83-
Description: "The type of archive to generate. NOTE: `zip` is supported.",
83+
Description: "The type of archive to generate. NOTE: `zip` and `tar.gz` is supported.",
8484
Required: true,
8585
},
8686
"source_content": schema.StringAttribute{

0 commit comments

Comments
 (0)