@@ -3307,6 +3307,66 @@ func TestReadTerragruntAuthProviderCmdEnvInLocalsRunAll(t *testing.T) {
33073307 assert .Equal (t , "from-auth-provider" , outputs ["secret" ].Value )
33083308}
33093309
3310+ func TestReadTerragruntAuthProviderCmdRunAllCallCountWithRacing (t * testing.T ) {
3311+ t .Parallel ()
3312+
3313+ helpers .CleanupTerraformFolder (t , testFixtureAuthProviderCmd )
3314+ tmpEnvPath := helpers .CopyEnvironment (t , testFixtureAuthProviderCmd )
3315+ rootPath := filepath .Join (tmpEnvPath , testFixtureAuthProviderCmd , "run-all-call-count" )
3316+ authProviderCmd := filepath .Join (rootPath , "auth-provider.sh" )
3317+ logPath := filepath .Join (rootPath , "calls.jsonl" )
3318+
3319+ helpers .ValidateAuthProviderScript (t , rootPath , authProviderCmd )
3320+ require .NoError (t , os .Remove (logPath ), "auth-provider.sh should have created %s" , logPath )
3321+
3322+ helpers .RunTerragrunt (
3323+ t ,
3324+ fmt .Sprintf (
3325+ "terragrunt run --all apply --non-interactive " +
3326+ "--working-dir %s --auth-provider-cmd %s" ,
3327+ rootPath ,
3328+ authProviderCmd ,
3329+ ),
3330+ )
3331+
3332+ logBytes , err := os .ReadFile (logPath )
3333+ require .NoError (t , err )
3334+
3335+ type authCall struct {
3336+ Timestamp string `json:"ts"`
3337+ WorkingDir string `json:"working_dir"`
3338+ PID int `json:"pid"`
3339+ }
3340+
3341+ lines := strings .Split (strings .TrimRight (string (logBytes ), "\n " ), "\n " )
3342+ calls := make ([]authCall , 0 , len (lines ))
3343+
3344+ for i , line := range lines {
3345+ var call authCall
3346+
3347+ require .NoErrorf (t , json .Unmarshal ([]byte (line ), & call ), "line %d: %q" , i + 1 , line )
3348+
3349+ calls = append (calls , call )
3350+ }
3351+
3352+ t .Logf ("auth-provider-cmd invocations:\n %s" , string (logBytes ))
3353+
3354+ // Five invocations are expected, in this order:
3355+ //
3356+ // 1. Discovery relationship phase parses `dep`.
3357+ // 2. Discovery relationship phase parses `dependent`.
3358+ // 3. Runner pool task parses `dep`for apply.
3359+ // 4. Runner pool task parses `dependent` for apply.
3360+ // 5. While `dependent`'s HCL is being decoded, the `dependency.dep`
3361+ // block fetches `dep`'s outputs, which requires parsing `dep` again.
3362+ //
3363+ assert .Len (t , calls , 5 )
3364+
3365+ for _ , call := range calls {
3366+ assert .NotContains (t , call .WorkingDir , ".terragrunt-cache" )
3367+ }
3368+ }
3369+
33103370func TestIamRolesLoadingFromDifferentModules (t * testing.T ) {
33113371 t .Parallel ()
33123372
0 commit comments