Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement data source filtering on string lists. #188

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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