From 7d0ed45ec926fadbdc6060712750f4e223250006 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 14 Oct 2016 12:22:45 -0400 Subject: [PATCH] Make buildEC2AttributeFilterList output sorted Makes the output deterministic --- builtin/providers/aws/ec2_filters.go | 14 ++++++++++++-- builtin/providers/aws/ec2_filters_test.go | 8 ++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/builtin/providers/aws/ec2_filters.go b/builtin/providers/aws/ec2_filters.go index 249bbf653e..4263d6efa3 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 d0d13b5596..267faa9573 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")}, + }, }, }, {