Skip to content

Commit

Permalink
Merge pull request #56 from gruntwork-io/copy-terraform-folder
Browse files Browse the repository at this point in the history
Add copy terraform folder that works with stages
  • Loading branch information
brikis98 authored Mar 4, 2018
2 parents 052fea9 + cf25ff3 commit b2cfd06
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test-structure/test_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,27 @@ func CleanupTestData(t *testing.T, path string, logger *log.Logger) {
} else {
logger.Printf("%s does not exist. Nothing to cleanup.", path)
}
}

// Copy the given root folder to a randomly-named temp folder and return the path to the given examples folder within
// the new temp root folder. This is useful when running multiple tests in parallel against the same set of Terraform
// files to ensure the tests don't overwrite each other's .terraform working directory and terraform.tfstate files. To
// ensure relative paths work, we copy over the entire root folder to a temp folder, and then return the path within
// that temp folder to the given example dir, which is where the actual test will be running.
//
// Note that if any of the SKIP_<stage> environment variables is set, we assume this is a test in the local dev where
// there are no other concurrent tests running and we want to be able to cache test data between test stages, so in
// that case, we do NOT copy anything to a temp folder, an dreturn the path to the original examples folder instead.
func CopyTerraformFolderToTemp(t *testing.T, rootFolder string, examplesFolder string, testName string, logger *log.Logger) string {
if SkipStageEnvVarSet() {
logger.Printf("A SKIP_XXX environment variable is set. Using original examples folder rather than a temp folder so we can cache data between stages for faster local testing.")
return filepath.Join(rootFolder, examplesFolder)
}

tmpRootFolder, err := files.CopyTerraformFolderToTemp(rootFolder, testName)
if err != nil {
t.Fatal(err)
}

return filepath.Join(tmpRootFolder, examplesFolder)
}

0 comments on commit b2cfd06

Please sign in to comment.