From b8ceff67a82d4cfabea299d7872750c3a9daea07 Mon Sep 17 00:00:00 2001 From: Piotr Kala <pkala@clearstreet.io> Date: Tue, 18 Apr 2023 18:38:58 +0000 Subject: [PATCH] Use filepathx to support ** --- cmd/generate.go | 3 ++- cmd/generate_test.go | 18 ++++++++++++++++++ go.mod | 4 ++++ go.sum | 8 ++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/cmd/generate.go b/cmd/generate.go index 0836f3e8..7baa7145 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -12,6 +12,7 @@ import ( "github.com/gruntwork-io/terragrunt/config" "github.com/gruntwork-io/terragrunt/options" "github.com/spf13/cobra" + "github.com/yargevad/filepathx" "golang.org/x/sync/errgroup" "golang.org/x/sync/semaphore" @@ -590,7 +591,7 @@ func getAllTerragruntFiles(path string) ([]string, error) { // filters are not working (yet) if using project hcl files (which are kind of filters by themselves) if filterPath != "" && len(projectHclFiles) == 0 { // get all matching folders - workingPaths, err = filepath.Glob(filterPath) + workingPaths, err = filepathx.Glob(filterPath) if err != nil { return nil, err } diff --git a/cmd/generate_test.go b/cmd/generate_test.go index 950c5cef..fbbafd19 100644 --- a/cmd/generate_test.go +++ b/cmd/generate_test.go @@ -451,6 +451,15 @@ func TestFilterFlagWithInfraLiveProd(t *testing.T) { }) } +func TestFilterBetterGlobFlagWithInfraLiveProd(t *testing.T) { + runTest(t, filepath.Join("golden", "filterInfraLiveProd.yaml"), []string{ + "--root", + filepath.Join("..", "test_examples", "terragrunt-infrastructure-live-example"), + "--filter", + filepath.Join("..", "test_examples", "terragrunt-infrastructure-live-example", "prod"), + }) +} + func TestFilterFlagWithInfraLiveNonProd(t *testing.T) { runTest(t, filepath.Join("golden", "filterInfraLiveNonProd.yaml"), []string{ "--root", @@ -469,6 +478,15 @@ func TestFilterGlobFlagWithInfraLiveMySql(t *testing.T) { }) } +func TestFilterGlobFlagWithInfraLiveMySqlDoubleWildcard(t *testing.T) { + runTest(t, filepath.Join("golden", "filterGlobInfraLiveMySQL.yaml"), []string{ + "--root", + filepath.Join("..", "test_examples", "terragrunt-infrastructure-live-example"), + "--filter", + filepath.Join("..", "test_examples", "terragrunt-infrastructure-live-example", "**", "mysql"), + }) +} + func TestMultipleIncludes(t *testing.T) { runTest(t, filepath.Join("golden", "multiple_includes.yaml"), []string{ "--root", diff --git a/go.mod b/go.mod index 822d6eee..c62309da 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.16 require ( github.com/bmatcuk/doublestar v1.3.1 // indirect + github.com/debber/debber-v0.3 v0.0.0-20201001103732-e53137b65bb8 // indirect github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 github.com/go-errors/errors v1.1.1 // indirect github.com/gruntwork-io/terragrunt v0.36.6 @@ -12,11 +13,14 @@ require ( github.com/hashicorp/terraform-config-inspect v0.0.0-20210625153042-09f34846faab github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c // indirect github.com/imdario/mergo v0.3.12 // indirect + github.com/laher/argo v0.0.0-20140722103944-11d91c83cc0f // indirect + github.com/laher/goxc v0.18.1 // indirect github.com/mattn/go-zglob v0.0.2 // indirect github.com/sirupsen/logrus v1.6.0 github.com/spf13/cobra v0.0.5 github.com/stretchr/testify v1.7.0 github.com/urfave/cli v1.22.4 // indirect + github.com/yargevad/filepathx v1.0.0 // indirect github.com/zclconf/go-cty v1.8.3 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c gopkg.in/ini.v1 v1.57.0 // indirect diff --git a/go.sum b/go.sum index 2318af4a..76bd635f 100644 --- a/go.sum +++ b/go.sum @@ -265,6 +265,8 @@ github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/debber/debber-v0.3 v0.0.0-20201001103732-e53137b65bb8 h1:a2HUpEk5VTewSv3bJ2oNNLJS5r9lyjhmHRkVbmK7vxo= +github.com/debber/debber-v0.3 v0.0.0-20201001103732-e53137b65bb8/go.mod h1:TCVRstzD4Q5cPZofOCFtaeBwCr5WXJdG3hxzFmYYnZ0= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U= @@ -650,6 +652,10 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/laher/argo v0.0.0-20140722103944-11d91c83cc0f h1:fQ8JwxJN77cxE0foUmSHkKQebcxyd6vAfWCv7Bs5r34= +github.com/laher/argo v0.0.0-20140722103944-11d91c83cc0f/go.mod h1:Ymqfd31XvifvQ001Ty97DbYjQoeJPnb1WVkFhGeNYA4= +github.com/laher/goxc v0.18.1 h1:b5KJsjerACeEBsFWBveVzdUjc5wetTA5IQhOSjFJx50= +github.com/laher/goxc v0.18.1/go.mod h1:NdnX1aggrtsAowOUacIAYkuGKn2Md8Ej2DpoPUUqofs= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.8.0 h1:9xohqzkUwzR4Ga4ivdTcawVS89YSDVxXMa3xJX3cGzg= github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= @@ -894,6 +900,8 @@ github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yargevad/filepathx v1.0.0 h1:SYcT+N3tYGi+NvazubCNlvgIPbzAk7i7y2dwg3I5FYc= +github.com/yargevad/filepathx v1.0.0/go.mod h1:BprfX/gpYNJHJfc35GjRRpVcwWXS89gGulUIU5tK3tA= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=