File tree 3 files changed +44
-2
lines changed
langserver/handlers/command
3 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -129,5 +129,6 @@ func getModuleDocumentationLink(record datadir.ModuleRecord) string {
129
129
return ""
130
130
}
131
131
132
- return fmt .Sprintf (`https://registry.terraform.io/modules/%s/%s` , record .SourceAddr , record .VersionStr )
132
+ shortName := strings .TrimPrefix (record .SourceAddr , "registry.terraform.io/" )
133
+ return fmt .Sprintf (`https://registry.terraform.io/modules/%s/%s` , shortName , record .VersionStr )
133
134
}
Original file line number Diff line number Diff line change @@ -87,3 +87,42 @@ func Test_parseModuleRecords(t *testing.T) {
87
87
})
88
88
}
89
89
}
90
+
91
+ // With the release of Terraform 1.1.0 module source addresses are now stored normalized
92
+ func Test_parseModuleRecords_v1_1 (t * testing.T ) {
93
+ tests := []struct {
94
+ name string
95
+ records []datadir.ModuleRecord
96
+ want []moduleCall
97
+ }{
98
+ {
99
+ name : "detects terraform module types" ,
100
+ records : []datadir.ModuleRecord {
101
+ {
102
+ Key : "ec2_instances" ,
103
+ SourceAddr : "registry.terraform.io/terraform-aws-modules/ec2-instance/aws" ,
104
+ VersionStr : "2.12.0" ,
105
+ Dir : ".terraform\\ modules\\ ec2_instances" ,
106
+ },
107
+ },
108
+ want : []moduleCall {
109
+ {
110
+ Name : "ec2_instances" ,
111
+ SourceAddr : "registry.terraform.io/terraform-aws-modules/ec2-instance/aws" ,
112
+ Version : "2.12.0" ,
113
+ SourceType : "tfregistry" ,
114
+ DocsLink : "https://registry.terraform.io/modules/terraform-aws-modules/ec2-instance/aws/2.12.0" ,
115
+ DependentModules : []moduleCall {},
116
+ },
117
+ },
118
+ },
119
+ }
120
+ for _ , tt := range tests {
121
+ t .Run (tt .name , func (t * testing.T ) {
122
+ got := parseModuleRecords (tt .records )
123
+ if diff := cmp .Diff (tt .want , got ); diff != "" {
124
+ t .Fatalf ("module mismatch: %s" , diff )
125
+ }
126
+ })
127
+ }
128
+ }
Original file line number Diff line number Diff line change @@ -34,7 +34,9 @@ func (r *ModuleRecord) GetModuleType() ModuleType {
34
34
// the authorative source: hashicorp/terraform/internal/addrs/module_source.go.
35
35
// However this works enough for now to identify module types for display in vscode-terraform.
36
36
// Example: terraform-aws-modules/ec2-instance/aws
37
- if _ , err := tfregistry .ParseRawProviderSourceString (r .SourceAddr ); err == nil {
37
+ _ , err := tfregistry .ParseRawProviderSourceString (r .SourceAddr )
38
+ // Example: registry.terraform.io/terraform-aws-modules/vpc/aws
39
+ if err == nil || strings .HasPrefix (r .SourceAddr , "registry.terraform.io/" ) {
38
40
return TFREGISTRY
39
41
}
40
42
You can’t perform that action at this time.
0 commit comments