]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/terraform/helper/schema/resource_timeout.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / helper / schema / resource_timeout.go
index 445819f0f956a9035031d90d0b17d9aebf4f107d..9e422c1a6f075aea1e717d9030bdb6bb0bd78493 100644 (file)
@@ -5,6 +5,7 @@ import (
        "log"
        "time"
 
+       "github.com/hashicorp/terraform/config"
        "github.com/hashicorp/terraform/terraform"
        "github.com/mitchellh/copystructure"
 )
@@ -62,55 +63,70 @@ func (t *ResourceTimeout) ConfigDecode(s *Resource, c *terraform.ResourceConfig)
        }
 
        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
                }
        }