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

TF Schema dump #2315

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions pf/internal/schemashim/attr_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ type attrSchema struct {

var _ shim.Schema = (*attrSchema)(nil)

func (s *attrSchema) Implementation() string {
return "pf"
}

func (s *attrSchema) Type() shim.ValueType {
ty := s.attr.GetType()
vt, err := convertType(ty)
Expand All @@ -47,11 +51,11 @@ func (s *attrSchema) Required() bool {
return s.attr.IsRequired()
}

func (*attrSchema) Default() interface{} {
panic("Default() should not be called during schema generation")
func (s *attrSchema) Default() interface{} {
return nil
}
func (*attrSchema) DefaultFunc() shim.SchemaDefaultFunc {
panic("DefaultFunc() should not be called during schema generation")
return nil
}
func (*attrSchema) DefaultValue() (interface{}, error) {
// DefaultValue() should not be called by tfgen, but it currently may be called by ExtractInputsFromOutputs, so
Expand Down Expand Up @@ -117,11 +121,23 @@ func (*attrSchema) MinItems() int {
}

func (*attrSchema) ConflictsWith() []string {
panic("ConflictsWith() should not be called during schema generation")
return nil

}
func (*attrSchema) ExactlyOneOf() []string {
panic("ExactlyOneOf() should not be called during schema generation")
return nil
}

func (*attrSchema) AtLeastOneOf() []string {
return nil
}

func (*attrSchema) RequiredWith() []string {
return nil
}

func (*attrSchema) ConfigMode() shim.ConfigModeType {
return 0
}

func (s *attrSchema) Deprecated() string {
Expand Down
27 changes: 21 additions & 6 deletions pf/internal/schemashim/block_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (s *blockSchema) Type() shim.ValueType {
return vt
}

func (*blockSchema) Implementation() string {
return "pf"
}

func (s *blockSchema) Description() string {
if desc := s.block.GetMarkdownDescription(); desc != "" {
return desc
Expand All @@ -54,7 +58,6 @@ func (s *blockSchema) Description() string {

// Needs to return a shim.Schema, a shim.Resource, or nil. See docstring on shim.Schema.Elem().
func (s *blockSchema) Elem() interface{} {

asObjectType := func(typ any) (shim.Resource, bool) {
if tt, ok := typ.(basetypes.ObjectTypable); ok {
var res shim.Resource = newObjectPseudoResource(tt,
Expand Down Expand Up @@ -118,15 +121,15 @@ func (s *blockSchema) MaxItems() int { return int(s.block.GetMaxItems()) }
func (s *blockSchema) MinItems() int { return int(s.block.GetMinItems()) }

func (*blockSchema) ConflictsWith() []string {
panic("ConflictsWith() should not be called during schema generation")
return nil
}

func (*blockSchema) Default() interface{} {
panic("Default() should not be called during schema generation")
func (s *blockSchema) Default() interface{} {
return nil
}

func (*blockSchema) DefaultFunc() shim.SchemaDefaultFunc {
panic("DefaultFunc() should not be called during schema generation")
return nil
}

func (*blockSchema) DefaultValue() (interface{}, error) {
Expand All @@ -136,7 +139,19 @@ func (*blockSchema) DefaultValue() (interface{}, error) {
}

func (*blockSchema) ExactlyOneOf() []string {
panic("ExactlyOneOf() should not be called during schema generation")
return nil
}

func (*blockSchema) AtLeastOneOf() []string {
return nil
}

func (*blockSchema) RequiredWith() []string {
return nil
}

func (*blockSchema) ConfigMode() shim.ConfigModeType {
return 0
}

func (*blockSchema) SetElement(config interface{}) (interface{}, error) {
Expand Down
12 changes: 10 additions & 2 deletions pf/internal/schemashim/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ func (r *schemaOnlyDataSource) Schema() shim.SchemaMap {
return r.tf.Shim()
}

func (*schemaOnlyDataSource) SchemaVersion() int {
panic("DataSource SchemaVersion() should not be called during schema generation")
func (*schemaOnlyDataSource) Implementation() string {
return "pf"
}

func (*schemaOnlyDataSource) UseJSONNumber() bool {
return false
}

func (r *schemaOnlyDataSource) SchemaVersion() int {
return int(r.tf.ResourceSchemaVersion())
}

func (r *schemaOnlyDataSource) DeprecationMessage() string {
Expand Down
43 changes: 33 additions & 10 deletions pf/internal/schemashim/object_pseudoresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type objectPseudoResource struct {

func newObjectPseudoResource(t basetypes.ObjectTypable,
nestedAttrs map[string]pfutils.Attr,
nestedBlocks map[string]pfutils.Block) *objectPseudoResource {
nestedBlocks map[string]pfutils.Block,
) *objectPseudoResource {
lowerType := t.TerraformType(context.Background())
objType, ok := lowerType.(tftypes.Object)
contract.Assertf(ok, "t basetypes.ObjectTypable should produce a tftypes.Object "+
Expand All @@ -61,20 +62,29 @@ func newObjectPseudoResource(t basetypes.ObjectTypable,
}
}

var _ shim.Resource = (*objectPseudoResource)(nil)
var _ shim.SchemaMap = (*objectPseudoResource)(nil)
var (
_ shim.Resource = (*objectPseudoResource)(nil)
_ shim.SchemaMap = (*objectPseudoResource)(nil)
)

func (r *objectPseudoResource) Validate() error {
return nil
}

func (r *objectPseudoResource) Implementation() string {
return "pf"
}

func (r *objectPseudoResource) Schema() shim.SchemaMap {
return r
}

func (*objectPseudoResource) SchemaVersion() int {
panic("This is an Object type encoded as a shim.Resource, and " +
"SchemaVersion() should not be called on this entity during schema generation")
return 0
}

func (*objectPseudoResource) UseJSONNumber() bool {
return false
}

func (*objectPseudoResource) DeprecationMessage() string {
Expand All @@ -92,13 +102,15 @@ func (*objectPseudoResource) Timeouts() *shim.ResourceTimeout {
}

func (*objectPseudoResource) InstanceState(id string, object,
meta map[string]interface{}) (shim.InstanceState, error) {
meta map[string]interface{},
) (shim.InstanceState, error) {
panic("This is an Object type encoded as a shim.Resource, and " +
"InstanceState() should not be called on this entity during schema generation")
}

func (*objectPseudoResource) DecodeTimeouts(
config shim.ResourceConfig) (*shim.ResourceTimeout, error) {
config shim.ResourceConfig,
) (*shim.ResourceTimeout, error) {
panic("This is an Object type encoded as a shim.Resource, and " +
"DecodeTimeouts() should not be called on this entity during schema generation")
}
Expand Down Expand Up @@ -187,7 +199,8 @@ func newTuplePseudoResource(t attr.TypeWithElementTypes) shim.Resource {
return &tuplePseudoResource{
schemaOnly: schemaOnly{"tuplePseudoResource"},
attrs: attrs,
tuple: t}
tuple: t,
}
}

func (*tuplePseudoResource) SchemaVersion() int { panic("TODO") }
Expand All @@ -197,6 +210,14 @@ func (r *tuplePseudoResource) Validate() error {
return nil
}

func (*tuplePseudoResource) Implementation() string {
return "pf"
}

func (*tuplePseudoResource) UseJSONNumber() bool {
return false
}

func (r *tuplePseudoResource) Schema() shim.SchemaMap {
return r
}
Expand Down Expand Up @@ -251,7 +272,8 @@ func (s *schemaOnly) Timeouts() *shim.ResourceTimeout {
}

func (s *schemaOnly) InstanceState(id string, object,
meta map[string]interface{}) (shim.InstanceState, error) {
meta map[string]interface{},
) (shim.InstanceState, error) {
m := "type"
if s != nil || s.typ != "" {
m = s.typ
Expand All @@ -260,7 +282,8 @@ func (s *schemaOnly) InstanceState(id string, object,
}

func (s *schemaOnly) DecodeTimeouts(
config shim.ResourceConfig) (*shim.ResourceTimeout, error) {
config shim.ResourceConfig,
) (*shim.ResourceTimeout, error) {
m := "type"
if s != nil || s.typ != "" {
m = s.typ
Expand Down
12 changes: 10 additions & 2 deletions pf/internal/schemashim/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ func (r *schemaOnlyResource) Schema() shim.SchemaMap {
return r.tf.Shim()
}

func (*schemaOnlyResource) SchemaVersion() int {
panic("SchemaVersion() should not be called on a Resource during schema generation")
func (*schemaOnlyResource) Implementation() string {
return "pf"
}

func (*schemaOnlyResource) UseJSONNumber() bool {
return false
}

func (r *schemaOnlyResource) SchemaVersion() int {
return int(r.tf.ResourceSchemaVersion())
}

func (r *schemaOnlyResource) DeprecationMessage() string {
Expand Down
24 changes: 20 additions & 4 deletions pf/internal/schemashim/type_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func newTypeSchema(t pfattr.Type, nested map[string]pfutils.Attr) *typeSchema {
}
}

func (*typeSchema) Implementation() string {
return "pf"
}

func (s *typeSchema) Type() shim.ValueType {
vt, err := convertType(s.t)
if err != nil {
Expand Down Expand Up @@ -79,11 +83,11 @@ func (*typeSchema) MinItems() int { return 0 }
func (*typeSchema) Deprecated() string { return "" }

func (*typeSchema) Default() interface{} {
panic("Default() should not be called during schema generation")
return nil
}

func (*typeSchema) DefaultFunc() shim.SchemaDefaultFunc {
panic("DefaultFunc() should not be called during schema generation")
return nil
}

func (*typeSchema) DefaultValue() (interface{}, error) {
Expand All @@ -102,11 +106,23 @@ func (*typeSchema) StateFunc() shim.SchemaStateFunc {
}

func (*typeSchema) ConflictsWith() []string {
panic("ConflictsWith() should not be called during schema generation")
return nil
}

func (*typeSchema) ExactlyOneOf() []string {
panic("ExactlyOneOf() should not be called during schema generation")
return nil
}

func (*typeSchema) AtLeastOneOf() []string {
return nil
}

func (*typeSchema) RequiredWith() []string {
return nil
}

func (*typeSchema) ConfigMode() shim.ConfigModeType {
return 0
}

func (*typeSchema) Removed() string { panic("Removed() should not be called during schema generation") }
Expand Down
6 changes: 5 additions & 1 deletion pf/proto/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var _ = shim.Schema(attribute{})

type attribute struct{ attr tfprotov6.SchemaAttribute }

func (a attribute) Implementation() string { return "pf" }

// Simple schema options

func (a attribute) Optional() bool { return a.attr.Optional }
Expand Down Expand Up @@ -82,7 +84,6 @@ func (a attribute) Elem() interface{} {
}
}
return element{a.attr.ValueType(), a.Optional()}.Elem()

}

// Defaults are applied in the provider binary, not here
Expand All @@ -94,6 +95,9 @@ func (a attribute) DefaultValue() (interface{}, error) { return nil, nil }
func (a attribute) StateFunc() shim.SchemaStateFunc { return nil }
func (a attribute) ConflictsWith() []string { return nil }
func (a attribute) ExactlyOneOf() []string { return nil }
func (a attribute) AtLeastOneOf() []string { return nil }
func (a attribute) RequiredWith() []string { return nil }
func (a attribute) ConfigMode() shim.ConfigModeType { return 0 }

func (a attribute) SetElement(config interface{}) (interface{}, error) {
panic("UNIMPLIMENTED")
Expand Down
6 changes: 6 additions & 0 deletions pf/proto/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type blockResource struct {
block *tfprotov6.SchemaBlock
}

func (b blockResource) Implementation() string { return "pf" }
func (b blockResource) UseJSONNumber() bool { return false }
func (b blockResource) Schema() shim.SchemaMap { return blockMap{b.block} }
func (b blockResource) DeprecationMessage() string { return deprecated(b.block.Deprecated) }

Expand Down Expand Up @@ -114,6 +116,7 @@ func (m blockSchema) Elem() interface{} {
}
}

func (m blockSchema) Implementation() string { return "pf" }
func (m blockSchema) Optional() bool { return false }
func (m blockSchema) Required() bool { return false }
func (m blockSchema) Default() interface{} { return nil }
Expand All @@ -127,6 +130,9 @@ func (m blockSchema) MaxItems() int { return int(m.block.M
func (m blockSchema) MinItems() int { return int(m.block.MinItems) }
func (m blockSchema) ConflictsWith() []string { return nil }
func (m blockSchema) ExactlyOneOf() []string { return nil }
func (a blockSchema) AtLeastOneOf() []string { return nil }
func (a blockSchema) RequiredWith() []string { return nil }
func (a blockSchema) ConfigMode() shim.ConfigModeType { return 0 }
func (m blockSchema) Removed() string { return "" }
func (m blockSchema) Sensitive() bool { return false }
func (m blockSchema) Deprecated() string { return deprecated(m.block.Block.Deprecated) }
Expand Down
Loading
Loading