Normalize sets, don’t check for missing services.

This commit is contained in:
Joern Barthel 2016-08-09 14:42:09 +02:00
parent 67bf13fccf
commit d0278ecf0f
1 changed files with 22 additions and 6 deletions

View File

@ -99,19 +99,35 @@ func dataSourceAwsIPRangesRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error setting sync token: %s", err) return fmt.Errorf("Error setting sync token: %s", err)
} }
get := func(key string) *schema.Set {
set := d.Get(key).(*schema.Set)
for _, e := range set.List() {
s := e.(string)
set.Remove(s)
set.Add(strings.ToLower(s))
}
return set
}
var ( var (
regions = d.Get("regions").(*schema.Set) regions = get("regions")
services = d.Get("services").(*schema.Set) services = get("services")
noRegionFilter = regions.Len() == 0 noRegionFilter = regions.Len() == 0
noServiceFilter = services.Len() == 0 prefixes []string
prefixes []string
) )
for _, e := range result.Prefixes { for _, e := range result.Prefixes {
var ( var (
matchRegion = noRegionFilter || regions.Contains(strings.ToLower(e.Region)) matchRegion = noRegionFilter || regions.Contains(strings.ToLower(e.Region))
matchService = noServiceFilter || services.Contains(strings.ToLower(e.Service)) matchService = services.Contains(strings.ToLower(e.Service))
) )
if matchRegion && matchService { if matchRegion && matchService {