From 0120d53baf1abb00a2f386484f0011e2187e6247 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 19 Jul 2018 13:53:31 -0400 Subject: [PATCH] only add "id" to top-level resources Make sure we only add "id" to the top-level resource, since Resource is also used for nested blocks. --- helper/schema/core_schema.go | 4 ++-- helper/schema/core_schema_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/helper/schema/core_schema.go b/helper/schema/core_schema.go index bdabf1324..f16cf3e64 100644 --- a/helper/schema/core_schema.go +++ b/helper/schema/core_schema.go @@ -73,7 +73,7 @@ func (s *Schema) coreConfigSchemaAttribute() *configschema.Attribute { // of Resource, and will panic otherwise. func (s *Schema) coreConfigSchemaBlock() *configschema.NestedBlock { ret := &configschema.NestedBlock{} - if nested := s.Elem.(*Resource).CoreConfigSchema(); nested != nil { + if nested := s.Elem.(*Resource).coreConfigSchema(); nested != nil { ret.Block = *nested } switch s.Type { @@ -126,7 +126,7 @@ func (s *Schema) coreConfigSchemaType() cty.Type { // In practice we don't actually use this for normal schema // construction because we construct a NestedBlock in that // case instead. See schemaMap.CoreConfigSchema. - elemType = set.CoreConfigSchema().ImpliedType() + elemType = set.coreConfigSchema().ImpliedType() default: if set != nil { // Should never happen for a valid schema diff --git a/helper/schema/core_schema_test.go b/helper/schema/core_schema_test.go index 94669c788..aedd72ea4 100644 --- a/helper/schema/core_schema_test.go +++ b/helper/schema/core_schema_test.go @@ -304,9 +304,9 @@ func TestSchemaMapCoreConfigSchema(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { - got := schemaMap(test.Schema).CoreConfigSchema() - if !cmp.Equal(got, test.Want, typeComparer) { - cmp.Diff(got, test.Want, typeComparer) + got := (&Resource{Schema: test.Schema}).CoreConfigSchema() + if !cmp.Equal(got, test.Want, equateEmpty, typeComparer) { + t.Error(cmp.Diff(got, test.Want, equateEmpty, typeComparer)) } }) }