diff --git a/modules/files/files.go b/modules/files/files.go index a93b2ac5f..2eed76e4e 100644 --- a/modules/files/files.go +++ b/modules/files/files.go @@ -43,12 +43,12 @@ func IsExistingDir(path string) bool { // 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. This method returns // the path to the dest folder with the copied contents. Hidden files and folders (with the exception of the `.terraform-version` files used -// by the [tfenv tool](https://github.com/tfutils/tfenv)), Terraform state files, and terraform.tfvars files are not copied to this temp folder, -// as you typically don't want them interfering with your tests. +// by the [tfenv tool](https://github.com/tfutils/tfenv) and `.terraform.lock.hcl` used by Terraform to lock providers versions), Terraform state +// files, and terraform.tfvars files are not copied to this temp folder, as you typically don't want them interfering with your tests. // This method is useful when running through a build tool so the files are copied to a destination that is cleaned on each run of the pipeline. func CopyTerraformFolderToDest(folderPath string, destRootFolder string, tempFolderPrefix string) (string, error) { filter := func(path string) bool { - if PathIsTerraformVersionFile(path) { + if PathIsTerraformVersionFile(path) || PathIsTerraformLockFile(path) { return true } if PathContainsHiddenFileOrFolder(path) || PathContainsTerraformStateOrVars(path) { @@ -211,6 +211,11 @@ func PathIsTerraformVersionFile(path string) bool { return filepath.Base(path) == ".terraform-version" } +// PathIsTerraformLockFile return true if the given path is the special '.terraform.lock.hcl' file used by Terraform to lock providers versions +func PathIsTerraformLockFile(path string) bool { + return filepath.Base(path) == ".terraform.lock.hcl" +} + // CopyFile copies a file from source to destination. func CopyFile(source string, destination string) error { contents, err := ioutil.ReadFile(source)