Skip to content

Commit

Permalink
d\images: Use fixed id (#17766)
Browse files Browse the repository at this point in the history
  • Loading branch information
myc2h6o authored Aug 12, 2022
1 parent fa545a5 commit 5ed7d81
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion internal/services/compute/images_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package compute
import (
"context"
"fmt"
"sort"
"time"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute"
Expand Down Expand Up @@ -139,7 +140,23 @@ func dataSourceImagesRead(d *pluginsdk.ResourceData, meta interface{}) error {
return fmt.Errorf("no images were found that match the specified tags")
}

d.SetId(time.Now().UTC().String())
tagsId := ""
tagKeys := make([]string, 0, len(filterTags))
for key := range filterTags {
tagKeys = append(tagKeys, key)
}
sort.Strings(tagKeys)
for _, key := range tagKeys {
value := ""
if v, ok := filterTags[key]; ok && v != nil {
value = *v
}
tagsId += fmt.Sprintf("[%s:%s]", key, value)
}
if tagsId == "" {
tagsId = "[]"
}
d.SetId(fmt.Sprintf("resourceGroups/%s/tags/%s/images", resourceGroup, tagsId))

d.Set("resource_group_name", resourceGroup)

Expand Down

0 comments on commit 5ed7d81

Please sign in to comment.