From 3fdeacdca79afb9746fe8986c1b8625d019eb49c Mon Sep 17 00:00:00 2001 From: Clint Date: Thu, 9 Mar 2017 14:40:14 -0600 Subject: [PATCH] helper/schema: Rename Timeout resource block to Timeouts (#12533) helper/schema: Rename Timeout resource block to Timeouts - Pluralize configuration argument name to better represent that there is one block for many timeouts - use a const for the configuration timeouts key - update docs --- builtin/providers/aws/resource_aws_db_instance_test.go | 4 ++++ helper/schema/resource_test.go | 2 +- helper/schema/resource_timeout.go | 3 ++- helper/schema/resource_timeout_test.go | 6 +++--- helper/schema/schema.go | 2 +- helper/schema/schema_test.go | 4 ++-- website/source/docs/configuration/resources.html.md | 4 ++-- 7 files changed, 15 insertions(+), 10 deletions(-) diff --git a/builtin/providers/aws/resource_aws_db_instance_test.go b/builtin/providers/aws/resource_aws_db_instance_test.go index 779e30920..56f890532 100644 --- a/builtin/providers/aws/resource_aws_db_instance_test.go +++ b/builtin/providers/aws/resource_aws_db_instance_test.go @@ -622,6 +622,10 @@ resource "aws_db_instance" "bar" { backup_retention_period = 0 parameter_group_name = "default.mysql5.6" + + timeouts { + create = "30m" + } }` var testAccAWSDBInstanceConfigKmsKeyId = ` diff --git a/helper/schema/resource_test.go b/helper/schema/resource_test.go index f98aa5c43..67dfaa435 100644 --- a/helper/schema/resource_test.go +++ b/helper/schema/resource_test.go @@ -156,7 +156,7 @@ func TestResourceDiff_Timeout_diff(t *testing.T) { raw, err := config.NewRawConfig( map[string]interface{}{ "foo": 42, - "timeout": []map[string]interface{}{ + "timeouts": []map[string]interface{}{ map[string]interface{}{ "create": "2h", }}, diff --git a/helper/schema/resource_timeout.go b/helper/schema/resource_timeout.go index 908d3e406..445819f0f 100644 --- a/helper/schema/resource_timeout.go +++ b/helper/schema/resource_timeout.go @@ -10,6 +10,7 @@ import ( ) const TimeoutKey = "e2bfb730-ecaa-11e6-8f88-34363bc7c4c0" +const TimeoutsConfigKey = "timeouts" const ( TimeoutCreate = "create" @@ -60,7 +61,7 @@ func (t *ResourceTimeout) ConfigDecode(s *Resource, c *terraform.ResourceConfig) *t = *raw.(*ResourceTimeout) } - if raw, ok := c.Config["timeout"]; ok { + if raw, ok := c.Config[TimeoutsConfigKey]; ok { if configTimeouts, ok := raw.([]map[string]interface{}); ok { for _, timeoutValues := range configTimeouts { // loop through each Timeout given in the configuration and validate they diff --git a/helper/schema/resource_timeout_test.go b/helper/schema/resource_timeout_test.go index 6e6b2604a..ad036600b 100644 --- a/helper/schema/resource_timeout_test.go +++ b/helper/schema/resource_timeout_test.go @@ -63,8 +63,8 @@ func TestResourceTimeout_ConfigDecode_badkey(t *testing.T) { raw, err := config.NewRawConfig( map[string]interface{}{ - "foo": "bar", - "timeout": c.Config, + "foo": "bar", + TimeoutsConfigKey: c.Config, }) if err != nil { t.Fatalf("err: %s", err) @@ -104,7 +104,7 @@ func TestResourceTimeout_ConfigDecode(t *testing.T) { raw, err := config.NewRawConfig( map[string]interface{}{ "foo": "bar", - "timeout": []map[string]interface{}{ + TimeoutsConfigKey: []map[string]interface{}{ map[string]interface{}{ "create": "2m", }, diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 05d21c7ff..f49dba577 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -1327,7 +1327,7 @@ func (m schemaMap) validateObject( if m, ok := raw.(map[string]interface{}); ok { for subk, _ := range m { if _, ok := schema[subk]; !ok { - if subk == "timeout" { + if subk == TimeoutsConfigKey { continue } es = append(es, fmt.Errorf( diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 4119b7ff5..294712993 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -4774,7 +4774,7 @@ func TestSchemaMap_Validate(t *testing.T) { Err: false, }, - "special timeout field": { + "special timeouts field": { Schema: map[string]*Schema{ "availability_zone": &Schema{ Type: TypeString, @@ -4785,7 +4785,7 @@ func TestSchemaMap_Validate(t *testing.T) { }, Config: map[string]interface{}{ - "timeout": "bar", + TimeoutsConfigKey: "bar", }, Err: false, diff --git a/website/source/docs/configuration/resources.html.md b/website/source/docs/configuration/resources.html.md index ab15b6744..1cc79bda4 100644 --- a/website/source/docs/configuration/resources.html.md +++ b/website/source/docs/configuration/resources.html.md @@ -102,7 +102,7 @@ wildcard (e.g. `"rout*"`) is **not** supported. ### Timeouts -Individual Resources may provide a `timeout` block to enable users to configure the +Individual Resources may provide a `timeouts` block to enable users to configure the amount of time a specific operation is allowed to take before being considered an error. For example, the [aws_db_instance](/docs/providers/aws/r/db_instance.html#timeouts) @@ -122,7 +122,7 @@ resource "aws_db_instance" "timeout_example" { name = "mydb" [...] - timeout { + timeouts { create = "60m" delete = "2h" }