From c8a2f3840b4a548cb6639051cfde424a4f5fa940 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 14 May 2019 18:05:30 -0400 Subject: [PATCH] remove SkipCoreTypeCheck This experiment is no longer needed for handling computed blocks, since the legacy SDK can't reasonably handle Dynamic types, we need to remove this before the final release. Remove LegacySchema functions as well, since handling SkipCoreTypeCheck was the only thing left they were handling. --- helper/schema/core_schema.go | 8 ------ helper/schema/core_schema_test.go | 22 ---------------- helper/schema/schema.go | 36 -------------------------- helper/schema/shims.go | 42 ------------------------------- 4 files changed, 108 deletions(-) diff --git a/helper/schema/core_schema.go b/helper/schema/core_schema.go index d563ab8ca..875677eb3 100644 --- a/helper/schema/core_schema.go +++ b/helper/schema/core_schema.go @@ -174,14 +174,6 @@ func (s *Schema) coreConfigSchemaBlock() *configschema.NestedBlock { // coreConfigSchemaType determines the core config schema type that corresponds // to a particular schema's type. func (s *Schema) coreConfigSchemaType() cty.Type { - if s.SkipCoreTypeCheck { - // If we're preparing a schema for Terraform Core and the schema is - // asking us to skip the Core type-check then we'll tell core that this - // attribute is dynamically-typed, so it'll just pass through anything - // and let us validate it on the plugin side. - return cty.DynamicPseudoType - } - switch s.Type { case TypeString: return cty.String diff --git a/helper/schema/core_schema_test.go b/helper/schema/core_schema_test.go index 92fe194af..7d4b32e01 100644 --- a/helper/schema/core_schema_test.go +++ b/helper/schema/core_schema_test.go @@ -445,28 +445,6 @@ func TestSchemaMapCoreConfigSchema(t *testing.T) { BlockTypes: map[string]*configschema.NestedBlock{}, }), }, - "skip core type check": { - map[string]*Schema{ - "list": { - Type: TypeList, - ConfigMode: SchemaConfigModeAttr, - SkipCoreTypeCheck: true, - Optional: true, - Elem: &Resource{ - Schema: map[string]*Schema{}, - }, - }, - }, - testResource(&configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "list": { - Type: cty.DynamicPseudoType, - Optional: true, // Just so we can progress to provider-driven validation and return the error there - }, - }, - BlockTypes: map[string]*configschema.NestedBlock{}, - }), - }, } for name, test := range tests { diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 140cdff22..6a3c15a64 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -95,34 +95,6 @@ type Schema struct { // behavior, and SchemaConfigModeBlock is not permitted. ConfigMode SchemaConfigMode - // SkipCoreTypeCheck, if set, will advertise this attribute to Terraform Core - // has being dynamically-typed rather than deriving a type from the schema. - // This has the effect of making Terraform Core skip all type-checking of - // the value, and thus leaves all type checking up to a combination of this - // SDK and the provider's own code. - // - // This flag does nothing for Terraform versions prior to v0.12, because - // in prior versions there was no Core-side typecheck anyway. - // - // The most practical effect of this flag is to allow object-typed schemas - // (specified with Elem: schema.Resource) to pass through Terraform Core - // even without all of the object type attributes specified, which may be - // useful when using ConfigMode: SchemaConfigModeAttr to achieve - // nested-block-like behaviors while using attribute syntax. - // - // However, by doing so we require type information to be sent and stored - // per-object rather than just once statically in the schema, and so this - // will change the wire serialization of a resource type in state. Changing - // the value of SkipCoreTypeCheck will therefore require a state migration - // if there has previously been any release of the provider compatible with - // Terraform v0.12. - // - // SkipCoreTypeCheck can only be set when ConfigMode is SchemaConfigModeAttr, - // because nested blocks cannot be decoded by Terraform Core without at - // least shallow information about the next level of nested attributes and - // blocks. - SkipCoreTypeCheck bool - // If one of these is set, then this item can come from the configuration. // Both cannot be set. If Optional is set, the value is optional. If // Required is set, the value is required. @@ -735,8 +707,6 @@ func (m schemaMap) internalValidate(topSchemaMap schemaMap, attrsOnly bool) erro computedOnly := v.Computed && !v.Optional - isBlock := false - switch v.ConfigMode { case SchemaConfigModeBlock: if _, ok := v.Elem.(*Resource); !ok { @@ -748,7 +718,6 @@ func (m schemaMap) internalValidate(topSchemaMap schemaMap, attrsOnly bool) erro if computedOnly { return fmt.Errorf("%s: ConfigMode of block cannot be used for computed schema", k) } - isBlock = true case SchemaConfigModeAttr: // anything goes case SchemaConfigModeAuto: @@ -756,7 +725,6 @@ func (m schemaMap) internalValidate(topSchemaMap schemaMap, attrsOnly bool) erro // and that's impossible inside an attribute, we require it to be // explicitly overridden as mode "Attr" for clarity. if _, ok := v.Elem.(*Resource); ok { - isBlock = true if attrsOnly { return fmt.Errorf("%s: in *schema.Resource with ConfigMode of attribute, so must also have ConfigMode of attribute", k) } @@ -765,10 +733,6 @@ func (m schemaMap) internalValidate(topSchemaMap schemaMap, attrsOnly bool) erro return fmt.Errorf("%s: invalid ConfigMode value", k) } - if isBlock && v.SkipCoreTypeCheck { - return fmt.Errorf("%s: SkipCoreTypeCheck must be false unless ConfigMode is attribute", k) - } - if v.Computed && v.Default != nil { return fmt.Errorf("%s: Default must be nil if computed", k) } diff --git a/helper/schema/shims.go b/helper/schema/shims.go index d43028e58..203d01704 100644 --- a/helper/schema/shims.go +++ b/helper/schema/shims.go @@ -113,45 +113,3 @@ func JSONMapToStateValue(m map[string]interface{}, block *configschema.Block) (c func StateValueFromInstanceState(is *terraform.InstanceState, ty cty.Type) (cty.Value, error) { return is.AttrsAsObjectValue(ty) } - -// LegacyResourceSchema takes a *Resource and returns a deep copy with 0.12 specific -// features removed. This is used by the shims to get a configschema that -// directly matches the structure of the schema.Resource. -func LegacyResourceSchema(r *Resource) *Resource { - if r == nil { - return nil - } - // start with a shallow copy - newResource := new(Resource) - *newResource = *r - newResource.Schema = map[string]*Schema{} - - for k, s := range r.Schema { - newResource.Schema[k] = LegacySchema(s) - } - - return newResource -} - -// LegacySchema takes a *Schema and returns a deep copy with some 0.12-specific -// features disabled. This is used by the shims to get a configschema that -// better reflects the given schema.Resource, without any adjustments we -// make for when sending a schema to Terraform Core. -func LegacySchema(s *Schema) *Schema { - if s == nil { - return nil - } - // start with a shallow copy - newSchema := new(Schema) - *newSchema = *s - newSchema.SkipCoreTypeCheck = false - - switch e := newSchema.Elem.(type) { - case *Schema: - newSchema.Elem = LegacySchema(e) - case *Resource: - newSchema.Elem = LegacyResourceSchema(e) - } - - return newSchema -}