Skip to content

Commit

Permalink
Add format tar.gz (#277)
Browse files Browse the repository at this point in the history
* Add format tar.gz

* add doc note

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>

* fix: inconsistent output with multiple files

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>

* fix lint issues

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>

* Regenerate provider documentation

* fix: stabilize checksum in data resource for directories

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>

* fix: nil pointer in tests

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>

* fix: tests

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>

* fix: tests

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>

* Close gzip reader

* fix windows issues

* fix: conflicts

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>

* Update internal/provider/tar_archiver_test.go

Co-authored-by: Selena Goods <github@simplebox.anonaddy.com>

* test: move assert out of loop

* test: remove unused var

* Update internal/provider/tar_archiver_test.go

Co-authored-by: Selena Goods <github@simplebox.anonaddy.com>

* 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 <mail@jkroepke.de>
Co-authored-by: Selena Goods <github@simplebox.anonaddy.com>
  • Loading branch information
jkroepke and SBGoods authored Aug 6, 2024
1 parent 13311ad commit 7708696
Show file tree
Hide file tree
Showing 19 changed files with 5,587 additions and 2,459 deletions.
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20240806-142303.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'data-source/archive_file: Add support for creating `tar.gz` archive files.'
time: 2024-08-06T14:23:03.200664-04:00
custom:
Issue: "277"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20240806-142529.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'resource/archive_file: Add support for creating `tar.gz` archive files.'
time: 2024-08-06T14:25:29.318873-04:00
custom:
Issue: "277"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Terraform Provider: Archive

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

## Documentation, questions and discussions
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ data "archive_file" "lambda_my_function" {
### Required

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

### Optional

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ description: |-
### Required

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

### Optional

Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0
github.com/hashicorp/terraform-plugin-go v0.23.0
github.com/hashicorp/terraform-plugin-testing v1.9.0
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
)

require (
Expand Down Expand Up @@ -54,12 +55,12 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.14.4 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.org/x/tools v0.23.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.63.2 // indirect
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,17 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -204,8 +206,8 @@ golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
Expand Down
15 changes: 9 additions & 6 deletions internal/provider/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ type Archiver interface {
type ArchiverBuilder func(outputPath string) Archiver

var archiverBuilders = map[string]ArchiverBuilder{
"zip": NewZipArchiver,
"zip": NewZipArchiver,
"tar.gz": NewTarGzArchiver,
}

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

func assertValidDir(indirname string) (os.FileInfo, error) {
func assertValidDir(indirname string) error {
fi, err := os.Stat(indirname)
if err != nil {
if os.IsNotExist(err) {
return fi, fmt.Errorf("could not archive missing directory: %s", indirname)
return fmt.Errorf("could not archive missing directory: %s", indirname)
}
return fi, err
return err
}

if !fi.IsDir() {
return fi, fmt.Errorf("could not archive directory that is a file: %s", indirname)
return fmt.Errorf("could not archive directory that is a file: %s", indirname)
}
return fi, nil

return nil
}
2 changes: 1 addition & 1 deletion internal/provider/data_source_archive_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (d *archiveFileDataSource) Schema(ctx context.Context, req datasource.Schem
Computed: true,
},
"type": schema.StringAttribute{
Description: "The type of archive to generate. NOTE: `zip` is supported.",
Description: "The type of archive to generate. NOTE: `zip` and `tar.gz` is supported.",
Required: true,
},
"source_content": schema.StringAttribute{
Expand Down
Loading

0 comments on commit 7708696

Please sign in to comment.