diff --git a/builtin/providers/aws/ec2_filters.go b/builtin/providers/aws/ec2_filters.go index 249bbf653..4263d6efa 100644 --- a/builtin/providers/aws/ec2_filters.go +++ b/builtin/providers/aws/ec2_filters.go @@ -2,6 +2,7 @@ package aws import ( "fmt" + "sort" "github.com/aws/aws-sdk-go/aws" "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 // retrieve data about EC2 objects. 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 == "" { continue } diff --git a/builtin/providers/aws/ec2_filters_test.go b/builtin/providers/aws/ec2_filters_test.go index d0d13b559..267faa957 100644 --- a/builtin/providers/aws/ec2_filters_test.go +++ b/builtin/providers/aws/ec2_filters_test.go @@ -22,14 +22,14 @@ func TestBuildEC2AttributeFilterList(t *testing.T) { "baz": "boo", }, []*ec2.Filter{ - { - Name: aws.String("foo"), - Values: []*string{aws.String("bar")}, - }, { Name: aws.String("baz"), Values: []*string{aws.String("boo")}, }, + { + Name: aws.String("foo"), + Values: []*string{aws.String("bar")}, + }, }, }, {