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

Handle duplicate sid in policy document #6675

Merged
merged 2 commits into from
Dec 3, 2018
Merged
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions aws/data_source_aws_iam_policy_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"encoding/json"
"fmt"
"strconv"
"strings"

Expand Down Expand Up @@ -114,14 +115,22 @@ func dataSourceAwsIamPolicyDocumentRead(d *schema.ResourceData, meta interface{}
if cfgStmts, hasCfgStmts := d.GetOk("statement"); hasCfgStmts {
var cfgStmtIntf = cfgStmts.([]interface{})
stmts := make([]*IAMPolicyStatement, len(cfgStmtIntf))
sidMap := make(map[string]struct{})

for i, stmtI := range cfgStmtIntf {
cfgStmt := stmtI.(map[string]interface{})
stmt := &IAMPolicyStatement{
Effect: cfgStmt["effect"].(string),
}

if sid, ok := cfgStmt["sid"]; ok {
if _, ok := sidMap[sid.(string)]; ok {
return fmt.Errorf("Sid should be blank or unique. Change Sid : %s", sid.(string))
sunilkumarmohanty marked this conversation as resolved.
Show resolved Hide resolved
}
stmt.Sid = sid.(string)
if len(stmt.Sid) > 0 {
sidMap[stmt.Sid] = struct{}{}
}
}

if actions := cfgStmt["actions"].(*schema.Set).List(); len(actions) > 0 {
Expand Down