-
Notifications
You must be signed in to change notification settings - Fork 386
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
Added filter
block to databricks_instance_profiles
data source
#2988
base: main
Are you sure you want to change the base?
Conversation
248f98d
to
8732f62
Compare
8732f62
to
b1c0f85
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #2988 +/- ##
==========================================
+ Coverage 84.14% 84.17% +0.03%
==========================================
Files 159 159
Lines 13897 13912 +15
==========================================
+ Hits 11694 11711 +17
+ Misses 1534 1533 -1
+ Partials 669 668 -1
|
var fieldNames []string | ||
val := reflect.ValueOf(instanceProfileData{}) | ||
for i := 0; i < val.Type().NumField(); i++ { | ||
fieldNames = append(fieldNames, val.Type().Field(i).Tag.Get("json")) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can avoid having this if we expose listAllFields
function implemented in #3044 - in this case it will handle inherited fields correctly
if data.Filter.Name == "" { | ||
return fmt.Errorf("field `name` cannot be empty") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we can move this condition after the line 48
_ = json.Unmarshal(m, &ipMap) | ||
val := ipMap[filter.Name] | ||
stringVal := fmt.Sprint(val) | ||
re := regexp.MustCompile(filter.Pattern) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use .Compile
and check for the error. Also, it's very inefficient - it's better to check validity of the regexp earlier, around line 46, compile regexp, and pass it explicitly. Otherwise we'll compile it on each function invocation.
Changes
This PR adds filtering capabilities to the
databricks_instance_profiles
data source. A new optional blockfilter
is introduced that exposes two arguments:name
: This takes the name of the instance profile attribute to filter onpattern
: This takes a regex pattern to use for filtering based on the field specified in thename
argumentOnly one
filter
block can be specified.Tests
make test
run locallydocs/
folderinternal/acceptance