Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy validated Terraform to /tmp to avoid conflict #935

Merged
merged 3 commits into from
Jun 19, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion modules/terraform/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package terraform
import (
// We alias Golang's native testing package to go_test to avoid naming conflicts with terratest's own testing module

"path/filepath"
go_test "testing"

"github.com/gruntwork-io/terratest/modules/files"
"github.com/gruntwork-io/terratest/modules/testing"
"github.com/stretchr/testify/require"
)
Expand All @@ -24,7 +26,12 @@ func ValidateAllTerraformModules(t *go_test.T, opts *ValidationOptions) {
dir := dir
t.Run(dir, func(t *go_test.T) {
t.Parallel()
tfOpts := &Options{TerraformDir: dir}

//Copy the module to a tmp directory to avoid conflicts with tests that don't copy to /tmp
testFolder, err := files.CopyTerraformFolderToTemp(opts.RootDir, filepath.Base(dir))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that, due to an import cycle error, I had to use the files package's CopyTerraformFolderToTemp method. test_structure imports the terraform package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this logic correct? I think this is wrong for cases where there is a subdir (e.g., modules/agents/cloudwatch-agent).

I think you need to use filepath.Rel here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Revised as discussed.

require.NoError(t, err)

tfOpts := &Options{TerraformDir: testFolder}
InitAndValidate(t, tfOpts)
})
}
Expand Down