Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Download default terraform version when minor version mismatches#1775

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
AbhineetJain merged 12 commits intomainfromabhineetjain/default-terraform-version
Jun 22, 2022

Conversation

AbhineetJain
Copy link
Contributor

@AbhineetJainAbhineetJain commentedMay 26, 2022
edited
Loading

This PR downloads the default Terraform version when the minor version of the already installed Terraform is different.

Subtasks

  • Identify the installed version by parsingterraform version.
  • Download the default version if there's a mismatch or we can't identify the version.
  • Add unit tests for the feature.

Fixes#1743

Comment on lines 56 to 72
// If the "coder" binary is in the same directory as
// the "terraform" binary, "terraform" is returned.
//
// We must resolve the absolute path for other processes
// to execute this properly!
absoluteBinary, err := filepath.Abs(binaryPath)
if err != nil {
return xerrors.Errorf("absolute: %w", err)
}
// Checking the installed version of Terraform.
output, err := exec.Command(absoluteBinary, "version").Output()
if err != nil {
return xerrors.Errorf("terraform version: %w", err)
}
// The output for `terraform version` is:
// Terraform v1.2.1
// on linux_amd64
versionRegex := regexp.MustCompile("Terraform v(.+)\n?.*")
match := versionRegex.FindStringSubmatch(string(output))
if match != nil {
// match[0] is the entire string.
// match[1] is the matched substring.
version := match[1]
terraformMinorVersion := strings.Join(strings.Split(terraformVersion, versionDelimiter)[:2], versionDelimiter)
if !strings.HasPrefix(version, terraformMinorVersion) {
downloadTerraform = true
}
} else {
// Download the required Terraform version when unable to determine the existing one.
downloadTerraform = true
}
if !downloadTerraform {
options.BinaryPath = absoluteBinary
}
Copy link
Member

Choose a reason for hiding this comment

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

Theterraform-exec library already handles most of this for us!

https://github.com/coder/coder/blob/main/provisioner/terraform/provision.go#L63-L70

@ammario
Copy link
Member

What is the status of this PR?

@AbhineetJain
Copy link
ContributorAuthor

What is the status of this PR?

@ammario Got stuck in limbo as I moved onto some frontend changes. I am back to addressing the comments on it this week; we should be able to get it in by EOW.

ammario reacted with thumbs up emoji

@AbhineetJainAbhineetJainforce-pushed theabhineetjain/default-terraform-version branch from07c6480 to91fd183CompareJune 17, 2022 15:45
@AbhineetJainAbhineetJain marked this pull request as ready for reviewJune 17, 2022 16:39
@AbhineetJainAbhineetJainforce-pushed theabhineetjain/default-terraform-version branch from91fd183 toccddf23CompareJune 17, 2022 19:08
Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

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

Looks good, beautiful tests 😉!

AbhineetJain reacted with hooray emojiAbhineetJain reacted with heart emoji
Comment on lines 93 to 96

t.Cleanup(func() {
t.Setenv("PATH", pathVariable)
})
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
t.Cleanup(func() {
t.Setenv("PATH",pathVariable)
})

I don't think this is needed?t.Setenv already defines a cleanup function that restores the environment in the earlier step.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Removed it along with the top levelt.Parallel since this test was conflicting with some other tests.

mafredri reacted with thumbs up emoji
@AbhineetJainAbhineetJainforce-pushed theabhineetjain/default-terraform-version branch 2 times, most recently fromcad1205 to7964593CompareJune 21, 2022 14:45
Copy link
Member

@kylecarbskylecarbs left a comment

Choose a reason for hiding this comment

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

Nice!

@@ -41,33 +43,54 @@ type ServeOptions struct {
Logger slog.Logger
}

func getAbsoluteBinaryPath(ctx context.Context) (string, bool) {
Copy link
Member

Choose a reason for hiding this comment

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

Following Go idioms, thisget prefix could be removed!

AbhineetJain reacted with thumbs up emoji
@AbhineetJainAbhineetJainforce-pushed theabhineetjain/default-terraform-version branch 4 times, most recently fromed969f2 to4580e8cCompareJune 22, 2022 19:02
@AbhineetJainAbhineetJainforce-pushed theabhineetjain/default-terraform-version branch from4580e8c to744052fCompareJune 22, 2022 21:03
@AbhineetJainAbhineetJainforce-pushed theabhineetjain/default-terraform-version branch from744052f to6b84a73CompareJune 22, 2022 22:09
@AbhineetJainAbhineetJainenabled auto-merge (squash)June 22, 2022 22:58
@AbhineetJainAbhineetJain merged commitc6b1daa intomainJun 22, 2022
@AbhineetJainAbhineetJain deleted the abhineetjain/default-terraform-version branchJune 22, 2022 23:11
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mafredrimafredrimafredri approved these changes

@EmyrkEmyrkEmyrk approved these changes

@kylecarbskylecarbskylecarbs approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Default to downloading Terraform when the system has different minor version
5 participants
@AbhineetJain@ammario@mafredri@Emyrk@kylecarbs

[8]ページ先頭

©2009-2025 Movatter.jp