@@ -315,6 +315,7 @@ func TestFilterDocumentationExamples(t *testing.T) {
315315 generateIntersectionFixture (t , tmpDir )
316316 generateReadingFixture (t , tmpDir )
317317 generateGraphBasedFixture (t , tmpDir )
318+ generateSourceBasedFixture (t , tmpDir )
318319
319320 testCases := []struct {
320321 name string
@@ -512,6 +513,50 @@ func TestFilterDocumentationExamples(t *testing.T) {
512513 filterQuery : "service... | !^db..." ,
513514 expectedOutput : "cache\n db\n service\n " ,
514515 },
516+
517+ // Source-based filtering
518+ {
519+ name : "source-exact-match-github" ,
520+ fixtureDir : "source-based" ,
521+ filterQuery : "source=github.com/acme/foo" ,
522+ expectedOutput : "github-acme-foo\n " ,
523+ },
524+ {
525+ name : "source-exact-match-gitlab" ,
526+ fixtureDir : "source-based" ,
527+ filterQuery : "source=gitlab.com/example/baz" ,
528+ expectedOutput : "gitlab-example-baz\n " ,
529+ },
530+ {
531+ name : "source-exact-match-local" ,
532+ fixtureDir : "source-based" ,
533+ filterQuery : "source=./module" ,
534+ expectedOutput : "local-module\n " ,
535+ },
536+ {
537+ name : "source-glob-github-org" ,
538+ fixtureDir : "source-based" ,
539+ filterQuery : "source=*github.com**acme/*" ,
540+ expectedOutput : "github-acme-bar\n github-acme-foo\n " ,
541+ },
542+ {
543+ name : "source-glob-github-ssh" ,
544+ fixtureDir : "source-based" ,
545+ filterQuery :
"source=git::[email protected] :acme/**" ,
546+ expectedOutput : "github-acme-bar\n " ,
547+ },
548+ {
549+ name : "source-glob-all-github" ,
550+ fixtureDir : "source-based" ,
551+ filterQuery : "source=**github.com**" ,
552+ expectedOutput : "github-acme-bar\n github-acme-foo\n " ,
553+ },
554+ {
555+ name : "source-glob-gitlab" ,
556+ fixtureDir : "source-based" ,
557+ filterQuery : "source=gitlab.com/**" ,
558+ expectedOutput : "gitlab-example-baz\n " ,
559+ },
515560 }
516561
517562 // Run all test cases
@@ -833,6 +878,59 @@ dependency "cache" {
833878 require .NoError (t , os .WriteFile (filepath .Join (serviceDir , "main.tf" ), []byte ("" ), 0644 ))
834879}
835880
881+ func generateSourceBasedFixture (t * testing.T , baseDir string ) {
882+ rootDir := filepath .Join (baseDir , "source-based" , "root" )
883+ require .NoError (t , os .MkdirAll (rootDir , 0755 ))
884+
885+ // Create github-acme-foo with source github.com/acme/foo
886+ githubAcmeFooDir := filepath .Join (rootDir , "github-acme-foo" )
887+ require .NoError (t , os .MkdirAll (githubAcmeFooDir , 0755 ))
888+ require .NoError (t , os .WriteFile (filepath .Join (githubAcmeFooDir , "terragrunt.hcl" ), []byte (`terraform {
889+ source = "github.com/acme/foo"
890+ }
891+ ` ), 0644 ))
892+ require .NoError (t , os .WriteFile (filepath .Join (githubAcmeFooDir , "main.tf" ), []byte ("" ), 0644 ))
893+
894+ // Create github-acme-bar with source git::[email protected] :acme/bar 895+ githubAcmeBarDir := filepath .Join (rootDir , "github-acme-bar" )
896+ require .NoError (t , os .MkdirAll (githubAcmeBarDir , 0755 ))
897+ require .NoError (t , os .WriteFile (filepath .Join (githubAcmeBarDir , "terragrunt.hcl" ), []byte (`terraform {
898+ source = "git::[email protected] :acme/bar" 899+ }
900+ ` ), 0644 ))
901+ require .NoError (t , os .WriteFile (filepath .Join (githubAcmeBarDir , "main.tf" ), []byte ("" ), 0644 ))
902+
903+ // Create gitlab-example-baz with source gitlab.com/example/baz
904+ gitlabExampleBazDir := filepath .Join (rootDir , "gitlab-example-baz" )
905+ require .NoError (t , os .MkdirAll (gitlabExampleBazDir , 0755 ))
906+ require .NoError (t , os .WriteFile (filepath .Join (gitlabExampleBazDir , "terragrunt.hcl" ), []byte (`terraform {
907+ source = "gitlab.com/example/baz"
908+ }
909+ ` ), 0644 ))
910+ require .NoError (t , os .WriteFile (filepath .Join (gitlabExampleBazDir , "main.tf" ), []byte ("" ), 0644 ))
911+
912+ // Create local-module with source ./module
913+ localModuleDir := filepath .Join (rootDir , "local-module" )
914+ require .NoError (t , os .MkdirAll (localModuleDir , 0755 ))
915+ require .NoError (t , os .WriteFile (filepath .Join (localModuleDir , "terragrunt.hcl" ), []byte (`terraform {
916+ source = "./module"
917+ }
918+ ` ), 0644 ))
919+ // Create the module directory with main.tf
920+ moduleDir := filepath .Join (localModuleDir , "module" )
921+ require .NoError (t , os .MkdirAll (moduleDir , 0755 ))
922+ require .NoError (t , os .WriteFile (filepath .Join (moduleDir , "main.tf" ), []byte ("" ), 0644 ))
923+
924+ // Create other-unit with source s3://bucket/module (for non-matching examples)
925+ otherUnitDir := filepath .Join (rootDir , "other-unit" )
926+ require .NoError (t , os .MkdirAll (otherUnitDir , 0755 ))
927+ require .NoError (t , os .WriteFile (filepath .Join (otherUnitDir , "terragrunt.hcl" ), []byte (`terraform {
928+ source = "s3://bucket/module"
929+ }
930+ ` ), 0644 ))
931+ require .NoError (t , os .WriteFile (filepath .Join (otherUnitDir , "main.tf" ), []byte ("" ), 0644 ))
932+ }
933+
836934// Helper functions to create Terragrunt configuration files
837935
838936func createTerragruntUnit (t * testing.T , dir string ) {
0 commit comments