|
| 1 | +resource "aws_iam_role" "firehose_role" { |
| 2 | + count = var.enable_event_cache ? 1 : 0 |
| 3 | + |
| 4 | + name = "${local.csi}-firehose-role" |
| 5 | + assume_role_policy = data.aws_iam_policy_document.firehose_assume_role[0].json |
| 6 | +} |
| 7 | + |
| 8 | +data "aws_iam_policy_document" "firehose_assume_role" { |
| 9 | + count = var.enable_event_cache ? 1 : 0 |
| 10 | + |
| 11 | + statement { |
| 12 | + effect = "Allow" |
| 13 | + |
| 14 | + principals { |
| 15 | + type = "Service" |
| 16 | + identifiers = ["firehose.amazonaws.com"] |
| 17 | + } |
| 18 | + |
| 19 | + actions = ["sts:AssumeRole"] |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +resource "aws_iam_role_policy_attachment" "s3_write_object" { |
| 24 | + count = var.enable_event_cache ? 1 : 0 |
| 25 | + |
| 26 | + role = aws_iam_role.firehose_role[0].name |
| 27 | + policy_arn = aws_iam_policy.s3_write_object[0].arn |
| 28 | +} |
| 29 | + |
| 30 | +resource "aws_iam_policy" "s3_write_object" { |
| 31 | + count = var.enable_event_cache ? 1 : 0 |
| 32 | + |
| 33 | + name = "${local.csi}-${var.name}-s3-write-object" |
| 34 | + description = "S3 Put Object policy for ${local.csi}-${var.name} Firehose" |
| 35 | + policy = data.aws_iam_policy_document.s3_write_object[0].json |
| 36 | +} |
| 37 | + |
| 38 | +data "aws_iam_policy_document" "s3_write_object" { |
| 39 | + count = var.enable_event_cache ? 1 : 0 |
| 40 | + |
| 41 | + statement { |
| 42 | + sid = "AllowWriteObject" |
| 43 | + effect = "Allow" |
| 44 | + |
| 45 | + actions = [ |
| 46 | + "s3:AbortMultipartUpload", |
| 47 | + "s3:GetBucketLocation", |
| 48 | + "s3:GetObject", |
| 49 | + "s3:ListBucket", |
| 50 | + "s3:ListBucketMultipartUploads", |
| 51 | + "s3:PutObject", |
| 52 | + "s3:PutObject", |
| 53 | + ] |
| 54 | + |
| 55 | + resources = [ |
| 56 | + "${module.s3bucket_event_cache[0].arn}/*", |
| 57 | + ] |
| 58 | + } |
| 59 | +} |
0 commit comments