Skip to content

Commit fa657cb

Browse files
authored
Merge pull request #35264 from hashicorp/revert-35231-TF-12601/deprecated-module-version-warns-rev2
2 parents be73fa3 + 3a52212 commit fa657cb

File tree

6 files changed

+18
-184
lines changed

6 files changed

+18
-184
lines changed

internal/command/views/json/diagnostic.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ type Diagnostic struct {
3838
Address string `json:"address,omitempty"`
3939
Range *DiagnosticRange `json:"range,omitempty"`
4040
Snippet *DiagnosticSnippet `json:"snippet,omitempty"`
41-
Extra any `json:"extra,omitempty"`
4241
}
4342

4443
// Pos represents a position in the source code.
@@ -145,18 +144,11 @@ func NewDiagnostic(diag tfdiags.Diagnostic, sources map[string][]byte) *Diagnost
145144

146145
desc := diag.Description()
147146

148-
extra := diag.ExtraInfo()
149-
var publicExtra tfdiags.PublicExtraInfo
150-
if e, ok := extra.(tfdiags.PublicExtraInfo); ok {
151-
publicExtra = e
152-
}
153-
154147
diagnostic := &Diagnostic{
155148
Severity: sev,
156149
Summary: desc.Summary,
157150
Detail: desc.Detail,
158151
Address: desc.Address,
159-
Extra: publicExtra,
160152
}
161153

162154
sourceRefs := diag.Source()

internal/initwd/module_install.go

Lines changed: 14 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,6 @@ type moduleVersion struct {
4949
version string
5050
}
5151

52-
// TypeModuleVersionDeprecation is a constant of TypeDiagnosticExtra indicating
53-
// that a Warning is related to a deprecated module version is in use.
54-
type TypeDiagnosticExtra string
55-
56-
const TypeModuleVersionDeprecation TypeDiagnosticExtra = "module_version_deprecation"
57-
58-
// ModuleVersionDeprecationDiagnosticExtra holds the diagnostic information
59-
// about the deprecation of a module version. This ends up being serialized as extra data within a
60-
// diagnostic and should be considered public API.
61-
type ModuleVersionDeprecationDiagnosticExtra struct {
62-
Type TypeDiagnosticExtra `json:"type"`
63-
Version string `json:"version"`
64-
SourceAddr string `json:"source_name"`
65-
DeprecationMessage string `json:"deprecation_message"`
66-
Link string `json:"link"`
67-
}
68-
69-
// IsPublic confirms the visibility of the extra field in the public API.
70-
func (m ModuleVersionDeprecationDiagnosticExtra) IsPublic() {
71-
// NOP
72-
}
73-
7452
func NewModuleInstaller(modsDir string, loader *configload.Loader, reg *registry.Client) *ModuleInstaller {
7553
return &ModuleInstaller{
7654
modsDir: modsDir,
@@ -276,32 +254,6 @@ func (i *ModuleInstaller) moduleInstallWalker(ctx context.Context, manifest mods
276254
}
277255

278256
log.Printf("[TRACE] ModuleInstaller: Module installer: %s %s already installed in %s", key, record.Version, record.Dir)
279-
280-
// Checking for module deprecations in the case no new module versions need installation
281-
if addr, isRegistryModule := req.SourceAddr.(addrs.ModuleSourceRegistry); isRegistryModule {
282-
regClient := i.reg
283-
284-
regsrcAddr := regsrc.ModuleFromRegistryPackageAddr(addr.Package)
285-
resp, err := regClient.ModuleVersions(ctx, regsrcAddr)
286-
if err != nil {
287-
log.Printf("[WARN] Deprecation for %s could not be checked: call to registry failed: %v", addr.Package.String(), err)
288-
289-
} else {
290-
found:
291-
for _, modProviderVersions := range resp.Modules {
292-
for _, modVersion := range modProviderVersions.Versions {
293-
vm, _ := version.NewVersion(modVersion.Version)
294-
if vm.Equal(record.Version) {
295-
if modVersion.Deprecation != nil {
296-
diags = append(diags, buildModuleVersionDeprecationWarning(modVersion, req, addr.Package.String()))
297-
}
298-
break found
299-
}
300-
}
301-
}
302-
}
303-
}
304-
305257
return mod, record.Version, diags
306258
}
307259
}
@@ -528,8 +480,7 @@ func (i *ModuleInstaller) installRegistryModule(ctx context.Context, req *config
528480

529481
modMeta := resp.Modules[0]
530482

531-
var latestMatch *response.ModuleVersion
532-
var latestMatchVersion *version.Version
483+
var latestMatch *version.Version
533484
var latestVersion *version.Version
534485
for _, mv := range modMeta.Versions {
535486
v, err := version.NewVersion(mv.Version)
@@ -594,9 +545,8 @@ func (i *ModuleInstaller) installRegistryModule(ctx context.Context, req *config
594545
}
595546

596547
if req.VersionConstraint.Required.Check(v) {
597-
if latestMatch == nil || v.GreaterThan(latestMatchVersion) {
598-
latestMatch = mv
599-
latestMatchVersion = v
548+
if latestMatch == nil || v.GreaterThan(latestMatch) {
549+
latestMatch = v
600550
}
601551
}
602552
}
@@ -621,27 +571,23 @@ func (i *ModuleInstaller) installRegistryModule(ctx context.Context, req *config
621571
return nil, nil, diags
622572
}
623573

624-
if latestMatch.Deprecation != nil {
625-
diags = diags.Append(buildModuleVersionDeprecationWarning(latestMatch, req, addr.Package.String()))
626-
}
627-
628574
// Report up to the caller that we're about to start downloading.
629-
hooks.Download(key, packageAddr.String(), latestMatchVersion)
575+
hooks.Download(key, packageAddr.String(), latestMatch)
630576

631577
// If we manage to get down here then we've found a suitable version to
632578
// install, so we need to ask the registry where we should download it from.
633579
// The response to this is a go-getter-style address string.
634580

635581
// first check the cache for the download URL
636-
moduleAddr := moduleVersion{module: packageAddr, version: latestMatchVersion.String()}
582+
moduleAddr := moduleVersion{module: packageAddr, version: latestMatch.String()}
637583
if _, exists := i.registryPackageSources[moduleAddr]; !exists {
638-
realAddrRaw, err := reg.ModuleLocation(ctx, regsrcAddr, latestMatchVersion.String())
584+
realAddrRaw, err := reg.ModuleLocation(ctx, regsrcAddr, latestMatch.String())
639585
if err != nil {
640-
log.Printf("[ERROR] %s from %s %s: %s", key, addr, latestMatchVersion, err)
586+
log.Printf("[ERROR] %s from %s %s: %s", key, addr, latestMatch, err)
641587
diags = diags.Append(&hcl.Diagnostic{
642588
Severity: hcl.DiagError,
643589
Summary: "Error accessing remote module registry",
644-
Detail: fmt.Sprintf("Failed to retrieve a download URL for %s %s from %s: %s", addr, latestMatchVersion, hostname, err),
590+
Detail: fmt.Sprintf("Failed to retrieve a download URL for %s %s from %s: %s", addr, latestMatch, hostname, err),
645591
})
646592
return nil, nil, diags
647593
}
@@ -650,7 +596,7 @@ func (i *ModuleInstaller) installRegistryModule(ctx context.Context, req *config
650596
diags = diags.Append(&hcl.Diagnostic{
651597
Severity: hcl.DiagError,
652598
Summary: "Invalid package location from module registry",
653-
Detail: fmt.Sprintf("Module registry %s returned invalid source location %q for %s %s: %s.", hostname, realAddrRaw, addr, latestMatchVersion, err),
599+
Detail: fmt.Sprintf("Module registry %s returned invalid source location %q for %s %s: %s.", hostname, realAddrRaw, addr, latestMatch, err),
654600
})
655601
return nil, nil, diags
656602
}
@@ -665,15 +611,15 @@ func (i *ModuleInstaller) installRegistryModule(ctx context.Context, req *config
665611
diags = diags.Append(&hcl.Diagnostic{
666612
Severity: hcl.DiagError,
667613
Summary: "Invalid package location from module registry",
668-
Detail: fmt.Sprintf("Module registry %s returned invalid source location %q for %s %s: must be a direct remote package address.", hostname, realAddrRaw, addr, latestMatchVersion),
614+
Detail: fmt.Sprintf("Module registry %s returned invalid source location %q for %s %s: must be a direct remote package address.", hostname, realAddrRaw, addr, latestMatch),
669615
})
670616
return nil, nil, diags
671617
}
672618
}
673619

674620
dlAddr := i.registryPackageSources[moduleAddr]
675621

676-
log.Printf("[TRACE] ModuleInstaller: %s %s %s is available at %q", key, packageAddr, latestMatchVersion, dlAddr.Package)
622+
log.Printf("[TRACE] ModuleInstaller: %s %s %s is available at %q", key, packageAddr, latestMatch, dlAddr.Package)
677623

678624
err := fetcher.FetchPackage(ctx, instPath, dlAddr.Package.String())
679625
if errors.Is(err, context.Canceled) {
@@ -735,14 +681,14 @@ func (i *ModuleInstaller) installRegistryModule(ctx context.Context, req *config
735681
// Note the local location in our manifest.
736682
manifest[key] = modsdir.Record{
737683
Key: key,
738-
Version: latestMatchVersion,
684+
Version: latestMatch,
739685
Dir: modDir,
740686
SourceAddr: req.SourceAddr.String(),
741687
}
742688
log.Printf("[DEBUG] Module installer: %s installed at %s", key, modDir)
743-
hooks.Install(key, latestMatchVersion, modDir)
689+
hooks.Install(key, latestMatch, modDir)
744690

745-
return mod, latestMatchVersion, diags
691+
return mod, latestMatch, diags
746692
}
747693

748694
func (i *ModuleInstaller) installGoGetterModule(ctx context.Context, req *configs.ModuleRequest, key string, instPath string, manifest modsdir.Manifest, hooks ModuleInstallHooks, fetcher *getmodules.PackageFetcher) (*configs.Module, hcl.Diagnostics) {
@@ -990,27 +936,3 @@ func splitAddrSubdir(addr addrs.ModuleSource) (string, string) {
990936
return addr.String(), ""
991937
}
992938
}
993-
994-
func buildModuleVersionDeprecationWarning(modVersion *response.ModuleVersion, req *configs.ModuleRequest, packageAddr string) *hcl.Diagnostic {
995-
var additionalInfo []string
996-
if modVersion.Deprecation.Reason != "" {
997-
additionalInfo = append(additionalInfo, modVersion.Deprecation.Reason)
998-
}
999-
if modVersion.Deprecation.Link != "" {
1000-
additionalInfo = append(additionalInfo, fmt.Sprintf("More information: %s", modVersion.Deprecation.Link))
1001-
}
1002-
detail := strings.Join(additionalInfo, "\n\n")
1003-
return &hcl.Diagnostic{
1004-
Severity: hcl.DiagWarning,
1005-
Summary: fmt.Sprintf("Module version %s of %s is deprecated", modVersion.Version, packageAddr),
1006-
Detail: detail,
1007-
Subject: req.CallRange.Ptr(),
1008-
Extra: &ModuleVersionDeprecationDiagnosticExtra{
1009-
Type: TypeModuleVersionDeprecation,
1010-
Version: modVersion.Version,
1011-
SourceAddr: packageAddr,
1012-
DeprecationMessage: modVersion.Deprecation.Reason,
1013-
Link: modVersion.Deprecation.Link,
1014-
},
1015-
}
1016-
}

internal/initwd/module_install_test.go

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/hashicorp/terraform/internal/configs/configload"
2626
"github.com/hashicorp/terraform/internal/copy"
2727
"github.com/hashicorp/terraform/internal/registry"
28-
"github.com/hashicorp/terraform/internal/registry/response"
2928
"github.com/hashicorp/terraform/internal/tfdiags"
3029

3130
_ "github.com/hashicorp/terraform/internal/logging"
@@ -596,70 +595,6 @@ func TestLoaderInstallModules_registry(t *testing.T) {
596595

597596
}
598597

599-
func TestLoaderInstallModules_registry_deprecated(t *testing.T) {
600-
fixtureDir := filepath.Clean("testdata/registry-module-from-test")
601-
tmpDir, done := tempChdir(t, fixtureDir)
602-
// the module installer runs filepath.EvalSymlinks() on the destination
603-
// directory before copying files, and the resultant directory is what is
604-
// returned by the install hooks. Without this, tests could fail on machines
605-
// where the default temp dir was a symlink.
606-
dir, err := filepath.EvalSymlinks(tmpDir)
607-
if err != nil {
608-
t.Error(err)
609-
}
610-
611-
defer done()
612-
613-
hooks := &testInstallHooks{}
614-
modulesDir := filepath.Join(dir, ".terraform/modules")
615-
616-
loader, close := configload.NewLoaderForTests(t)
617-
defer close()
618-
619-
inst := NewModuleInstaller(modulesDir, loader, registry.NewClient(nil, nil))
620-
621-
// Avoid actual registry lookup by populating registry cache
622-
packageAddr := addrs.ModuleRegistryPackage{
623-
Host: svchost.Hostname("registry.terraform.io"),
624-
Namespace: "hashicorp",
625-
Name: "module-installer-acctest",
626-
TargetSystem: "aws",
627-
}
628-
629-
inst.registryPackageVersions[packageAddr] = &response.ModuleVersions{
630-
Modules: []*response.ModuleProviderVersions{
631-
{
632-
Source: "",
633-
Versions: []*response.ModuleVersion{
634-
{
635-
Version: "0.0.1",
636-
Root: response.VersionSubmodule{},
637-
Submodules: []*response.VersionSubmodule{},
638-
Deprecation: &response.Deprecation{
639-
Reason: "This module version is deprecated",
640-
Link: "https://example.com/deprecation",
641-
},
642-
},
643-
},
644-
},
645-
},
646-
}
647-
648-
_, diags := inst.InstallModules(context.Background(), dir, "tests", false, false, hooks)
649-
650-
if !diags.HasWarnings() {
651-
t.Fatal("expected warning")
652-
} else {
653-
assertDiagnosticCount(t, diags, 1)
654-
assertDiagnosticSummary(t, diags, "Module version 0.0.1 of registry.terraform.io/hashicorp/module-installer-acctest/aws is deprecated")
655-
656-
wantDetail := "This module version is deprecated\n\nMore information: https://example.com/deprecation"
657-
if diags[0].Description().Detail != wantDetail {
658-
t.Errorf("wrong deprecation detail\nwant: %s\ngot: %s", wantDetail, diags[0].Description().Detail)
659-
}
660-
}
661-
}
662-
663598
func TestLoaderInstallModules_goGetter(t *testing.T) {
664599
if os.Getenv("TF_ACC") == "" {
665600
t.Skip("this test accesses github.com; set TF_ACC=1 to run it")
@@ -1033,7 +968,7 @@ func assertDiagnosticCount(t *testing.T, diags tfdiags.Diagnostics, want int) bo
1033968
if len(diags) != want {
1034969
t.Errorf("wrong number of diagnostics %d; want %d", len(diags), want)
1035970
for _, diag := range diags {
1036-
t.Logf("- %#v", diag.Description().Summary)
971+
t.Logf("- %#v", diag)
1037972
}
1038973
return true
1039974
}

internal/registry/response/module_versions.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,9 @@ type ModuleProviderVersions struct {
2020
// ModuleVersion is the output metadata for a given version needed by CLI to
2121
// resolve candidate versions to satisfy requirements.
2222
type ModuleVersion struct {
23-
Version string `json:"version"`
24-
Root VersionSubmodule `json:"root"`
25-
Submodules []*VersionSubmodule `json:"submodules"`
26-
Deprecation *Deprecation `json:"deprecation"`
27-
}
28-
29-
// Deprecation holds the user provided reason and link for the specific module version deprecation
30-
type Deprecation struct {
31-
Reason string `json:"reason"`
32-
Link string `json:"link"`
23+
Version string `json:"version"`
24+
Root VersionSubmodule `json:"root"`
25+
Submodules []*VersionSubmodule `json:"submodules"`
3326
}
3427

3528
// VersionSubmodule is the output metadata for a submodule within a given

internal/tfdiags/diagnostic.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,3 @@ type FromExpr struct {
6565
Expression hcl.Expression
6666
EvalContext *hcl.EvalContext
6767
}
68-
69-
// PublicExtraInfo is an interface for marking Extra field that contain public extra information
70-
type PublicExtraInfo interface {
71-
IsPublic()
72-
}

website/docs/cli/commands/validate.mdx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,6 @@ The nested objects in `diagnostics` have the following properties:
178178
which may be useful in understanding the source of a diagnostic in a
179179
complex expression. These expression value objects are described below.
180180

181-
- `extra` (object): An optional object that serves as an extension point for additional
182-
machine-readable information about the problem.
183-
184181
### Source Position
185182

186183
A source position object, as used in the `range` property of a diagnostic

0 commit comments

Comments
 (0)