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.
This commit is contained in:
James Bardin 2018-07-19 13:53:31 -04:00 committed by Martin Atkins
parent 3855b79736
commit 0120d53baf
2 changed files with 5 additions and 5 deletions

View File

@ -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

View File

@ -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))
}
})
}