Giter Site home page Giter Site logo

protoc-gen-tfschema's Issues

Regression: generated inline list Elem has Optional / Required field when it shouldn't

In the generated schema:

		// types.UserSpecV2.Roles
		"roles": {
			Type:     schema.TypeList,
			Optional: true,
			Elem: &schema.Schema{
				Type:     schema.TypeString,
				Optional: true,
			},
		},

When running terraform plan:

Error: InternalValidate
Internal validation of the provider failed! This is always a bug
with the provider itself, and not a user issue. Please report
this bug:
2 errors occurred:
        * resource teleport_user: roles: Elem must have only Type set
        * resource teleport_role: values: Elem must have only Type set

Regression: `types` flag not parsed in the builder template version

@gzigzigzeo,

types option stopped working correctly after the merge. If I put comma-separated list of types, as in the readme (I believe that's a legacy readme that I've written before), it errors out like this, and no schema is generated:

nate-mbp:~/g/s/g/g/t/terraform protoc --proto_path=. \                                                                                                            (base) 
                                 --proto_path=/Users/xnutsive/go/src/github.com/gravitational/teleport/vendor/github.com/gogo/protobuf \
                                 --proto_path=/Users/xnutsive/go/src/github.com/gravitational/teleport/api/types \
                                 --proto_path=/Users/xnutsive/go/src \
                                 types.proto \
                                 --tfschema_out=./tfschema/ \
                                 --go_out=./tfschema/ \
                                 --tfschema_opt="types=UserV2,RoleV3"
INFO[0000] Reading CodeGeneratorRequest from stdin.     
INFO[0000] Command-line arguments: types=UserV2,RoleV3  
FATA[0000] no such flag -RoleV3                         
--tfschema_out: protoc-gen-tfschema: Plugin failed with status code 1.
nate-mbp:~/g/s/g/g/t/terraform 

If I list types separated by a space (this way it worked before), it ignores provided types and schema file is generated, but it doesn't contain any schemas, just the package name and imports:

nate-mbp:~/g/s/g/g/t/terraform protoc --proto_path=. \                                                                                                            (base) 
                                 --proto_path=/Users/xnutsive/go/src/github.com/gravitational/teleport/vendor/github.com/gogo/protobuf \
                                 --proto_path=/Users/xnutsive/go/src/github.com/gravitational/teleport/api/types \
                                 --proto_path=/Users/xnutsive/go/src \
                                 types.proto \
                                 --tfschema_out=./tfschema/ \
                                 --go_out=./tfschema/ \
                                 --tfschema_opt="types=UserV2 RoleV3"
INFO[0000] Reading CodeGeneratorRequest from stdin.     
INFO[0000] Command-line arguments: types=UserV2 RoleV3  
2021/02/02 10:06:28 WARNING: Missing 'go_package' option in "github.com/gravitational/teleport/api/types/wrappers/wrappers.proto", please specify:
	option go_package = "github.com/gravitational/teleport/api/types/wrappers";
A future release of protoc-gen-go will require this be specified.
See https://developers.google.com/protocol-buffers/docs/reference/go-generated#package for more information.

2021/02/02 10:06:28 WARNING: Missing 'go_package' option in "types.proto",
please specify it with the full Go package path as
a future release of protoc-gen-go will require this be specified.
See https://developers.google.com/protocol-buffers/docs/reference/go-generated#package for more information.

INFO[0000] Package name: tfschema                       
INFO[0000] Types to export: [UserV2 RoleV3]             
INFO[0000] Protoc version: v3.14.0                      
INFO[0000] Generating schema files...                   
INFO[0000] types.tfschema.go prepared                   
INFO[0000] 1 files generated                            
2021/02/02 10:06:28 WARNING: Missing 'go_package' option in "github.com/gravitational/teleport/api/types/wrappers/wrappers.proto", please specify:
	option go_package = "github.com/gravitational/teleport/api/types/wrappers";
A future release of protoc-gen-go will require this be specified.
See https://developers.google.com/protocol-buffers/docs/reference/go-generated#package for more information.

2021/02/02 10:06:28 WARNING: Missing 'go_package' option in "types.proto",
please specify it with the full Go package path as
a future release of protoc-gen-go will require this be specified.
See https://developers.google.com/protocol-buffers/docs/reference/go-generated#package for more information.

schema:

// DO NOT EDIT.
// Code is generated by protoc-gen-tfschema 0.0.2
// Using protoc v3.14.0

package tfschema

import (
	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

And if I set no types flag at all — all types are generated. I'm fine with that for now ;)

I think the problem is that protoc plugin flags are not parsed as regular CLI flags, and the parser code from my version is required to do that correctly. It's a bummer and it looks like crap, but it works.

Wrapped protobuf values result in messy schemas

Teleport's proto uses wrapped values like these:

    // NodeLabels is a map of node labels (used to dynamically grant access to
    // nodes).
    wrappers.LabelValues NodeLabels = 3 [
        (gogoproto.nullable) = false,
        (gogoproto.jsontag) = "node_labels,omitempty",
        (gogoproto.customtype) = "Labels"
    ];

These tend to result in a recursive schema.Resource, but essentially, we could unwrap them and just declare the underlying type. Two lists of wrappers are interesting:

I don't see an obvious way for the schema generator to understand that some nested resource is essentially a wrapper and should be omitted, and other is a legit important nested structure that we don't want to squash.

One way to work with this would be to have a list of wrapper-types (like we already do with Timestamp) and a special function that would check if the field type is a wrapper and should be unwrapped, and if so — it would skip one level and insert the wrapped type's value type instead of the wrapper.

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.