Skip to content

Commit decc54b

Browse files
committed
bump tfschema to 08c17f04e2bc & account for upstream changes
Checking MetaState in (ModuleStore).LocalModuleMeta prevents a possible race condition where terraform-schema would otherwise build out module schema just because the module entry is present, but metadata was not parsed yet.
1 parent d0fa017 commit decc54b

9 files changed

+56
-37
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/hashicorp/terraform-exec v0.17.2
2020
github.com/hashicorp/terraform-json v0.14.0
2121
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c
22-
github.com/hashicorp/terraform-schema v0.0.0-20220708122804-408b2aefd4d6
22+
github.com/hashicorp/terraform-schema v0.0.0-20220712135911-08c17f04e2bc
2323
github.com/kylelemons/godebug v1.1.0 // indirect
2424
github.com/mh-cbon/go-fmt-fail v0.0.0-20160815164508-67765b3fbcb5
2525
github.com/mitchellh/cli v1.1.4

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ github.com/hashicorp/terraform-json v0.14.0 h1:sh9iZ1Y8IFJLx+xQiKHGud6/TSUCM0N8e
339339
github.com/hashicorp/terraform-json v0.14.0/go.mod h1:5A9HIWPkk4e5aeeXIBbkcOvaZbIYnAIkEyqP2pNSckM=
340340
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c h1:D8aRO6+mTqHfLsK/BC3j5OAoogv1WLRWzY1AaTo3rBg=
341341
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c/go.mod h1:Wn3Na71knbXc1G8Lh+yu/dQWWJeFQEpDeJMtWMtlmNI=
342-
github.com/hashicorp/terraform-schema v0.0.0-20220708122804-408b2aefd4d6 h1:nyYG4twPkXiAUnLSgF5HfhKUGNp3rErv2sYOS2bDsZY=
343-
github.com/hashicorp/terraform-schema v0.0.0-20220708122804-408b2aefd4d6/go.mod h1:GL+zHwXHrTc/MfKnQP8K2Z4hmaTck85ndiIbvZueMng=
342+
github.com/hashicorp/terraform-schema v0.0.0-20220712135911-08c17f04e2bc h1:08Pp12m9Rv4cQgk2GOlkoG6njaiAyCR+rKDpdrgvlVs=
343+
github.com/hashicorp/terraform-schema v0.0.0-20220712135911-08c17f04e2bc/go.mod h1:GL+zHwXHrTc/MfKnQP8K2Z4hmaTck85ndiIbvZueMng=
344344
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
345345
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
346346
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=

internal/cmd/inspect_module_command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func formatModuleRecords(mds []datadir.ModuleRecord) []string {
199199
continue
200200
}
201201
if m.IsExternal() {
202-
out = append(out, "EXTERNAL(%s)", m.SourceAddr)
202+
out = append(out, "EXTERNAL(%s)", m.SourceAddr.String())
203203
continue
204204
}
205205
out = append(out, fmt.Sprintf("%s (%s)", m.Dir, m.SourceAddr))

internal/state/module.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package state
22

33
import (
4+
"fmt"
45
"path/filepath"
56

67
"github.com/hashicorp/go-memdb"
@@ -374,6 +375,9 @@ func (s *ModuleStore) LocalModuleMeta(modPath string) (*tfmod.Meta, error) {
374375
if err != nil {
375376
return nil, err
376377
}
378+
if mod.MetaState != op.OpStateLoaded {
379+
return nil, fmt.Errorf("%s: module data not available", modPath)
380+
}
377381
return &tfmod.Meta{
378382
Path: mod.Path,
379383
ProviderReferences: mod.Meta.ProviderReferences,

internal/state/module_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestModuleStore_CallersOfModule(t *testing.T) {
9292
[]datadir.ModuleRecord{
9393
{
9494
Key: "web_server_sg1",
95-
SourceAddr: "terraform-aws-modules/security-group/aws//modules/http-80",
95+
SourceAddr: tfmod.ParseModuleSourceAddr("terraform-aws-modules/security-group/aws//modules/http-80"),
9696
VersionStr: "3.10.0",
9797
Version: version.Must(version.NewVersion("3.10.0")),
9898
Dir: filepath.Join(".terraform", "modules", "web_server_sg", "terraform-aws-security-group-3.10.0", "modules", "http-80"),
@@ -102,7 +102,7 @@ func TestModuleStore_CallersOfModule(t *testing.T) {
102102
},
103103
{
104104
Key: "local-x",
105-
SourceAddr: "../nested/submodule",
105+
SourceAddr: tfmod.ParseModuleSourceAddr("../nested/submodule"),
106106
Dir: filepath.Join("..", "nested", "submodule"),
107107
},
108108
},
@@ -115,7 +115,7 @@ func TestModuleStore_CallersOfModule(t *testing.T) {
115115
},
116116
{
117117
Key: "local-foo",
118-
SourceAddr: "../another/submodule",
118+
SourceAddr: tfmod.ParseModuleSourceAddr("../another/submodule"),
119119
Dir: filepath.Join("..", "another", "submodule"),
120120
},
121121
},
@@ -125,7 +125,7 @@ func TestModuleStore_CallersOfModule(t *testing.T) {
125125
[]datadir.ModuleRecord{
126126
{
127127
Key: "web_server_sg2",
128-
SourceAddr: "terraform-aws-modules/security-group/aws//modules/http-80",
128+
SourceAddr: tfmod.ParseModuleSourceAddr("terraform-aws-modules/security-group/aws//modules/http-80"),
129129
VersionStr: "3.10.0",
130130
Version: version.Must(version.NewVersion("3.10.0")),
131131
Dir: filepath.Join(".terraform", "modules", "web_server_sg", "terraform-aws-security-group-3.10.0", "modules", "http-80"),
@@ -135,7 +135,7 @@ func TestModuleStore_CallersOfModule(t *testing.T) {
135135
},
136136
{
137137
Key: "local-y",
138-
SourceAddr: "../nested/submodule",
138+
SourceAddr: tfmod.ParseModuleSourceAddr("../nested/submodule"),
139139
Dir: filepath.Join("..", "nested", "submodule"),
140140
},
141141
},

internal/terraform/datadir/module_manifest.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
version "github.com/hashicorp/go-version"
1212
"github.com/hashicorp/terraform-ls/internal/pathcmp"
13+
tfmod "github.com/hashicorp/terraform-schema/module"
1314
)
1415

1516
func ModuleManifestFilePath(fs fs.StatFS, modulePath string) (string, bool) {
@@ -34,11 +35,12 @@ type ModuleRecord struct {
3435
// position within the static module tree.
3536
Key string `json:"Key"`
3637

37-
// SourceAddr is the source address given for this module in configuration.
38-
// This is used only to detect if the source was changed in configuration
39-
// since the module was last installed, which means that the installer
40-
// must re-install it.
41-
SourceAddr string `json:"Source"`
38+
// SourceAddr is the source address for the module.
39+
SourceAddr tfmod.ModuleSourceAddr `json:"-"`
40+
41+
// RawSourceAddr is the raw source address for the module
42+
// as it appears in the manifest.
43+
RawSourceAddr string `json:"Source"`
4244

4345
// Version is the exact version of the module, which results from parsing
4446
// VersionStr. nil for un-versioned modules.
@@ -61,6 +63,11 @@ func (r *ModuleRecord) UnmarshalJSON(b []byte) error {
6163
if err != nil {
6264
return err
6365
}
66+
67+
if record.RawSourceAddr != "" {
68+
record.SourceAddr = tfmod.ParseModuleSourceAddr(record.RawSourceAddr)
69+
}
70+
6471
if record.VersionStr != "" {
6572
record.Version, err = version.NewVersion(record.VersionStr)
6673
if err != nil {

internal/terraform/datadir/module_manifest_test.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/google/go-cmp/cmp"
1010
"github.com/hashicorp/go-version"
11+
tfmod "github.com/hashicorp/terraform-schema/module"
1112
)
1213

1314
func TestParseModuleManifestFromFile(t *testing.T) {
@@ -22,26 +23,29 @@ func TestParseModuleManifestFromFile(t *testing.T) {
2223
rootDir: modPath,
2324
Records: []ModuleRecord{
2425
{
25-
Key: "web_server_sg1",
26-
SourceAddr: "terraform-aws-modules/security-group/aws//modules/http-80",
27-
VersionStr: "3.10.0",
28-
Version: version.Must(version.NewVersion("3.10.0")),
29-
Dir: filepath.Join(".terraform", "modules", "web_server_sg", "terraform-aws-security-group-3.10.0", "modules", "http-80"),
26+
Key: "web_server_sg1",
27+
SourceAddr: tfmod.ParseModuleSourceAddr("terraform-aws-modules/security-group/aws//modules/http-80"),
28+
RawSourceAddr: "terraform-aws-modules/security-group/aws//modules/http-80",
29+
VersionStr: "3.10.0",
30+
Version: version.Must(version.NewVersion("3.10.0")),
31+
Dir: filepath.Join(".terraform", "modules", "web_server_sg", "terraform-aws-security-group-3.10.0", "modules", "http-80"),
3032
},
3133
{
32-
Key: "web_server_sg2",
33-
SourceAddr: "terraform-aws-modules/security-group/aws//modules/http-80",
34-
VersionStr: "3.10.0",
35-
Version: version.Must(version.NewVersion("3.10.0")),
36-
Dir: filepath.Join(".terraform", "modules", "web_server_sg", "terraform-aws-security-group-3.10.0", "modules", "http-80"),
34+
Key: "web_server_sg2",
35+
SourceAddr: tfmod.ParseModuleSourceAddr("terraform-aws-modules/security-group/aws//modules/http-80"),
36+
RawSourceAddr: "terraform-aws-modules/security-group/aws//modules/http-80",
37+
VersionStr: "3.10.0",
38+
Version: version.Must(version.NewVersion("3.10.0")),
39+
Dir: filepath.Join(".terraform", "modules", "web_server_sg", "terraform-aws-security-group-3.10.0", "modules", "http-80"),
3740
},
3841
{
3942
Dir: ".",
4043
},
4144
{
42-
Key: "local",
43-
SourceAddr: "./nested/path",
44-
Dir: filepath.Join("nested", "path"),
45+
Key: "local",
46+
SourceAddr: tfmod.ParseModuleSourceAddr("./nested/path"),
47+
RawSourceAddr: "./nested/path",
48+
Dir: filepath.Join("nested", "path"),
4549
},
4650
},
4751
}

internal/terraform/datadir/module_manifest_unix_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/google/go-cmp/cmp"
1111
"github.com/hashicorp/go-version"
12+
tfmod "github.com/hashicorp/terraform-schema/module"
1213
)
1314

1415
func TestRecord_UnmarshalJSON_basic(t *testing.T) {
@@ -23,11 +24,12 @@ func TestRecord_UnmarshalJSON_basic(t *testing.T) {
2324
t.Fatal(err)
2425
}
2526
expectedRecord := ModuleRecord{
26-
Key: "web_server_sg",
27-
SourceAddr: "terraform-aws-modules/security-group/aws//modules/http-80",
28-
VersionStr: "3.10.0",
29-
Version: expectedVersion,
30-
Dir: ".terraform/modules/web_server_sg/terraform-aws-security-group-3.10.0/modules/http-80",
27+
Key: "web_server_sg",
28+
SourceAddr: tfmod.ParseModuleSourceAddr("terraform-aws-modules/security-group/aws//modules/http-80"),
29+
RawSourceAddr: "terraform-aws-modules/security-group/aws//modules/http-80",
30+
VersionStr: "3.10.0",
31+
Version: expectedVersion,
32+
Dir: ".terraform/modules/web_server_sg/terraform-aws-security-group-3.10.0/modules/http-80",
3133
}
3234
if diff := cmp.Diff(expectedRecord, record); diff != "" {
3335
t.Fatalf("version mismatch: %s", diff)

internal/terraform/datadir/module_manifest_windows_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/google/go-cmp/cmp"
88
"github.com/hashicorp/go-version"
9+
tfmod "github.com/hashicorp/terraform-schema/module"
910
)
1011

1112
func TestRecord_UnmarshalJSON_basic(t *testing.T) {
@@ -20,11 +21,12 @@ func TestRecord_UnmarshalJSON_basic(t *testing.T) {
2021
t.Fatal(err)
2122
}
2223
expectedRecord := ModuleRecord{
23-
Key: "web_server_sg",
24-
SourceAddr: "terraform-aws-modules/security-group/aws//modules/http-80",
25-
VersionStr: "3.10.0",
26-
Version: expectedVersion,
27-
Dir: `.terraform\modules\web_server_sg\terraform-aws-security-group-3.10.0\modules\http-80`,
24+
Key: "web_server_sg",
25+
SourceAddr: tfmod.ParseModuleSourceAddr("terraform-aws-modules/security-group/aws//modules/http-80"),
26+
RawSourceAddr: "terraform-aws-modules/security-group/aws//modules/http-80",
27+
VersionStr: "3.10.0",
28+
Version: expectedVersion,
29+
Dir: `.terraform\modules\web_server_sg\terraform-aws-security-group-3.10.0\modules\http-80`,
2830
}
2931
if diff := cmp.Diff(expectedRecord, record); diff != "" {
3032
t.Fatalf("version mismatch: %s", diff)

0 commit comments

Comments
 (0)