-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Add the ability to do basic filtering with azurerm_subscriptions #2429
Add the ability to do basic filtering with azurerm_subscriptions #2429
Conversation
…ce azurerm_subscriptions
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.
hey @tiwood
Thanks for this PR :)
I've taken a look through and left some comments inline but this mostly LGTM - if we can fix up the comments (and the tests pass) this otherwise LGTM 👍
Thanks!
azurerm/data_source_subscriptions.go
Outdated
|
||
//check if the display name matches the 'contains' comparison | ||
if displayNameContains != "" { | ||
if !strings.Contains(strings.ToLower(*val.DisplayName), displayNameContains) { |
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.
rather than iterating over the results multiple times, I'd suggest it'd be easiest to do this check here - what do you think?
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 moved the check to the bottom and simplified it a bit (check against the slice val). This saved a few lines of code, but I'm not sure if this is what you meant. 🤓️
azurerm/data_source_subscriptions.go
Outdated
subscriptions := make([]map[string]interface{}, 0) | ||
for results.NotDone() { | ||
val := results.Value() | ||
|
||
//check if the display name prefix matches the given input | ||
if displayNamePrefix != "" { | ||
if !strings.HasPrefix(strings.ToLower(*val.DisplayName), displayNamePrefix) { |
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.
rather than iterating over the results multiple times, I'd suggest it'd be easiest to do this check here - what do you think?
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.
see above.
There are no arguments available for this data source. | ||
-> **NOTE** The comparisons are case-insensitive. | ||
|
||
* `display_name_prefix` - (Optional) This argument can be used to only return subscriptions that start with this given string. |
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.
* `display_name_prefix` - (Optional) This argument can be used to only return subscriptions that start with this given string. | |
* `display_name_prefix` - (Optional) A case-insensitive prefix which can be used to filter on the `display_name` field |
thanks @tombuildsstuff, I made the requested changes. |
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.
LGTM - thanks for this @tiwood
(given this test is based on the Subscription name, we're unable to add tests for these at this time since we're not able to dynamically provision subscriptions at the moment - we'll circle back to this when we can)
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks! |
This adds two new optional parameters to the data source azurerm_subscriptions:
display_name_prefix
display_name_contains
Example:
This gives: