From 490e4b74ed0becaeaab1d01704ecced833dab2d6 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 22 Feb 2021 14:05:59 -0500 Subject: [PATCH 1/3] data-source/iam_policy_document: Keep empty conditions --- aws/data_source_aws_iam_policy_document.go | 2 +- aws/data_source_aws_iam_policy_document_test.go | 2 ++ aws/structure.go | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/aws/data_source_aws_iam_policy_document.go b/aws/data_source_aws_iam_policy_document.go index f8521c480fe..04b7fc14dcd 100644 --- a/aws/data_source_aws_iam_policy_document.go +++ b/aws/data_source_aws_iam_policy_document.go @@ -311,7 +311,7 @@ func dataSourceAwsIamPolicyDocumentMakeConditions(in []interface{}, version stri Variable: item["variable"].(string), } out[i].Values, err = dataSourceAwsIamPolicyDocumentReplaceVarsInList( - aws.StringValueSlice(expandStringList(item["values"].([]interface{}))), + aws.StringValueSlice(expandStringListKeepEmpty(item["values"].([]interface{}))), version, ) if err != nil { diff --git a/aws/data_source_aws_iam_policy_document_test.go b/aws/data_source_aws_iam_policy_document_test.go index 8ac7a72c49d..d9af7a3112a 100644 --- a/aws/data_source_aws_iam_policy_document_test.go +++ b/aws/data_source_aws_iam_policy_document_test.go @@ -312,6 +312,7 @@ data "aws_iam_policy_document" "test" { variable = "s3:prefix" values = [ "home/", + "", "home/&{aws:username}/", ] } @@ -394,6 +395,7 @@ func testAccAWSIAMPolicyDocumentExpectedJSON() string { "StringLike": { "s3:prefix": [ "home/", + "", "home/${aws:username}/" ] } diff --git a/aws/structure.go b/aws/structure.go index 1781aa7bb81..6c715cc8203 100644 --- a/aws/structure.go +++ b/aws/structure.go @@ -983,6 +983,16 @@ func expandStringList(configured []interface{}) []*string { return vs } +func expandStringListKeepEmpty(configured []interface{}) []*string { + vs := make([]*string, 0, len(configured)) + for _, v := range configured { + if val, ok := v.(string); ok { + vs = append(vs, aws.String(val)) + } + } + return vs +} + // Takes the result of flatmap.Expand for an array of int64 // and returns a []*int64 func expandInt64List(configured []interface{}) []*int64 { From e4a62f0a3747be64f0c184e60ee5faebd7353707 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 22 Feb 2021 14:55:52 -0500 Subject: [PATCH 2/3] data-source/iam_policy_document: Add changelog --- .changelog/17752.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/17752.txt diff --git a/.changelog/17752.txt b/.changelog/17752.txt new file mode 100644 index 00000000000..e3ecc7e83b6 --- /dev/null +++ b/.changelog/17752.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_iam_policy_document: Keep empty conditions +``` \ No newline at end of file From 6cd0ff17722a0a3197ff1c0f3410dfce63d242cf Mon Sep 17 00:00:00 2001 From: Dirk Avery <31492422+YakDriver@users.noreply.github.com> Date: Mon, 22 Feb 2021 16:21:21 -0500 Subject: [PATCH 3/3] Update .changelog/17752.txt Co-authored-by: angie pinilla --- .changelog/17752.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changelog/17752.txt b/.changelog/17752.txt index e3ecc7e83b6..f7589b6efc4 100644 --- a/.changelog/17752.txt +++ b/.changelog/17752.txt @@ -1,3 +1,3 @@ ```release-note:bug -resource/aws_iam_policy_document: Keep empty conditions -``` \ No newline at end of file +data-source/aws_iam_policy_document: Keep empty conditions +```