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

Added filter block to databricks_instance_profiles data source #2988

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ehab-eb
Copy link
Contributor

@ehab-eb ehab-eb commented Dec 4, 2023

Changes

This PR adds filtering capabilities to the databricks_instance_profiles data source. A new optional block filter is introduced that exposes two arguments:

  1. name: This takes the name of the instance profile attribute to filter on
  2. pattern: This takes a regex pattern to use for filtering based on the field specified in the name argument

Only one filter block can be specified.

Tests

  • make test run locally
  • relevant change in docs/ folder
  • covered with integration tests in internal/acceptance
  • relevant acceptance tests are passing
  • using Go SDK

@ehab-eb ehab-eb requested review from a team as code owners December 4, 2023 11:19
@ehab-eb ehab-eb requested review from hectorcast-db and removed request for a team December 4, 2023 11:19
aws/data_instance_profiles.go Outdated Show resolved Hide resolved
@ehab-eb ehab-eb force-pushed the filter_instance_profiles branch 3 times, most recently from 248f98d to 8732f62 Compare December 5, 2023 15:46
@codecov-commenter
Copy link

Codecov Report

Merging #2988 (b1c0f85) into master (2359eb0) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            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     
Files Coverage Δ
aws/data_instance_profiles.go 94.28% <100.00%> (+4.28%) ⬆️

... and 1 file with indirect coverage changes

Comment on lines +49 to +53
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"))
}
Copy link
Contributor

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

Comment on lines +55 to +57
if data.Filter.Name == "" {
return fmt.Errorf("field `name` cannot be empty")
}
Copy link
Contributor

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)
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants