-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
terraform modules
command
#35884
terraform modules
command
#35884
Conversation
b48dca3
to
33f4a4a
Compare
This command json doesn't quite have the same experience as the other json view commands. We should be very careful with the schema since it effectively becomes public API. To that end, we could define the JSON schema in https://github.com/hashicorp/terraform-json At a minimum, it would need a schema version string and probably some lower case keys. I'm also unsure of the "dir" attribute and think it should be more (like source refs in diags) or removed altogether. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! I have been smoke testing and I really like the behavior when there are no modules, when there is config parsing error, etc.
The output itself, as we have discussed in the project Slack channel, can be improved a little to, for example, not include dir
field and include other fields seen in terraform providers schema -json
and other json outputs.
I have dropped other comments in the code as well.
// appended to the manifest that records this new information. | ||
func (r *Resolver) findAndTrimReferencedEntries(cfg *configs.Config) { | ||
for entryKey, entry := range r.internalManifest { | ||
for callerKey := range cfg.Module.ModuleCalls { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any chance we could get to this point and cfg or cfg.Module is nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command will ensure that configuration is loaded & correct before attempting to resolve module references. Each configs.Config
object represents the Terraform configuration for a single module. The Module
field, holds data about resources, variables, module blocks, defined in that configuration. While configuration can be empty, this field will never be nil.
53330c8
to
80bdd12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved for unblocking purposes. Added a tiny suggestion for style and some questions to expand the context for users! As always, let me know if anything doesn't feel good on these ✨
--- | ||
page_title: 'Command: modules' | ||
description: >- | ||
The terraform modules command prints information about all the declared |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of information?
# Command: modules | ||
|
||
The `terraform modules` command provides a holistic view of all Terraform | ||
modules and their resolved versions that have been declared in Terraform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modules and their resolved versions that have been declared in Terraform | |
modules and their resolved versions declared in Terraform |
|
||
## Usage | ||
|
||
Usage: `terraform modules -json` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if you omit the -json
flag? Does it error? Or just provide json anyways? This is just me being curious 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will error similar to how terraform providers schema
errors when you omit the -json
flag. It will return an error stating -json
is required with the command help text below it.
The modules command provides a holistic view of all installed modules for a given root module. It also includes information on whether a installed module is currently referenced by configuration. As of now, this command only supports a machine-readable view format.
This commit makes several modifications to the modules command. It downcases the field names in the resulting JSON string, adds a format version to the result. The result of this command will now only contain entries which have been declared in configuration, as opposed to the internal manifest which shows all installed modules for a working dir.
0bd763b
to
814130a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super small nits, but I think this looks great! Thank you for doing all this so quickly! Everything is good to go from my side with these comments ✨
814130a
to
1133d0e
Compare
Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch. |
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 contributions. |
This PR implements the
terraform modules -json
command which provides a full view of all configuration declared modules (local, registry, remote) in a working directory (under.terraform/
). To do so, this command will read the internal module manifest and subsequently traverse the module tree to find references for each entry in the manifest. If a reference is found, which are unique per module caller, the entry will be added to the final result. Currently the internal module manifest, which can be found./.terraform/modules/modules.json
, was an implementation detail and not guaranteed to have a fixed public interface. This command creates a public, versioned interface for that manifest.Currently this command only supports machine-readable output and thus the
-json
flag will be required. At a later point a human readable format will be supported.This command also does not display the root module entry from the list of modules as it is redundant information & never directly referenced in Terraform configuration.
Target Release
1.10.0
Draft CHANGELOG entry
NEW FEATURES
terraform modules -json
: Displays a full list of all installed modules in a working directory, including whether each module is currently referenced by the working directory's Terraform configuration.