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

Helper function or routine to convert Schema.ResourceData to a JSON representation #83

Open
manalivaltix opened this issue Nov 13, 2021 · 3 comments
Labels
question Further information is requested waiting-response

Comments

@manalivaltix
Copy link

Is there a helper function or utility to convert Schema.ResourceData to a JSON representation?

@radeksimko
Copy link
Member

radeksimko commented Nov 15, 2021

Hi @manalivaltix
To answer your question directly, Terraform CLI is currently the only (HashiCorp supported) way to convert the provider schema into a JSON representation. You can read more about the relevant command and format of the JSON format here: https://www.terraform.io/docs/cli/commands/providers/schema.html

It is worth noting that this necessitates terraform init and relatedly access to the state. See also hashicorp/terraform#24261


So we can provide perhaps more helpful answer - Would you mind sharing your use case - i.e. What are you trying to build?

Thanks.

@radeksimko radeksimko added the question Further information is requested label Nov 15, 2021
@manalivaltix
Copy link
Author

@radeksimko we are trying to build a utility that takes our existing infrastructure, and can programmatically spew out the terraform config for that infrastructure so our users can seamlessly move to terraform. We looked at the terraform import option, but it is too tedious, and doesn't provide a "one" click import that we would like. We can build a library already that can do a READ of the resources we have and save it in schema.ResourceData, all we need is an api that can convert that to a JSON format. Can we expect that api to be exposed to the end-user?

@radeksimko
Copy link
Member

Just for posterity, this is an area which is recognized by the Terraform Core team as one that needs improvement, but I don't have any concrete plans to share with you at this point, just that ideally we'd like Terraform CLI to be able to handle this problem natively at some point.

I'm still struggling to understand however how do you imagine your in-house library to work in the context of a provider (I'm assuming the context as you mentioned schema.ResourceData which is concept only relevant in providers/SDK). Generally providers are treated as gRPC servers and the gRPC protocol defines what endpoints and data they can offer. Terraform CLI then acts as a gRPC client in that context and does all the "heavy-lifting" such as configuration parsing, provides any end-user UI etc.

There is currently no pattern/guidance around how providers can or should provide any functionality beyond the documented gRPC protocol and there's usually no expectations for providers to be executed as standalone binaries by the end-user, partially because the binaries are also usually hidden away from the end-user and installed only via Terraform CLI.
This is also why providers are generally not expected to know how to parse configuration, or generate it. The gRPC doesn't give them the opportunity as it doesn't provide the original bytes or any kind of direct access to the parsed configuration. Providers receive already parsed configuration which is relevant to the provider.

With all that in mind - Do you mind expanding on your use case and how are you hoping this library can help address that use case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested waiting-response
Projects
None yet
Development

No branches or pull requests

2 participants