diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/schema/resource_timeout.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/helper/schema/resource_timeout.go | 98 |
1 files changed, 57 insertions, 41 deletions
diff --git a/vendor/github.com/hashicorp/terraform/helper/schema/resource_timeout.go b/vendor/github.com/hashicorp/terraform/helper/schema/resource_timeout.go index 445819f..9e422c1 100644 --- a/vendor/github.com/hashicorp/terraform/helper/schema/resource_timeout.go +++ b/vendor/github.com/hashicorp/terraform/helper/schema/resource_timeout.go | |||
@@ -5,6 +5,7 @@ import ( | |||
5 | "log" | 5 | "log" |
6 | "time" | 6 | "time" |
7 | 7 | ||
8 | "github.com/hashicorp/terraform/config" | ||
8 | "github.com/hashicorp/terraform/terraform" | 9 | "github.com/hashicorp/terraform/terraform" |
9 | "github.com/mitchellh/copystructure" | 10 | "github.com/mitchellh/copystructure" |
10 | ) | 11 | ) |
@@ -62,55 +63,70 @@ func (t *ResourceTimeout) ConfigDecode(s *Resource, c *terraform.ResourceConfig) | |||
62 | } | 63 | } |
63 | 64 | ||
64 | if raw, ok := c.Config[TimeoutsConfigKey]; ok { | 65 | if raw, ok := c.Config[TimeoutsConfigKey]; ok { |
65 | if configTimeouts, ok := raw.([]map[string]interface{}); ok { | 66 | var rawTimeouts []map[string]interface{} |
66 | for _, timeoutValues := range configTimeouts { | 67 | switch raw := raw.(type) { |
67 | // loop through each Timeout given in the configuration and validate they | 68 | case map[string]interface{}: |
68 | // the Timeout defined in the resource | 69 | rawTimeouts = append(rawTimeouts, raw) |
69 | for timeKey, timeValue := range timeoutValues { | 70 | case []map[string]interface{}: |
70 | // validate that we're dealing with the normal CRUD actions | 71 | rawTimeouts = raw |
71 | var found bool | 72 | case string: |
72 | for _, key := range timeoutKeys() { | 73 | if raw == config.UnknownVariableValue { |
73 | if timeKey == key { | 74 | // Timeout is not defined in the config |
74 | found = true | 75 | // Defaults will be used instead |
75 | break | 76 | return nil |
76 | } | 77 | } else { |
77 | } | 78 | log.Printf("[ERROR] Invalid timeout value: %q", raw) |
79 | return fmt.Errorf("Invalid Timeout value found") | ||
80 | } | ||
81 | default: | ||
82 | log.Printf("[ERROR] Invalid timeout structure: %#v", raw) | ||
83 | return fmt.Errorf("Invalid Timeout structure found") | ||
84 | } | ||
78 | 85 | ||
79 | if !found { | 86 | for _, timeoutValues := range rawTimeouts { |
80 | return fmt.Errorf("Unsupported Timeout configuration key found (%s)", timeKey) | 87 | for timeKey, timeValue := range timeoutValues { |
88 | // validate that we're dealing with the normal CRUD actions | ||
89 | var found bool | ||
90 | for _, key := range timeoutKeys() { | ||
91 | if timeKey == key { | ||
92 | found = true | ||
93 | break | ||
81 | } | 94 | } |
95 | } | ||
82 | 96 | ||
83 | // Get timeout | 97 | if !found { |
84 | rt, err := time.ParseDuration(timeValue.(string)) | 98 | return fmt.Errorf("Unsupported Timeout configuration key found (%s)", timeKey) |
85 | if err != nil { | 99 | } |
86 | return fmt.Errorf("Error parsing Timeout for (%s): %s", timeKey, err) | ||
87 | } | ||
88 | 100 | ||
89 | var timeout *time.Duration | 101 | // Get timeout |
90 | switch timeKey { | 102 | rt, err := time.ParseDuration(timeValue.(string)) |
91 | case TimeoutCreate: | 103 | if err != nil { |
92 | timeout = t.Create | 104 | return fmt.Errorf("Error parsing %q timeout: %s", timeKey, err) |
93 | case TimeoutUpdate: | 105 | } |
94 | timeout = t.Update | ||
95 | case TimeoutRead: | ||
96 | timeout = t.Read | ||
97 | case TimeoutDelete: | ||
98 | timeout = t.Delete | ||
99 | case TimeoutDefault: | ||
100 | timeout = t.Default | ||
101 | } | ||
102 | 106 | ||
103 | // If the resource has not delcared this in the definition, then error | 107 | var timeout *time.Duration |
104 | // with an unsupported message | 108 | switch timeKey { |
105 | if timeout == nil { | 109 | case TimeoutCreate: |
106 | return unsupportedTimeoutKeyError(timeKey) | 110 | timeout = t.Create |
107 | } | 111 | case TimeoutUpdate: |
112 | timeout = t.Update | ||
113 | case TimeoutRead: | ||
114 | timeout = t.Read | ||
115 | case TimeoutDelete: | ||
116 | timeout = t.Delete | ||
117 | case TimeoutDefault: | ||
118 | timeout = t.Default | ||
119 | } | ||
108 | 120 | ||
109 | *timeout = rt | 121 | // If the resource has not delcared this in the definition, then error |
122 | // with an unsupported message | ||
123 | if timeout == nil { | ||
124 | return unsupportedTimeoutKeyError(timeKey) | ||
110 | } | 125 | } |
126 | |||
127 | *timeout = rt | ||
111 | } | 128 | } |
112 | } else { | 129 | return nil |
113 | log.Printf("[WARN] Invalid Timeout structure found, skipping timeouts") | ||
114 | } | 130 | } |
115 | } | 131 | } |
116 | 132 | ||