|
| 1 | +resource "aws_iam_role" "glue_role" { |
| 2 | + name = "${local.csi}-glue-role" |
| 3 | + assume_role_policy = data.aws_iam_policy_document.glue_assume_role.json |
| 4 | +} |
| 5 | + |
| 6 | +data "aws_iam_policy_document" "glue_assume_role" { |
| 7 | + statement { |
| 8 | + sid = "AllowGlueServiceAssumeRole" |
| 9 | + effect = "Allow" |
| 10 | + |
| 11 | + principals { |
| 12 | + type = "Service" |
| 13 | + identifiers = ["glue.amazonaws.com"] |
| 14 | + } |
| 15 | + |
| 16 | + actions = [ |
| 17 | + "sts:AssumeRole", |
| 18 | + ] |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +resource "aws_iam_policy" "glue_service_policy" { |
| 23 | + name = "${local.csi}-glue-service-policy" |
| 24 | + description = "Policy for ${local.csi} Glue Service Role" |
| 25 | + policy = data.aws_iam_policy_document.glue_service_policy.json |
| 26 | +} |
| 27 | + |
| 28 | +data "aws_iam_policy_document" "glue_service_policy" { |
| 29 | + statement { |
| 30 | + sid = "AllowGlueLogging" |
| 31 | + effect = "Allow" |
| 32 | + |
| 33 | + actions = [ |
| 34 | + "logs:CreateLogGroup", |
| 35 | + "logs:CreateLogStream", |
| 36 | + "logs:PutLogEvents" |
| 37 | + ] |
| 38 | + resources = ["arn:aws:logs:*:*:*"] |
| 39 | + } |
| 40 | + |
| 41 | + statement { |
| 42 | + sid = "AllowS3Access" |
| 43 | + effect = "Allow" |
| 44 | + |
| 45 | + actions = [ |
| 46 | + "s3:GetObject", |
| 47 | + "s3:PutObject", |
| 48 | + "s3:DeleteObject" |
| 49 | + ] |
| 50 | + resources = ["arn:aws:s3:::${local.csi}-glue-bucket/*", |
| 51 | + "arn:aws:s3:::${local.csi}-event_reporting/*"] |
| 52 | + } |
| 53 | + statement { |
| 54 | + sid = "GlueCatalogAccess" |
| 55 | + effect = "Allow" |
| 56 | + actions = [ |
| 57 | + "glue:GetDatabase", |
| 58 | + "glue:GetDatabases", |
| 59 | + "glue:GetTable", |
| 60 | + "glue:GetTables", |
| 61 | + "glue:CreateTable", |
| 62 | + "glue:UpdateTable", |
| 63 | + "glue:CreatePartition", |
| 64 | + "glue:BatchCreatePartition", |
| 65 | + "glue:GetPartition", |
| 66 | + "glue:BatchGetPartition" |
| 67 | + ] |
| 68 | + resources = ["*"] |
| 69 | + } |
| 70 | + statement { |
| 71 | + sid = "S3TempAndGlueETL" |
| 72 | + effect = "Allow" |
| 73 | + actions = [ |
| 74 | + "s3:PutObject", |
| 75 | + "s3:GetObject" |
| 76 | + ] |
| 77 | + resources = [ |
| 78 | + "arn:aws:s3:::aws-glue-*", |
| 79 | + "arn:aws:s3:::aws-glue-*/*" |
| 80 | + ] |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +resource "aws_iam_role_policy_attachment" "gllue_attach_policy" { |
| 85 | + role = aws_iam_role.glue_role.name |
| 86 | + policy_arn = aws_iam_policy.glue_service_policy.arn |
| 87 | +} |
0 commit comments