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

Add the ability to do basic filtering with azurerm_subscriptions #2429

Merged
merged 4 commits into from
Dec 4, 2018

Conversation

tiwood
Copy link
Contributor

@tiwood tiwood commented Dec 3, 2018

This adds two new optional parameters to the data source azurerm_subscriptions:

  • display_name_prefix
  • display_name_contains

Example:

data "azurerm_subscriptions" "current" {
  display_name_prefix = "Sub_"
  display_name_contains = "_123"
}

output "available_subscriptions" {
  value = "${data.azurerm_subscriptions.current.subscriptions}"
}

This gives:

{
        display_name = Sub_FooBar_123,
        location_placement_id = Public_2014-09-01,
        quota_id = AAD_2015-09-01,
        spending_limit = On,
        state = Enabled,
        subscription_id = foo
}

@ghost ghost added the size/S label Dec 3, 2018
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a 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 Show resolved Hide resolved

//check if the display name matches the 'contains' comparison
if displayNameContains != "" {
if !strings.Contains(strings.ToLower(*val.DisplayName), displayNameContains) {
Copy link
Contributor

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?

Copy link
Contributor Author

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. 🤓️

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see above.

azurerm/data_source_subscriptions.go Outdated Show resolved Hide resolved
website/docs/d/subscriptions.html.markdown Outdated Show resolved Hide resolved
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* `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

website/docs/d/subscriptions.html.markdown Outdated Show resolved Hide resolved
website/docs/d/subscriptions.html.markdown Outdated Show resolved Hide resolved
@tiwood
Copy link
Contributor Author

tiwood commented Dec 3, 2018

thanks @tombuildsstuff, I made the requested changes.

@ghost ghost removed the waiting-response label Dec 3, 2018
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a 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)

@tombuildsstuff tombuildsstuff added this to the 1.20.0 milestone Dec 4, 2018
@tombuildsstuff
Copy link
Contributor

Tests pass:

screenshot 2018-12-04 at 11 02 45

@tombuildsstuff tombuildsstuff merged commit d9a9a56 into hashicorp:master Dec 4, 2018
tombuildsstuff added a commit that referenced this pull request Dec 4, 2018
@ghost
Copy link

ghost commented Mar 5, 2019

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 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants