Coder Social home page Coder Social logo

Comments (3)

wata727 avatar wata727 commented on June 18, 2024

I found that Terraform declares a proto message to serialize cty.Path.
https://github.com/hashicorp/terraform/blob/v1.3.9/docs/plugin-protocol/tfplugin6.3.proto#L43-L56

Is this approach preferable?

from go-cty.

apparentlymart avatar apparentlymart commented on June 18, 2024

Hi @wata727,

Terraform also has some functions that produce JSON representation of paths, it seems: https://github.com/hashicorp/terraform/blob/729408333e3c0de2ae42207bb9147bf240cfad7b/internal/command/jsonplan/plan.go#L824

It feels a little weird to me to implement a "standard" JSON serialisation of a concept that doesn't really exist in JSON. Of course the same argument could be made for types, but those ended up having a JSON serialisation because it was necessary for it to be possible to encode to DynamicPseudoType; it doesn't seem so important for this package to define a serialisation for paths because each application can decide its own serialisation depending on what it needs to capture. For example, it seems like what Terraform is doing in the code I linked above is "lossy", I think because this Terraform format is designed with the assumption that the consumer knows the resource type schema and so can infer automatically what each element of the path represents.

As you saw, Terraform also uses a protocol buffers version of this information in the plugin wire protocol, which I think was desirable because it avoided an extra level of encoding and decoding since this protocol is already using protocol buffers for other reasons.

Therefore my instinct is to not define some fixed serialisation of these paths and instead leave each application to choose a suitable serialisation based on its own constraints and requirements.

Would that work for you, or does your goal rely on this being built in to this library? Thanks!

from go-cty.

wata727 avatar wata727 commented on June 18, 2024

Thank you for your reply. At first, I thought this proposal was reasonable because I didn't understand why only cty.Type and cty.Value implement a JSON serialization, but your explanation made me understand.

As with Terraform, I'm going to implement our own serialization in our application. Thanks again!

from go-cty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.