Skip to content

Commit

Permalink
Implement data source filtering on string lists. (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaorihinata authored Dec 8, 2021
1 parent fa92d09 commit b7df91d
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions vultr/data_source_vultr_common_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,33 @@ func filterLoop(f []filter, m map[string]interface{}) bool {
return true
}

func valuesLoop(values []string, i interface{}) bool {
for _, v := range values {
if v == i {
return true
func valuesLoop(values []string, actual interface{}) bool {
switch actual.(type) {
case []interface{}:
// It's an array of strings, so something like: location
var found bool
for _, i := range values {
found = false
for _, j := range actual.([]interface{}) {
if i == j {
found = true
break
}
}
if !found {
return false
}
}
return true
default:
// It's a string, so something like: ram, type, vcpu_count
for _, i := range values {
if actual == i {
return true
}
}
return false
}
return false
}

func dataSourceFiltersSchema() *schema.Schema {
Expand Down

0 comments on commit b7df91d

Please sign in to comment.