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

[WIP] Add cli command to export provider/provisioner/resource schemas #3508

Closed
wants to merge 15 commits into from
Closed

[WIP] Add cli command to export provider/provisioner/resource schemas #3508

wants to merge 15 commits into from

Conversation

VladRassokhin
Copy link
Contributor

This feature allows to run command like terraform schemas aws and get json with information about required/optional properties of providers/provisioners/resources and their types. (and much more info)

Originally it was required to add 'properties completion' and 'required properties inspection' features in IntelliJ HCL/Terraform plugin and I think it could be shared with community, so vim/emacs/etc users could use it.

Example of generated output for provisioner local-exec (terraform schemas -indent -json local-exec) could be found here. There are other files for other providers/provisioners in the same directory, look around.

Still some things should be done:

  • Documentation
  • Tests
  • Output formats
    • JSON
    • XML
    • plain text (could be useful for bash completion or something like that)
  • Check backward compatibility of third party plugins (new command added for provisioners and providers, at least recompilation required)
    • Source compatibility
    • Binary compatibility

@apparentlymart
Copy link
Contributor

This is a really interesting idea!

Are there some standard formats this could support that would then allow its output to be used with existing tools to generate documentation? e.g. would it make sense for the JSON output to be JSON-schema compatible?

I think there are a couple challenges here:

  • This changes the interface for plugins to include the new Export function (which maybe could be named ExportSchema instead?). This means that it'll fail when run against third-party plugins that were compiled against older versions of Terraform.
  • In Terraform's current architecture, the "schema" helper is considered an implementation detail of a provider as far as core Terraform is concerned. In order to make this work while preserving that architecture, you've invented another set of structures for schema within Terraform core that are at a similar -- but not quite the same -- level of abstraction. I expect we'll want to think hard about whether this is the right separation of concerns, and whether the core model of schema is at the right level of abstraction when compared to the schema helper's idea of schema.

With all of that said, I really like the idea of Terraform's configuration model being more self-describing. In future it might make it easier to keep docs in sync with implementation, and in the further future it may allow more sophisticated tools for working with Terraform configurations, allowing automation or interactive configuration. I'm going to add the "thinking" tag to this, which is a marker that this change requires some philosophy as well as code. 😀

@VladRassokhin
Copy link
Contributor Author

@apparentlymart

Are there some standard formats this could support that would then allow its output to be used with existing tools to generate documentation? e.g. would it make sense for the JSON output to be JSON-schema compatible?

Don't know about any of such formats. :( Swagger maybe?

This changes the interface for plugins to include the new Export function (which maybe could be named ExportSchema instead?). This means that it'll fail when run against third-party plugins that were compiled against older versions of Terraform.

If plugin is old and terraform core is new, error message would be shown instead of json (afaik).
New method added to ResourceProvider, but since it already implemented in rpc it would be in any plugin after recompilation (no changes to source code).
Situation with Provisioners is quite different. Plugin source code should be a bit modified (see how builtin provisioners modified)

In Terraform's current architecture, the "schema" helper is considered an implementation detail of a provider as far as core Terraform is concerned. In order to make this work while preserving that architecture, you've invented another set of structures for schema within Terraform core that are at a similar -- but not quite the same -- level of abstraction. I expect we'll want to think hard about whether this is the right separation of concerns, and whether the core model of schema is at the right level of abstraction when compared to the schema helper's idea of schema.

Well, since new model uses just maps, arrays and strings any change into new schema class would be still binary backward compatible. Situation is different with Schema struct which already present in Terraform code (and used only in plugins). But there's a lot things to think and discuss.

In future it might make it easier to keep docs in sync with implementation

Yep, it's second usage of this feature that come into my mind.

@josephholsten
Copy link
Contributor

@VladRassokhin how's this coming? looks like it needs to be updated to work with master

@VladRassokhin
Copy link
Contributor Author

@josephholsten I'm rebasing it from time to time to update schemas in my IntelliJ plugin, but have no spare time to finish this feature at the moment.
So, will rebase it again on weekend and maybe implement some of the items from list above.

@phinze phinze changed the title Add cli command to export provider/provisioner/resource schemas [WIP] Add cli command to export provider/provisioner/resource schemas Feb 9, 2016
@phinze phinze removed the wip label Feb 9, 2016
@stack72 stack72 added the waiting-response An issue/pull request is waiting for a response from the community label Jun 9, 2016
@stack72
Copy link
Contributor

stack72 commented Jun 9, 2016

Hi @VladRassokhin

What is the status of this PR? Is this something that can be closed? There hasn't been activity in a while

Thanks

Paul

Initial version
Providers and resources
JSON output only

Fix tests: add Export function to MockResourceProvider
Export only modified values
Export not all fields (omit fields about generating value, etc)
Export nested schemas (when some value have own schema)

Fixes after `go vet`
Fix tests: add Export function to MockResourceProvisioner
Minor

Fix chef provisioner (change was lost during rebase)
…tions' argument for 'schemas' command)

Fix compilation

Fix test compilation

simplify functions schema
Useful for 'chef' since there's both provider and provisioner with that name.
@stack72
Copy link
Contributor

stack72 commented Oct 26, 2016

I am going to close this PR out - thanks for the work here. I haven't received any response about the status of the PR since June. If you still feel this is work you'd like to get merged in, please do open another PR

Thanks again

Paul

@stack72 stack72 closed this Oct 26, 2016
@stack72
Copy link
Contributor

stack72 commented Oct 26, 2016

I am going to close this PR out - thanks for the work here. I haven't received any response about the status of the PR since June. If you still feel this is work you'd like to get merged in, please do open another PR

Thanks again

Paul

@ghost
Copy link

ghost commented Apr 21, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
core enhancement waiting-response An issue/pull request is waiting for a response from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants