-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
modules/terraform/validate.go
Outdated
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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Revised as discussed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM assuming the test
build passes (you can ignore the failing gcp_test
). I had two nits, but they can be addressed in a subsequent PR.
Make sure to cut a backward incompatible release when you release this!
// Excludes any folders specified in the ValidationOptions.ExcludeDirs. IncludeDirs will take precedence over ExcludeDirs | ||
// Use the NewValidationOptions method to pass relative paths for either of these options to have the full paths built | ||
// Note that go_test is an alias to Golang's native testing package created to avoid naming conflicts with Terratest's | ||
// own testing package. We are using the native testing.T here because Terratest's testing.T struct does not implement Run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Mention that the this is here instead of terraform
module to avoid import cycling.
@@ -1,4 +1,4 @@ | |||
package terraform | |||
package test_structure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Mention in the function docs that this is here instead of terraform
module to avoid import cycling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: This file should probably still be called validate_struct.go
, given the contents.
Thanks for the review! Going to merge this in now but will address your nits in a follow-up PR. |
/tmp
first, which can lead to conflicts whenValidateAllTerraformModules
is called/tmp
FindTerraformModulePathsInRootE
to return.terraform
hidden directories, leading to duplicate work and possible false positives.