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

resource/aws_cloudwatch_event_permission: Support DescribeEventBus API returning account ID or root account ARN #16319

Merged
Merged
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
26 changes: 17 additions & 9 deletions aws/resource_aws_cloudwatch_event_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,25 @@ func resourceAwsCloudWatchEventPermissionRead(d *schema.ResourceData, meta inter
return fmt.Errorf("error setting condition: %w", err)
}

principalString, ok := policyStatement.Principal.(string)
if ok && (principalString == "*") {
d.Set("principal", "*")
} else {
principalMap := policyStatement.Principal.(map[string]interface{})
policyARN, err := arn.Parse(principalMap["AWS"].(string))
if err != nil {
return fmt.Errorf("error reading CloudWatch Events permission (%s): %w", d.Id(), err)
switch principal := policyStatement.Principal.(type) {
case string:
d.Set("principal", principal)
case map[string]interface{}:
if v, ok := principal["AWS"].(string); ok {
if arn.IsARN(v) {
principalARN, err := arn.Parse(v)

if err != nil {
return fmt.Errorf("error parsing CloudWatch Events Permission (%s) principal as ARN (%s): %w", d.Id(), v, err)
}

d.Set("principal", principalARN.AccountID)
} else {
d.Set("principal", v)
}
}
d.Set("principal", policyARN.AccountID)
}

d.Set("statement_id", policyStatement.Sid)

return nil
Expand Down