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

Add terraform version command #1016

Merged
merged 9 commits into from
Aug 2, 2022
Merged

Add terraform version command #1016

merged 9 commits into from
Aug 2, 2022

Conversation

jpogran
Copy link
Contributor

@jpogran jpogran commented Jul 26, 2022

This commit adds a new module.terraform command which returns the required and discovered version of Terraform in the currrent workspace.

@jpogran jpogran added the enhancement New feature or request label Jul 26, 2022
@jpogran jpogran self-assigned this Jul 26, 2022
This commit adds a new `module.terraform` command which returns the required and discovered version of Terraform in the currrent workspace.
@jpogran jpogran marked this pull request as ready for review July 27, 2022 14:23
@jpogran jpogran requested a review from a team as a code owner July 27, 2022 14:23
@radeksimko radeksimko added this to the v0.29.0 milestone Jul 27, 2022
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

Aside from my in-line comments, do you mind adding a test for this new command?

Feel free to look into https://github.com/hashicorp/terraform-ls/blob/main/internal/langserver/handlers/execute_command_module_providers_test.go for some inspiration.

internal/langserver/handlers/command/terraform.go Outdated Show resolved Hide resolved
internal/langserver/handlers/command/terraform.go Outdated Show resolved Hide resolved
@jpogran
Copy link
Contributor Author

jpogran commented Jul 29, 2022

What's more important however is that we notify the client when this changes - see how we already do this for module.providers and module.calls.

This ticket is targeting hashicorp/vscode-terraform#697, which points to #69 for detecting and tracking when the version changes. Should we tackle both work items in this PR, or just the original ticket?

@radeksimko
Copy link
Member

Good question!

So I think for the Terraform version in particular, until #69 is addressed, it won't change, but the version requirements which are parsed from the configuration may change at any time - so for those I think we should send the updates.

response.RequiredVersion = mod.Meta.CoreRequirements.String()
}

progress.Report(ctx, "Sending response ...")
Copy link
Member

Choose a reason for hiding this comment

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

Since this is getting the data from memory, it should be pretty quick (definitely sub-second, low milliseconds in most cases), so I'm not sure there's much value in the progress reporting for this particular command?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The method is a no-op if a token isn't provided in the request, so this technically doesn't do anything yet.

My thinking along this lines is that we enable progress information everywhere as we go, instead of having to add when there's a problem. Then we can dial back if it's too much.

@radeksimko
Copy link
Member

radeksimko commented Jul 29, 2022

Thank you for adding the test - that looks good - we could possibly deal with the data updates in a separate PR, if you wish.

One thing we should still do however is to document this new command here https://github.com/hashicorp/terraform-ls/blob/main/docs/commands.md

@jpogran
Copy link
Contributor Author

jpogran commented Aug 1, 2022

Version change notification added and docs updated

Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

I'm half wondering if the refresh command should be called refreshModuleTerraform, to indicate that it's related to the module.terraform, which in turn exposes more than just a Terraform version, however I'm also happy to keep it as is while we figure out what exact data and in what exact shape do we want to expose. 😃

👍🏻

docs/commands.md Outdated Show resolved Hide resolved
@@ -463,6 +463,10 @@ func (svc *service) configureSessionDependencies(ctx context.Context, cfgOpts *s
moduleHooks = append(moduleHooks, callRefreshClientCommand(svc.server, commandId))
}

if commandId, ok := lsp.ExperimentalClientCapabilities(cc.Experimental).RefreshTerraformVersionCommandId(); ok {
moduleHooks = append(moduleHooks, callRefreshClientCommand(svc.server, commandId))
}
Copy link
Member

Choose a reason for hiding this comment

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

I think in the long run we'll probably want to create a separate hook which only fires when the data exposed through each command changes (not just any data), but this is 🆗 for now, since the other two refresh commands above have the exact same problem.

Co-authored-by: Radek Simko <radek.simko@gmail.com>
@jpogran jpogran merged commit 1d16fc6 into main Aug 2, 2022
@jpogran jpogran deleted the terraform_version_command branch August 2, 2022 13:43
@jpogran jpogran linked an issue Aug 2, 2022 that may be closed by this pull request
1 task
@github-actions
Copy link

github-actions bot commented Sep 2, 2022

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce module.terraform command to expose details about Terraform installation
2 participants