Skip to content

Commit

Permalink
helper/schema: Rename Timeout resource block to Timeouts (#12533)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
catsby authored Mar 9, 2017
1 parent 3c1ec9d commit 3fdeacd
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
4 changes: 4 additions & 0 deletions builtin/providers/aws/resource_aws_db_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,10 @@ resource "aws_db_instance" "bar" {
backup_retention_period = 0
parameter_group_name = "default.mysql5.6"
timeouts {
create = "30m"
}
}`

var testAccAWSDBInstanceConfigKmsKeyId = `
Expand Down
2 changes: 1 addition & 1 deletion helper/schema/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}},
Expand Down
3 changes: 2 additions & 1 deletion helper/schema/resource_timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

const TimeoutKey = "e2bfb730-ecaa-11e6-8f88-34363bc7c4c0"
const TimeoutsConfigKey = "timeouts"

const (
TimeoutCreate = "create"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions helper/schema/resource_timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
},
Expand Down
2 changes: 1 addition & 1 deletion helper/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions helper/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -4785,7 +4785,7 @@ func TestSchemaMap_Validate(t *testing.T) {
},

Config: map[string]interface{}{
"timeout": "bar",
TimeoutsConfigKey: "bar",
},

Err: false,
Expand Down
4 changes: 2 additions & 2 deletions website/source/docs/configuration/resources.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -122,7 +122,7 @@ resource "aws_db_instance" "timeout_example" {
name = "mydb"
[...]
timeout {
timeouts {
create = "60m"
delete = "2h"
}
Expand Down

0 comments on commit 3fdeacd

Please sign in to comment.