From f153720a36bcf3c0823eb0f4e5a9b6e7495a82b5 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 30 Oct 2018 14:14:23 -0400 Subject: [PATCH] add checks for timeouts attributes and blocks Don't overwrite anything the provider defined, in order to maintain existing behavior. Change strings to pre-defined constants --- helper/schema/core_schema.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/helper/schema/core_schema.go b/helper/schema/core_schema.go index a01653b803..85e8b8c5b3 100644 --- a/helper/schema/core_schema.go +++ b/helper/schema/core_schema.go @@ -172,48 +172,52 @@ func (r *Resource) CoreConfigSchema() *configschema.Block { } } - // insert configured timeout values into the schema - if r.Timeouts != nil { + _, timeoutsAttr := block.Attributes[TimeoutsConfigKey] + _, timeoutsBlock := block.BlockTypes[TimeoutsConfigKey] + + // Insert configured timeout values into the schema, as long as the schema + // didn't define anything else by that name. + if r.Timeouts != nil && !timeoutsAttr && !timeoutsBlock { timeouts := configschema.Block{ Attributes: map[string]*configschema.Attribute{}, } if r.Timeouts.Create != nil { - timeouts.Attributes["create"] = &configschema.Attribute{ + timeouts.Attributes[TimeoutCreate] = &configschema.Attribute{ Type: cty.String, Optional: true, } } if r.Timeouts.Read != nil { - timeouts.Attributes["read"] = &configschema.Attribute{ + timeouts.Attributes[TimeoutRead] = &configschema.Attribute{ Type: cty.String, Optional: true, } } if r.Timeouts.Update != nil { - timeouts.Attributes["update"] = &configschema.Attribute{ + timeouts.Attributes[TimeoutUpdate] = &configschema.Attribute{ Type: cty.String, Optional: true, } } if r.Timeouts.Delete != nil { - timeouts.Attributes["delete"] = &configschema.Attribute{ + timeouts.Attributes[TimeoutDelete] = &configschema.Attribute{ Type: cty.String, Optional: true, } } if r.Timeouts.Default != nil { - timeouts.Attributes["default"] = &configschema.Attribute{ + timeouts.Attributes[TimeoutDefault] = &configschema.Attribute{ Type: cty.String, Optional: true, } } - block.BlockTypes["timeouts"] = &configschema.NestedBlock{ + block.BlockTypes[TimeoutsConfigKey] = &configschema.NestedBlock{ Nesting: configschema.NestingSingle, Block: timeouts, }