Make buildEC2AttributeFilterList output sorted
Makes the output deterministic
This commit is contained in:
parent
fecc218505
commit
7d0ed45ec9
|
@ -2,6 +2,7 @@ package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/service/ec2"
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
|
@ -31,9 +32,18 @@ import (
|
||||||
// the EC2 API, to aid in the implementation of Terraform data sources that
|
// the EC2 API, to aid in the implementation of Terraform data sources that
|
||||||
// retrieve data about EC2 objects.
|
// retrieve data about EC2 objects.
|
||||||
func buildEC2AttributeFilterList(attrs map[string]string) []*ec2.Filter {
|
func buildEC2AttributeFilterList(attrs map[string]string) []*ec2.Filter {
|
||||||
filters := make([]*ec2.Filter, 0, len(attrs))
|
var filters []*ec2.Filter
|
||||||
|
|
||||||
for filterName, value := range attrs {
|
// sort the filters by name to make the output deterministic
|
||||||
|
var names []string
|
||||||
|
for filterName := range attrs {
|
||||||
|
names = append(names, filterName)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(names)
|
||||||
|
|
||||||
|
for _, filterName := range names {
|
||||||
|
value := attrs[filterName]
|
||||||
if value == "" {
|
if value == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,14 +22,14 @@ func TestBuildEC2AttributeFilterList(t *testing.T) {
|
||||||
"baz": "boo",
|
"baz": "boo",
|
||||||
},
|
},
|
||||||
[]*ec2.Filter{
|
[]*ec2.Filter{
|
||||||
{
|
|
||||||
Name: aws.String("foo"),
|
|
||||||
Values: []*string{aws.String("bar")},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Name: aws.String("baz"),
|
Name: aws.String("baz"),
|
||||||
Values: []*string{aws.String("boo")},
|
Values: []*string{aws.String("boo")},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: aws.String("foo"),
|
||||||
|
Values: []*string{aws.String("bar")},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue