Skip to content

Commit 774cc97

Browse files
authored
Update data_aws_crossaccount_policy to format resource string with account and region (#3544)
* Update data_aws_crossaccount_policy to format resource string with account and region String with formatting wasn't passed to `fmt.Sprintf` resulting in the actual policy containing '%s' e.g. 'arn:aws:ec2:%s:%s:volume/*'. Passing the string to `fmt.Sprintf` results in the desired iam policy json. * Update test checking for exact length of resulting policy --------- Co-authored-by: frosforever <[email protected]>
1 parent ee1e4b5 commit 774cc97

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

aws/data_aws_crossaccount_policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ func DataAwsCrossaccountPolicy() common.Resource {
187187
Effect: "Allow",
188188
Actions: "ec2:RunInstances",
189189
Resources: []string{
190-
"arn:aws:ec2:%s:%s:volume/*",
191-
"arn:aws:ec2:%s:%s:instance/*",
190+
fmt.Sprintf("arn:aws:ec2:%s:%s:volume/*", region, aws_account_id),
191+
fmt.Sprintf("arn:aws:ec2:%s:%s:instance/*", region, aws_account_id),
192192
},
193193
Condition: map[string]map[string]string{
194194
"StringEquals": {

aws/data_aws_crossaccount_policy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestDataAwsCrossAccountRestrictedPolicy(t *testing.T) {
6060
}.Apply(t)
6161
assert.NoError(t, err)
6262
j := d.Get("json")
63-
assert.Lenf(t, j, 5691, "Strange length for policy: %s", j)
63+
assert.Lenf(t, j, 5725, "Strange length for policy: %s", j)
6464
}
6565

6666
func TestDataAwsCrossAccountInvalidPolicy(t *testing.T) {

0 commit comments

Comments
 (0)