helper/schema: Guard against a panic if Timeout is not properly
structured
This commit is contained in:
parent
b58709aa91
commit
aa3677cd89
|
@ -61,52 +61,55 @@ func (t *ResourceTimeout) ConfigDecode(s *Resource, c *terraform.ResourceConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
if raw, ok := c.Config["timeout"]; ok {
|
if raw, ok := c.Config["timeout"]; ok {
|
||||||
configTimeouts := raw.([]map[string]interface{})
|
if configTimeouts, ok := raw.([]map[string]interface{}); ok {
|
||||||
for _, timeoutValues := range configTimeouts {
|
for _, timeoutValues := range configTimeouts {
|
||||||
// loop through each Timeout given in the configuration and validate they
|
// loop through each Timeout given in the configuration and validate they
|
||||||
// the Timeout defined in the resource
|
// the Timeout defined in the resource
|
||||||
for timeKey, timeValue := range timeoutValues {
|
for timeKey, timeValue := range timeoutValues {
|
||||||
// validate that we're dealing with the normal CRUD actions
|
// validate that we're dealing with the normal CRUD actions
|
||||||
var found bool
|
var found bool
|
||||||
for _, key := range timeoutKeys() {
|
for _, key := range timeoutKeys() {
|
||||||
if timeKey == key {
|
if timeKey == key {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
return fmt.Errorf("Unsupported Timeout configuration key found (%s)", timeKey)
|
return fmt.Errorf("Unsupported Timeout configuration key found (%s)", timeKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get timeout
|
// Get timeout
|
||||||
rt, err := time.ParseDuration(timeValue.(string))
|
rt, err := time.ParseDuration(timeValue.(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error parsing Timeout for (%s): %s", timeKey, err)
|
return fmt.Errorf("Error parsing Timeout for (%s): %s", timeKey, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var timeout *time.Duration
|
var timeout *time.Duration
|
||||||
switch timeKey {
|
switch timeKey {
|
||||||
case TimeoutCreate:
|
case TimeoutCreate:
|
||||||
timeout = t.Create
|
timeout = t.Create
|
||||||
case TimeoutUpdate:
|
case TimeoutUpdate:
|
||||||
timeout = t.Update
|
timeout = t.Update
|
||||||
case TimeoutRead:
|
case TimeoutRead:
|
||||||
timeout = t.Read
|
timeout = t.Read
|
||||||
case TimeoutDelete:
|
case TimeoutDelete:
|
||||||
timeout = t.Delete
|
timeout = t.Delete
|
||||||
case TimeoutDefault:
|
case TimeoutDefault:
|
||||||
timeout = t.Default
|
timeout = t.Default
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the resource has not delcared this in the definition, then error
|
// If the resource has not delcared this in the definition, then error
|
||||||
// with an unsupported message
|
// with an unsupported message
|
||||||
if timeout == nil {
|
if timeout == nil {
|
||||||
return unsupportedTimeoutKeyError(timeKey)
|
return unsupportedTimeoutKeyError(timeKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
*timeout = rt
|
*timeout = rt
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.Printf("[WARN] Invalid Timeout structure found, skipping timeouts")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue