Skip to content

Commit

Permalink
azurerm_data_source - optimize api with resource_group_name (#21661)
Browse files Browse the repository at this point in the history
  • Loading branch information
myc2h6o authored May 5, 2023
1 parent 2987e6c commit 6d4723c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions internal/services/resource/resources_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ func dataSourceResourcesRead(d *pluginsdk.ResourceData, meta interface{}) error

var filter string

if resourceGroupName != "" {
v := fmt.Sprintf("resourceGroup eq '%s'", resourceGroupName)
filter += v
}

if resourceName != "" {
if strings.Contains(filter, "eq") {
filter += " and "
Expand All @@ -106,10 +101,20 @@ func dataSourceResourcesRead(d *pluginsdk.ResourceData, meta interface{}) error
}

// Use List instead of listComplete because of bug in SDK: https://github.com/Azure/azure-sdk-for-go/issues/9510
var resourcesResp resources.ListResultPage
resources := make([]map[string]interface{}, 0)
resourcesResp, err := client.List(ctx, filter, "", nil)
if err != nil {
return fmt.Errorf("getting resources: %+v", err)
if resourceGroupName != "" {
resp, err := client.ListByResourceGroup(ctx, resourceGroupName, filter, "", nil)
if err != nil {
return fmt.Errorf("getting resources by resource group: %+v", err)
}
resourcesResp = resp
} else {
resp, err := client.List(ctx, filter, "", nil)
if err != nil {
return fmt.Errorf("getting resources: %+v", err)
}
resourcesResp = resp
}

resources = append(resources, filterResource(resourcesResp.Values(), requiredTags)...)
Expand Down

0 comments on commit 6d4723c

Please sign in to comment.