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

Fix module calls command for remote modules #872

Merged
merged 4 commits into from
Apr 14, 2022
Merged

Conversation

dbanck
Copy link
Member

@dbanck dbanck commented Apr 13, 2022

With the release of Terraform 1.1.0 module source addresses are now stored normalized:

config: Terraform now checks the syntax of and normalizes module source addresses (the source argument in module blocks) during configuration decoding rather than only at module installation time. This is largely just an internal refactoring, but a visible benefit of this change is that the terraform init messages about module downloading will now show the canonical module package address Terraform is downloading from, after interpreting the special shorthands for common cases like GitHub URLs. (hashicorp/terraform#28854)


With this change it's not possible anymore to identify remote modules using ParseRawProviderSourceString.

This PR updates the module source detection for remote modules and with this reenables 'Open Documentation' and displays the correct icon in the extension UI.

Before

2022/04/13 14:58:51 rpc_logger.go:50: Response to "workspace/executeCommand" (ID 73): {"v":0,"module_calls":[{"name":"vpc","source_addr":"registry.terraform.io/terraform-aws-modules/vpc/aws","version":"3.14.0","source_type":"unknown","dependent_modules":[]}]}

After

2022/04/13 15:05:19 rpc_logger.go:50: Response to "workspace/executeCommand" (ID 11): {"v":0,"module_calls":[{"name":"vpc","source_addr":"registry.terraform.io/terraform-aws-modules/vpc/aws","version":"3.14.0","source_type":"tfregistry","docs_link":"https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/3.14.0","dependent_modules":[]}]}

@dbanck dbanck added the bug Something isn't working label Apr 13, 2022
@dbanck dbanck added this to the v0.27.0 milestone Apr 13, 2022
@dbanck dbanck self-assigned this Apr 13, 2022
@dbanck dbanck requested a review from a team as a code owner April 13, 2022 13:28
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.

Thanks for finding the bug and raising a PR to fix it! 🙏🏻

I'm wondering if we should improve our testing strategy around the data in .terraform and have some E2E tests which generate modules.json and other files with the latest Terraform and run that nightly or something... Certainly not something I'm asking you to do as part of this PR - just thinking out loud.


Given that we need to support older versions of Terraform too (< 1.1.0), I think we should keep testing for the old format and ensure that is still handled correctly. I guess that also means using something like strings.HasPrefix(...) || tfregistry.ParseRawProviderSourceString(...) for the detection?

Ideally a future tfregistry.ParseRawModuleSourceString would account for both cases, but I'm not sure how much effort it would be to implement that. Last time I checked TF core, it didn't look as trivial as I hoped and there were some edge cases.

@dbanck
Copy link
Member Author

dbanck commented Apr 14, 2022

Thanks for your review!

I've reverted some changes to keep tfregistry.ParseRawProviderSourceString for older versions of Terraform. I'm hoping to update this implementation with something based on ParseRawModuleSourceString soon.

@dbanck dbanck requested a review from radeksimko April 14, 2022 13:41
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.

Just one question about tests - otherwise LGTM

@@ -18,7 +18,7 @@ func Test_parseModuleRecords(t *testing.T) {
records: []datadir.ModuleRecord{
{
Key: "ec2_instances",
SourceAddr: "terraform-aws-modules/ec2-instance/aws",
SourceAddr: "registry.terraform.io/terraform-aws-modules/ec2-instance/aws",
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind adding this as a separate test case, e.g. Test_parseModuleRecords_v1_1 ? Just to make sure we keep testing for both old and new format.

Copy link
Member Author

Choose a reason for hiding this comment

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

We have an entry in our test table below for terraform-aws-modules/eks/aws,but I can create a separate test case as well.

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.

LGTM, thank you for the quick turn around! :shipit:

@dbanck dbanck merged commit 94aa1d8 into main Apr 14, 2022
@dbanck dbanck deleted the b-fix-module-calls branch April 14, 2022 14:25
@github-actions
Copy link

This functionality has been released in v0.27.0 of the language server.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

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 May 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants