natikgadzhi / protoc-gen-tfschema Goto Github PK
View Code? Open in Web Editor NEWProtoc plugin for terraform providers
License: Apache License 2.0
Protoc plugin for terraform providers
License: Apache License 2.0
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
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.