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 Warning for Deprecated Modules in Init #34943

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

Maed223
Copy link
Contributor

@Maed223 Maed223 commented Apr 3, 2024

Jira Ticket

Target Release

1.8.x

Draft CHANGELOG entry

ENHANCEMENTS

  • terraform init: Displays a warning when deprecated modules are in use.

Description

All module deprecation info is consolidated into and displayed as a single warning upon running terraform init. This includes both cases of where the module does, or does not, need installation. Furthermore, the warning can be raised for both modules that are directly used in configuration, as well as any external dependencies they depend on.

Screenshot

Note that this screenshot includes both the root module as well as it's external dependencies

Screenshot 2024-04-29 at 12 28 13 PM

internal/command/get.go Outdated Show resolved Hide resolved
internal/command/init.go Outdated Show resolved Hide resolved
Copy link
Contributor

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

Some early questions that will help me get my bearings on this PR

Comment on lines +140 to +145
cfg, instDiags, workspaceDeprecations := i.installDescendentModules(rootMod, manifest, walker, installErrsOnly)
diags = append(diags, instDiags...)
if workspaceDeprecations.HasDeprecations() {
moduleDeprecationWarning := workspaceDeprecations.BuildDeprecationWarning()
diags = diags.Append(moduleDeprecationWarning)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious: Why couldn't the ModuleInstaller itself build the deprecation warnings and add them to the instDiags that are already returned? It would seem that would simplify the interface greatly.

Copy link
Contributor

Choose a reason for hiding this comment

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

My rationale is that they are being appended to diags along with instDiags, without further differentiation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comes from the requirement that we consolidate the deprecations into a single warning, as well as having a means of showing the hierarchy in which a deprecated module sits (i.e. the (Root: a -> b -> c) parts of the warning).

@@ -45,6 +45,7 @@ require (
github.com/manicminer/hamilton-autorest v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
Copy link
Contributor

Choose a reason for hiding this comment

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

These backend go mod changes look out of place because no other changes are in the package. What's going on with them?

Copy link
Contributor Author

@Maed223 Maed223 May 10, 2024

Choose a reason for hiding this comment

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

This is something I'm not 100% sure on, but it seems to me that change was needed since I added the dependency to configs package, which is somehow a dependency of backend package. Without this change I was getting failures in "Code Consistency Checks" test on CI, as well as some failing unit tests due to the missing presence of the dependency. This change and it's related changes are the result of running make syncdeps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Took some edits to how the Detail of diagnostics are handled in the format package, but was able to remove the direct colorization in the configs package that subsequently removes the need for these changes.

Included here 7b3e8a1

Otherwise dropped the previous commit that included the go.mod and go.sum changes

@Maed223
Copy link
Contributor Author

Maed223 commented May 10, 2024

@nfagerlund– just to address some of your points ✍️

TFE Version of this warning

Passing deprecations as a return value separate from configs.Config

  • configs.Config seemed to me to represent info that is specifically relevant to configuration (as it pertains to the direct usage of the module) and distinctly separate to something like deprecation metadata just used for a warning. Though I definitely see the argument that utilizing this existing structure is advantageous in retrospect.
  • Additionally, it looked to me that for root modules certain bits of needed info wouldn't be present, leading to adding redundant info for all Configs (such as Version not being present for the root, so I'd have to insert the Version through other means for all modules in the Config tree). This in combination with my thought above led me to keep them separate. Though in total, If you feel strongly about this I'll defer to your wisdom and make the change 😁

Changes in go-slug/sourcebundle

…it colorizing of diags details & abiding to -no-color
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants