Skip to content

Commit

Permalink
resource/iam_policy_document: Preserve order of condition values
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver committed Feb 10, 2021
1 parent 94a427b commit e9a98cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions aws/data_source_aws_iam_policy_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/hashcode"
Expand Down Expand Up @@ -69,7 +70,7 @@ func dataSourceAwsIamPolicyDocument() *schema.Resource {
Required: true,
},
"values": {
Type: schema.TypeSet,
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -310,9 +311,8 @@ func dataSourceAwsIamPolicyDocumentMakeConditions(in []interface{}, version stri
Variable: item["variable"].(string),
}
out[i].Values, err = dataSourceAwsIamPolicyDocumentReplaceVarsInList(
iamPolicyDecodeConfigStringList(
item["values"].(*schema.Set).List(),
), version,
aws.StringValueSlice(expandStringList(item["values"].([]interface{}))),
version,
)
if err != nil {
return nil, fmt.Errorf("error reading values: %s", err)
Expand Down
8 changes: 4 additions & 4 deletions aws/data_source_aws_iam_policy_document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ func testAccAWSIAMPolicyDocumentExpectedJSON() string {
"Condition": {
"StringLike": {
"s3:prefix": [
"home/${aws:username}/",
"home/"
"home/",
"home/${aws:username}/"
]
}
}
Expand Down Expand Up @@ -560,8 +560,8 @@ func testAccAWSIAMPolicyDocumentSourceExpectedJSON() string {
"Condition": {
"StringLike": {
"s3:prefix": [
"home/${aws:username}/",
"home/"
"home/",
"home/${aws:username}/"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion aws/iam_policy_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (cs IAMPolicyStatementConditionSet) MarshalJSON() ([]byte, error) {
if _, ok := raw[c.Test][c.Variable]; !ok {
raw[c.Test][c.Variable] = make([]string, 0, len(i))
}
sort.Sort(sort.Reverse(sort.StringSlice(i)))
// order matters with values so not sorting here
raw[c.Test][c.Variable] = append(raw[c.Test][c.Variable].([]string), i...)
case string:
raw[c.Test][c.Variable] = i
Expand Down

0 comments on commit e9a98cf

Please sign in to comment.