Skip to content

Can't find dynamic generated plan output for recipes/modules running in parallel #17

@Excoriate

Description

@Excoriate

🪲 Describe the Bug

When running in parallel, different subdirectories under the 'recipes' or examples directories, it can't find the dynamically generated plan output file

=== RUN   TestRecipesLifecycle/advanced
=== PAUSE TestRecipesLifecycle/advanced
=== CONT  TestRecipesLifecycle/advanced
    dirs.go:24: The git repo root is /Users/alex.torres@mambu.com/@code/@mambu-gitlab/@clonned/mambucom/product/sre/infrastructure/builder-experience/iac-framework/brainiac-iac-catalog/granular-aws-db
    client.go:200: Setting Terraform variable files: [fixtures/fixtures.tfvars]
    stage.go:43: 
        	Error Trace:	/Users/alex.torres@mambu.com/go/pkg/mod/github.com/!excoriate/tftest@v0.0.10/pkg/scenario/stage.go:43
        	            				/Users/alex.torres@mambu.com/@code/@mambu-gitlab/@clonned/mambucom/product/sre/infrastructure/builder-experience/iac-framework/brainiac-iac-catalog/granular-aws-db/tests/db-subnet-group/recipes/recipes_lifecycle_test.go:21
        	Error:      	Received unexpected error:
        	            	FatalError{Underlying: error while running command: exit status 1; 
        	            	Error: Failed to load "plan.out" as a plan file
        	            	
        	            	Error: stat plan.out: no such file or directory}
        	Test:       	TestRecipesLifecycle/advanced
        	Messages:   	Failed to apply terraform: 
        	            	Error: Failed to load "plan.out" as a plan file
        	            	
        	            	Error: stat plan.out: no such file or directory
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: - Installed hashicorp/aws v4.67.0 (signed by HashiCorp)
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: 
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: Terraform has been successfully initialized!
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: 
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: You may now begin working with Terraform. Try running "terraform plan" to see
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: any changes that are required for your infrastructure. All Terraform commands
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: should now work.
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: 
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: If you ever set or change modules or backend configuration for Terraform,
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: rerun this command to reinitialize your working directory. If you forget, other
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: commands will detect it and remind you to do so if necessary.
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 retry.go:91: terraform [apply -input=false -auto-approve -no-color -lock=false plan.out]
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: Running command terraform with args [apply -input=false -auto-approve -no-color -lock=false plan.out]
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: 
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: Error: Failed to load "plan.out" as a plan file
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: 
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 logger.go:66: Error: stat plan.out: no such file or directory
TestRecipesLifecycle/elasticache-filtered-subnets 2024-04-08T11:25:17+02:00 retry.go:99: Returning due to fatal error: FatalError{Underlying: error while running command: exit status 1; 
Error: Failed to load "plan.out" as a plan file

Error: stat plan.out: no such file or directory}
    --- FAIL: TestRecipesLifecycle/advanced (9.11s)

Example code

func TestRecipesLifecycle(t *testing.T) {
	for _, recipe := range recipes {
		t.Run(recipe, func(t *testing.T) {
			tfVarFile := filepath.Join(fixtureDir, "fixtures.tfvars")
			t.Parallel()
			workdir := filepath.Join(recipeDir, recipe)
			s, err := scenario.NewWithOptions(t, workdir, scenario.WithVarFiles(workdir, tfVarFile), scenario.WithParallel())

			assert.NoErrorf(t, err, "Failed to create scenario: %s", err)

			s.Stg.ApplyStage(t, s.GetTerraformOptions())
		})
	}
}

With a configuration that iterates over multiple recipes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is not working fine 🐛.

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions