|
| 1 | +################################################################################ |
| 2 | +# Serverless Cluster |
| 3 | +################################################################################ |
| 4 | +resource "aws_msk_serverless_cluster" "this" { |
| 5 | + count = var.create ? 1 : 0 |
| 6 | + |
| 7 | + client_authentication { |
| 8 | + sasl { |
| 9 | + iam { |
| 10 | + enabled = true |
| 11 | + } |
| 12 | + } |
| 13 | + } |
| 14 | + |
| 15 | + cluster_name = var.name |
| 16 | + |
| 17 | + vpc_config { |
| 18 | + security_group_ids = var.security_group_ids |
| 19 | + subnet_ids = var.subnet_ids |
| 20 | + } |
| 21 | + |
| 22 | + tags = var.tags |
| 23 | +} |
| 24 | + |
| 25 | +################################################################################ |
| 26 | +# Cluster Policy |
| 27 | +################################################################################ |
| 28 | + |
| 29 | +resource "aws_msk_cluster_policy" "this" { |
| 30 | + count = var.create && var.create_cluster_policy ? 1 : 0 |
| 31 | + |
| 32 | + cluster_arn = aws_msk_serverless_cluster.this[0].arn |
| 33 | + policy = data.aws_iam_policy_document.this[0].json |
| 34 | +} |
| 35 | + |
| 36 | +data "aws_iam_policy_document" "this" { |
| 37 | + count = var.create && var.create_cluster_policy ? 1 : 0 |
| 38 | + |
| 39 | + source_policy_documents = var.cluster_source_policy_documents |
| 40 | + override_policy_documents = var.cluster_override_policy_documents |
| 41 | + |
| 42 | + dynamic "statement" { |
| 43 | + for_each = var.cluster_policy_statements |
| 44 | + |
| 45 | + content { |
| 46 | + sid = try(statement.value.sid, null) |
| 47 | + actions = try(statement.value.actions, null) |
| 48 | + not_actions = try(statement.value.not_actions, null) |
| 49 | + effect = try(statement.value.effect, null) |
| 50 | + resources = try(statement.value.resources, [aws_msk_serverless_cluster.this[0].arn]) |
| 51 | + not_resources = try(statement.value.not_resources, null) |
| 52 | + |
| 53 | + dynamic "principals" { |
| 54 | + for_each = try(statement.value.principals, []) |
| 55 | + |
| 56 | + content { |
| 57 | + type = principals.value.type |
| 58 | + identifiers = principals.value.identifiers |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + dynamic "not_principals" { |
| 63 | + for_each = try(statement.value.not_principals, []) |
| 64 | + |
| 65 | + content { |
| 66 | + type = not_principals.value.type |
| 67 | + identifiers = not_principals.value.identifiers |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + dynamic "condition" { |
| 72 | + for_each = try(statement.value.conditions, []) |
| 73 | + |
| 74 | + content { |
| 75 | + test = condition.value.test |
| 76 | + values = condition.value.values |
| 77 | + variable = condition.value.variable |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments