"log"
"time"
+ "github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/copystructure"
)
}
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
- // the Timeout defined in the resource
- for timeKey, timeValue := range timeoutValues {
- // validate that we're dealing with the normal CRUD actions
- var found bool
- for _, key := range timeoutKeys() {
- if timeKey == key {
- found = true
- break
- }
- }
+ var rawTimeouts []map[string]interface{}
+ switch raw := raw.(type) {
+ case map[string]interface{}:
+ rawTimeouts = append(rawTimeouts, raw)
+ case []map[string]interface{}:
+ rawTimeouts = raw
+ case string:
+ if raw == config.UnknownVariableValue {
+ // Timeout is not defined in the config
+ // Defaults will be used instead
+ return nil
+ } else {
+ log.Printf("[ERROR] Invalid timeout value: %q", raw)
+ return fmt.Errorf("Invalid Timeout value found")
+ }
+ default:
+ log.Printf("[ERROR] Invalid timeout structure: %#v", raw)
+ return fmt.Errorf("Invalid Timeout structure found")
+ }
- if !found {
- return fmt.Errorf("Unsupported Timeout configuration key found (%s)", timeKey)
+ for _, timeoutValues := range rawTimeouts {
+ for timeKey, timeValue := range timeoutValues {
+ // validate that we're dealing with the normal CRUD actions
+ var found bool
+ for _, key := range timeoutKeys() {
+ if timeKey == key {
+ found = true
+ break
}
+ }
- // Get timeout
- rt, err := time.ParseDuration(timeValue.(string))
- if err != nil {
- return fmt.Errorf("Error parsing Timeout for (%s): %s", timeKey, err)
- }
+ if !found {
+ return fmt.Errorf("Unsupported Timeout configuration key found (%s)", timeKey)
+ }
- var timeout *time.Duration
- switch timeKey {
- case TimeoutCreate:
- timeout = t.Create
- case TimeoutUpdate:
- timeout = t.Update
- case TimeoutRead:
- timeout = t.Read
- case TimeoutDelete:
- timeout = t.Delete
- case TimeoutDefault:
- timeout = t.Default
- }
+ // Get timeout
+ rt, err := time.ParseDuration(timeValue.(string))
+ if err != nil {
+ return fmt.Errorf("Error parsing %q timeout: %s", timeKey, err)
+ }
- // If the resource has not delcared this in the definition, then error
- // with an unsupported message
- if timeout == nil {
- return unsupportedTimeoutKeyError(timeKey)
- }
+ var timeout *time.Duration
+ switch timeKey {
+ case TimeoutCreate:
+ timeout = t.Create
+ case TimeoutUpdate:
+ timeout = t.Update
+ case TimeoutRead:
+ timeout = t.Read
+ case TimeoutDelete:
+ timeout = t.Delete
+ case TimeoutDefault:
+ timeout = t.Default
+ }
- *timeout = rt
+ // If the resource has not delcared this in the definition, then error
+ // with an unsupported message
+ if timeout == nil {
+ return unsupportedTimeoutKeyError(timeKey)
}
+
+ *timeout = rt
}
- } else {
- log.Printf("[WARN] Invalid Timeout structure found, skipping timeouts")
+ return nil
}
}