@@ -313,6 +313,7 @@ func TestFilterDocumentationExamples(t *testing.T) {
313313 generatePathBasedFixture (t , tmpDir )
314314 generateNegationFixture (t , tmpDir )
315315 generateIntersectionFixture (t , tmpDir )
316+ generateReadingFixture (t , tmpDir )
316317
317318 testCases := []struct {
318319 name string
@@ -434,6 +435,38 @@ func TestFilterDocumentationExamples(t *testing.T) {
434435 filterQuery : "./dev/**|type=unit|!name=unit1" , // Our testing arg parsing is busted. Don't put whitespace between these.
435436 expectedOutput : "dev/units/unit2\n " ,
436437 },
438+
439+ // Reading attribute filtering
440+ {
441+ name : "reading-exact-file-match" ,
442+ fixtureDir : "reading" ,
443+ filterQuery : "reading=shared.hcl" ,
444+ expectedOutput : "apps/app1\n apps/app2\n " ,
445+ },
446+ {
447+ name : "reading-glob-pattern" ,
448+ fixtureDir : "reading" ,
449+ filterQuery : "reading=shared*" ,
450+ expectedOutput : "apps/app1\n apps/app2\n " ,
451+ },
452+ {
453+ name : "reading-nested-path" ,
454+ fixtureDir : "reading" ,
455+ filterQuery : "reading=common/vars.hcl" ,
456+ expectedOutput : "apps/app3\n " ,
457+ },
458+ {
459+ name : "reading-negation" ,
460+ fixtureDir : "reading" ,
461+ filterQuery : "!reading=shared.hcl" ,
462+ expectedOutput : "apps/app3\n libs/lib1\n " ,
463+ },
464+ {
465+ name : "reading-intersection" ,
466+ fixtureDir : "reading" ,
467+ filterQuery : "./apps/**|reading=shared.hcl" , // Our testing arg parsing is busted. Don't put whitespace between these.
468+ expectedOutput : "apps/app1\n apps/app2\n " ,
469+ },
437470 }
438471
439472 // Run all test cases
@@ -650,6 +683,77 @@ func generateUnionFixture(t *testing.T, baseDir string) {
650683 createTerragruntStack (t , filepath .Join (rootDir , "dev" , "stack2" ))
651684}
652685
686+ func generateReadingFixture (t * testing.T , baseDir string ) {
687+ rootDir := filepath .Join (baseDir , "reading" , "root" )
688+ require .NoError (t , os .MkdirAll (rootDir , 0755 ))
689+
690+ // Create shared configuration files
691+ require .NoError (t , os .WriteFile (filepath .Join (rootDir , "shared.hcl" ), []byte (`
692+ locals {
693+ common_value = "shared"
694+ }
695+ ` ), 0644 ))
696+
697+ require .NoError (t , os .WriteFile (filepath .Join (rootDir , "shared.tfvars" ), []byte (`
698+ test_var = "value"
699+ ` ), 0644 ))
700+
701+ commonDir := filepath .Join (rootDir , "common" )
702+ require .NoError (t , os .MkdirAll (commonDir , 0755 ))
703+ require .NoError (t , os .WriteFile (filepath .Join (commonDir , "vars.hcl" ), []byte (`
704+ locals {
705+ vpc_cidr = "10.0.0.0/16"
706+ }
707+ ` ), 0644 ))
708+
709+ // Create apps/app1 - reads shared.hcl
710+ app1Dir := filepath .Join (rootDir , "apps" , "app1" )
711+ require .NoError (t , os .MkdirAll (app1Dir , 0755 ))
712+ require .NoError (t , os .WriteFile (filepath .Join (app1Dir , "terragrunt.hcl" ), []byte (`
713+ locals {
714+ shared = read_terragrunt_config("../../shared.hcl")
715+ }
716+
717+ terraform {
718+ source = "."
719+ }
720+ ` ), 0644 ))
721+ require .NoError (t , os .WriteFile (filepath .Join (app1Dir , "main.tf" ), []byte ("" ), 0644 ))
722+
723+ // Create apps/app2 - reads shared.hcl and shared.tfvars
724+ app2Dir := filepath .Join (rootDir , "apps" , "app2" )
725+ require .NoError (t , os .MkdirAll (app2Dir , 0755 ))
726+ require .NoError (t , os .WriteFile (filepath .Join (app2Dir , "terragrunt.hcl" ), []byte (`
727+ locals {
728+ shared = read_terragrunt_config("../../shared.hcl")
729+ vars = read_tfvars_file("../../shared.tfvars")
730+ }
731+
732+ terraform {
733+ source = "."
734+ }
735+ ` ), 0644 ))
736+ require .NoError (t , os .WriteFile (filepath .Join (app2Dir , "main.tf" ), []byte ("" ), 0644 ))
737+
738+ // Create apps/app3 - reads common/vars.hcl
739+ app3Dir := filepath .Join (rootDir , "apps" , "app3" )
740+ require .NoError (t , os .MkdirAll (app3Dir , 0755 ))
741+ require .NoError (t , os .WriteFile (filepath .Join (app3Dir , "terragrunt.hcl" ), []byte (`
742+ locals {
743+ common = read_terragrunt_config("../../common/vars.hcl")
744+ }
745+
746+ terraform {
747+ source = "."
748+ }
749+ ` ), 0644 ))
750+ require .NoError (t , os .WriteFile (filepath .Join (app3Dir , "main.tf" ), []byte ("" ), 0644 ))
751+
752+ // Create libs/lib1 - doesn't read any files
753+ lib1Dir := filepath .Join (rootDir , "libs" , "lib1" )
754+ createTerragruntUnit (t , lib1Dir )
755+ }
756+
653757// Helper functions to create Terragrunt configuration files
654758
655759func createTerragruntUnit (t * testing.T , dir string ) {
0 commit comments