Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added single condition values handling #19533

Merged
merged 4 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/19533.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
data-source/aws_iam_policy_document: No longer show changes when there's a single condition
```
4 changes: 4 additions & 0 deletions internal/service/iam/policy_document_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ func dataSourcePolicyDocumentMakeConditions(in []interface{}, version string) (I
if err != nil {
return nil, fmt.Errorf("error reading values: %w", err)
}
itemValues := out[i].Values.([]string)
if len(itemValues) == 1 {
out[i].Values = itemValues[0]
}
}
return IAMPolicyStatementConditionSet(out), nil
}
Expand Down
61 changes: 61 additions & 0 deletions internal/service/iam/policy_document_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ func TestAccIAMPolicyDocumentDataSource_basic(t *testing.T) {
})
}

func TestAccIAMPolicyDocumentDataSource_singleConditionValue(t *testing.T) {
dataSourceName := "data.aws_iam_policy_document.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, iam.EndpointsID),
Providers: acctest.Providers,
Steps: []resource.TestStep{
{
Config: testAccPolicyDocumentConfig_SingleConditionValue,
Check: resource.ComposeTestCheckFunc(
acctest.CheckResourceAttrEquivalentJSON(dataSourceName, "json", testAccPolicyDocumentConfig_SingleConditionValue_ExpectedJSON),
),
},
},
})
}

func TestAccIAMPolicyDocumentDataSource_source(t *testing.T) {
// This really ought to be able to be a unit test rather than an
// acceptance test, but just instantiating the AWS provider requires
Expand Down Expand Up @@ -453,6 +471,49 @@ func testAccPolicyDocumentExpectedJSON() string {
}`, acctest.Partition())
}

const testAccPolicyDocumentConfig_SingleConditionValue = `
data "aws_iam_policy_document" "test" {
statement {
effect = "Deny"

principals {
type = "AWS"
identifiers = ["*"]
}

actions = ["elasticfilesystem:*"]

resources = ["*"]

condition {
test = "Bool"
variable = "aws:SecureTransport"
values = ["false"]
}
}
}
`

const testAccPolicyDocumentConfig_SingleConditionValue_ExpectedJSON = `{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Deny",
"Action": "elasticfilesystem:*",
"Resource": "*",
"Principal": {
"AWS": "*"
},
"Condition": {
"Bool": {
"aws:SecureTransport": "false"
}
}
}
]
}`

var testAccPolicyDocumentSourceConfig = `
data "aws_partition" "current" {}

Expand Down