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

Updated CopyTerraformFolderToTemp to include .terraform-version file #963

Conversation

yardbirdsax
Copy link
Contributor

The CopyTerraformFolderToTemp method will now copy the '.terraform-version' file if it exists in the source folder. This adds support for users who use the 'tfenv' tool to enforce that a certain version of Terraform is used in deployments and testing. This fixes #962.

The output of the unit tests is available here. Please note: I only ran the unit tests for the module containing the code I changed.

Thanks for your consideration!

The CopyTerraformFolderToTemp method will now copy the '.terraform-version' file if it exists in the source folder. This adds support for users who use the 'tfenv' tool to enforce that a certain version of Terraform is used in deployments and testing.
The .terraform-version file has been added to the 'full-copy' folder to resolve a failing unit test.
Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Comment on lines 178 to 183
pathParts := strings.Split(path, string(filepath.Separator))
for _, pathPart := range pathParts {
if strings.Contains(pathPart, ".terraform-version") {
return true
}
}
Copy link
Member

Choose a reason for hiding this comment

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

NIT: If .terraform-version is a file, wouldn't it be the final part of the path? And if so, could this be simplified to filepath.Base(path) == ".terraform-version"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

func CopyTerraformFolderToTemp(folderPath string, tempFolderPrefix string) (string, error) {
filter := func(path string) bool {
return !PathContainsHiddenFileOrFolder(path) && !PathContainsTerraformStateOrVars(path)
return (!PathContainsHiddenFileOrFolder(path) || PathIsTerraformVersionFile(path)) && !PathContainsTerraformStateOrVars(path)
Copy link
Member

Choose a reason for hiding this comment

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

NIT: this is getting hard to read / reason about with all the nots, ors, etc. Perhaps two lines will be easier to read?

if PathIsTerraformVersionFile(path) {
  return true
} else if PathContainsHiddenFileOrFolder(path) || PathContainsTerraformStateOrVars(path) {
  return false
} else {
  return true
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed with a slight modification to match the guidelines.

@yardbirdsax
Copy link
Contributor Author

Thanks for the review @brikis98 ! I made some corrections based on your comments and pushed the changes. The unit tests still succeed fine.

brikis98
brikis98 previously approved these changes Aug 19, 2021
Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! I'll kick off tests now.

@brikis98
Copy link
Member

Looks like pre-commit checks failed:

goimports................................................................Failed
- hook id: goimports
- files were modified by this hook

modules/files/files.go

Please run goimports!

@yardbirdsax
Copy link
Contributor Author

Whoops! Sorry about that, I re-ran it and pushed the branch again. Seems like my pre-commit install didn't work for some reason.

Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. Lost track of this one. I'll kick off tests again!

@brikis98
Copy link
Member

Hm, some tests are failing, and continue to fail on re-run, so it's not clear this is some transient issue. I'll have to come back to this to look into it to see if it's related to this PR or not.

@yardbirdsax
Copy link
Contributor Author

Yeah I saw that, which is very odd. If I have time I may run the tests locally both on the trunk branch and mine as well.

@brikis98
Copy link
Member

My apologies, I've been super buried, and completely lost track of this one. @infraredgirl Would you mind taking a look at the test failures here and seeing if they are relevant or if this is OK to merge?

@infraredgirl
Copy link
Contributor

I re-ran the tests, and the results are as follows:

  • 3 flaky GPC tests are failing with the following errror: Error resolving image name 'ubuntu-os-cloud/ubuntu-1604-lts': Could not find image or family ubuntu-os-cloud/ubuntu-1604-lts. This is obviously unrelated to this change.
  • TestGitRefChecks/GetCurrentRefReturnsLightTagValue has a failure that was fixed on master in the mean time.

Given the above, I'll go ahead and merge this PR. Thanks @yardbirdsax for your contribution and your patience!

@infraredgirl infraredgirl merged commit f4f2459 into gruntwork-io:master Dec 10, 2021
@infraredgirl
Copy link
Contributor

@yardbirdsax yardbirdsax deleted the feature/include-terraform-version-file branch December 20, 2021 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include '.terraform-version' file when copying Terraform folder to temporary location
3 participants