From 61e50b92359d42658f9ec39e6c861f5da021b7b2 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Wed, 8 Mar 2017 11:34:39 -0600 Subject: [PATCH 1/3] helper/schema: Rename Timeout resource block to Timeouts Pluralize configuration argument name to better represent that there is one block for many timeouts --- builtin/providers/aws/resource_aws_db_instance_test.go | 4 ++++ helper/schema/resource_test.go | 2 +- helper/schema/resource_timeout.go | 2 +- helper/schema/resource_timeout_test.go | 6 +++--- helper/schema/schema.go | 2 +- helper/schema/schema_test.go | 4 ++-- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/builtin/providers/aws/resource_aws_db_instance_test.go b/builtin/providers/aws/resource_aws_db_instance_test.go index 779e30920552..56f8905327c9 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 f98aa5c43134..67dfaa435263 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 908d3e406010..0001fefbb642 100644 --- a/helper/schema/resource_timeout.go +++ b/helper/schema/resource_timeout.go @@ -60,7 +60,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["timeouts"]; 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 6e6b2604ac31..b684af4a8367 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", + "timeouts": 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{}{ + "timeouts": []map[string]interface{}{ map[string]interface{}{ "create": "2m", }, diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 05d21c7ff178..45f94d26e18c 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 == "timeouts" { continue } es = append(es, fmt.Errorf( diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 4119b7ff5862..8a84003b2d20 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", + "timeouts": "bar", }, Err: false, From baee4c6291a386e5cd01c1475a23bcf76fea509f Mon Sep 17 00:00:00 2001 From: clint shryock Date: Thu, 9 Mar 2017 14:20:31 -0600 Subject: [PATCH 2/3] use a const for the configuration timeouts key --- helper/schema/resource_timeout.go | 3 ++- helper/schema/resource_timeout_test.go | 6 +++--- helper/schema/schema.go | 2 +- helper/schema/schema_test.go | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/helper/schema/resource_timeout.go b/helper/schema/resource_timeout.go index 0001fefbb642..445819f0f956 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["timeouts"]; 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 b684af4a8367..ad036600b5ba 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", - "timeouts": 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", - "timeouts": []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 45f94d26e18c..f49dba577121 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 == "timeouts" { + if subk == TimeoutsConfigKey { continue } es = append(es, fmt.Errorf( diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 8a84003b2d20..29471299338a 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -4785,7 +4785,7 @@ func TestSchemaMap_Validate(t *testing.T) { }, Config: map[string]interface{}{ - "timeouts": "bar", + TimeoutsConfigKey: "bar", }, Err: false, From d9d10e9c1639953a4d8dce39fead62cf7bcbf68d Mon Sep 17 00:00:00 2001 From: clint shryock Date: Thu, 9 Mar 2017 14:27:54 -0600 Subject: [PATCH 3/3] update docs --- website/source/docs/configuration/resources.html.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/source/docs/configuration/resources.html.md b/website/source/docs/configuration/resources.html.md index ab15b674423a..1cc79bda4ab0 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" }