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

Implement data source filtering on string lists. #188

merged 1 commit into from
Dec 8, 2021

Conversation

kaorihinata
Copy link
Contributor

@kaorihinata kaorihinata commented Dec 7, 2021

Description

Previously, attempting to filter a data source on string lists (like the locations field) would silently fail. This change implements filtering on such fields by expanding valuesLoop. It's probably possible to make things a bit simpler by reworking structToMap (and possibly more) if someone were to feel so inclined.

For example, it is now possible to do:

data "vultr_region" "server_region" {
  filter {
    name   = "city"
    values = ["Tokyo"]
  }
  filter {
    name   = "country"
    values = ["JP"]
  }
}

data "vultr_plan" "server_plan" {
  filter {
    name   = "type"
    values = ["vc2"]
  }
  filter {
    name   = "vcpu_count"
    values = [2]
  }
  filter {
    name   = "ram"
    values = [4096]
  }
  filter {
    name   = "locations"
    values = [data.vultr_region.server_region.id]
  }
}

...and the result would be, correctly, a single plan which depends on the existence of that plan at the Tokyo, Japan location. This makes it possible to depend on the existence of a specific plan, at a specific location, and a failure to find that plan will result in an earlier failure than if we had attempted to blindly create the resource. This also restores the ability to find resources without having to depend on directly referencing the ID, which is not always a meaningful value depending on the resource type.

Additionally, this will also make it possible to match against the new sao location (or future locations with special requirements) without having to know what custom ID suffix was given to it.

Related Issues

Closes #184.

Checklist:

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you linted your code locally prior to submission?
  • Have you successfully ran tests with your changes locally?

Previously, attempting to filter a data source on string lists (like the
locations field) would silently fail. This change implements filtering on
such fields by expanding valuesLoop. It's probably possible to make things
a bit simpler by reworking structToMap (and possibly more) if someone were
to feel so inclined.
@ddymko ddymko self-requested a review December 7, 2021 19:44
@ddymko
Copy link
Contributor

ddymko commented Dec 7, 2021

@kaorihinata Thanks for the PR we'll look at it today and look to merge/cut a new release tomorrow.

Copy link
Contributor

@ddymko ddymko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally - looks good

@ddymko ddymko merged commit b7df91d into vultr:master Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] - Filtering a vultr_plan on locations doesn't appear to perform a meaningful action.
2 participants