better error handling for type assertions

This commit is contained in:
Alex Pilon 2019-08-06 20:49:55 -04:00
parent a56e53ec5b
commit c993fc3c1b
No known key found for this signature in database
GPG Key ID: 95659F6AEFC48D7E
1 changed files with 7 additions and 2 deletions

View File

@ -293,8 +293,13 @@ func validateFn(c *terraform.ResourceConfig) (ws []string, es []error) {
// Validate service level configs
services, ok := c.Get("service")
if ok {
for _, svc := range services.([]interface{}) {
service := svc.(map[string]interface{})
for i, svc := range services.([]interface{}) {
service, ok := svc.(map[string]interface{})
if !ok {
es = append(es, fmt.Errorf("service %d: must be a block", i))
continue
}
strategy, ok := service["strategy"].(string)
if ok && !updateStrategies[strategy] {
es = append(es, errors.New(strategy+" is not a valid update strategy."))