Skip to content

Commit c7aafb6

Browse files
committed
feedback changes and example update
1 parent a27fbbf commit c7aafb6

File tree

5 files changed

+119
-6
lines changed

5 files changed

+119
-6
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ No modules.
156156
| [aws_msk_vpc_connection.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_vpc_connection) | resource |
157157
| [aws_mskconnect_custom_plugin.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/mskconnect_custom_plugin) | resource |
158158
| [aws_mskconnect_worker_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/mskconnect_worker_configuration) | resource |
159+
| [aws_iam_policy_document.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
159160

160161
## Inputs
161162

@@ -172,7 +173,9 @@ No modules.
172173
| <a name="input_cloudwatch_log_group_name"></a> [cloudwatch\_log\_group\_name](#input\_cloudwatch\_log\_group\_name) | Name of the Cloudwatch Log Group to deliver logs to | `string` | `null` | no |
173174
| <a name="input_cloudwatch_log_group_retention_in_days"></a> [cloudwatch\_log\_group\_retention\_in\_days](#input\_cloudwatch\_log\_group\_retention\_in\_days) | Specifies the number of days you want to retain log events in the log group | `number` | `0` | no |
174175
| <a name="input_cloudwatch_logs_enabled"></a> [cloudwatch\_logs\_enabled](#input\_cloudwatch\_logs\_enabled) | Indicates whether you want to enable or disable streaming broker logs to Cloudwatch Logs | `bool` | `false` | no |
175-
| <a name="input_cluster_policy"></a> [cluster\_policy](#input\_cluster\_policy) | Resource policy for cluster | `string` | `null` | no |
176+
| <a name="input_cluster_override_policy_documents"></a> [cluster\_override\_policy\_documents](#input\_cluster\_override\_policy\_documents) | Override policy documents for cluster policy | `list(string)` | `null` | no |
177+
| <a name="input_cluster_policy_statements"></a> [cluster\_policy\_statements](#input\_cluster\_policy\_statements) | Map of policy statements for cluster policy | `any` | `null` | no |
178+
| <a name="input_cluster_source_policy_documents"></a> [cluster\_source\_policy\_documents](#input\_cluster\_source\_policy\_documents) | Source policy documents for cluster policy | `list(string)` | `null` | no |
176179
| <a name="input_configuration_arn"></a> [configuration\_arn](#input\_configuration\_arn) | ARN of an externally created configuration to use | `string` | `null` | no |
177180
| <a name="input_configuration_description"></a> [configuration\_description](#input\_configuration\_description) | Description of the configuration | `string` | `null` | no |
178181
| <a name="input_configuration_name"></a> [configuration\_name](#input\_configuration\_name) | Name of the configuration | `string` | `null` | no |

examples/complete/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Note that this example may create resources which will incur monetary charges on
5353
| [aws_secretsmanager_secret_version.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret_version) | resource |
5454
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
5555
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
56+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
5657

5758
## Inputs
5859

examples/complete/main.tf

+50-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ provider "aws" {
44

55
data "aws_availability_zones" "available" {}
66

7+
data "aws_caller_identity" "current" {}
8+
79
locals {
810
name = "ex-${basename(path.cwd)}"
911
region = "us-east-1"
@@ -136,6 +138,43 @@ module "msk_cluster" {
136138
}
137139
}
138140

141+
# cross account cluster policy
142+
create_cluster_policy = true
143+
cluster_policy_statements = {
144+
basic = {
145+
sid = "basic"
146+
principals = [
147+
{
148+
type = "AWS"
149+
# identifiers would be cross account IDs to provide access to the cluster
150+
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
151+
}
152+
]
153+
actions = [
154+
"kafka:CreateVpcConnection",
155+
"kafka:GetBootstrapBrokers",
156+
"kafka:DescribeCluster",
157+
"kafka:DescribeClusterV2"
158+
]
159+
effect = "Allow"
160+
}
161+
firehose = {
162+
sid = "firehose"
163+
principals = [
164+
{
165+
type = "Service"
166+
identifiers = ["firehose.amazonaws.com"]
167+
}
168+
]
169+
actions = [
170+
"kafka:CreateVpcConnection",
171+
"kafka:GetBootstrapBrokers",
172+
"kafka:DescribeCluster",
173+
"kafka:DescribeClusterV2"
174+
]
175+
}
176+
}
177+
139178
tags = local.tags
140179
}
141180

@@ -177,7 +216,8 @@ module "security_group" {
177216
ingress_cidr_blocks = module.vpc.private_subnets_cidr_blocks
178217
ingress_rules = [
179218
"kafka-broker-tcp",
180-
"kafka-broker-tls-tcp"
219+
"kafka-broker-tls-tcp",
220+
"kafka-broker-sasl-scram-tcp"
181221
]
182222

183223
tags = local.tags
@@ -275,6 +315,15 @@ module "vpc_connection_security_group" {
275315
"kafka-broker-tcp",
276316
"kafka-broker-tls-tcp"
277317
]
318+
ingress_with_cidr_blocks = [
319+
{
320+
from_port = 14001
321+
to_port = 14003
322+
protocol = "tcp"
323+
description = "Service name"
324+
cidr_blocks = module.vpc_connection.vpc_cidr_block
325+
}
326+
]
278327

279328
tags = local.tags
280329
}

main.tf

+49-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,55 @@ resource "aws_msk_cluster_policy" "this" {
192192
count = var.create && var.create_cluster_policy ? 1 : 0
193193

194194
cluster_arn = aws_msk_cluster.this[0].arn
195-
policy = var.cluster_policy
195+
policy = data.aws_iam_policy_document.this[0].json
196+
}
197+
198+
data "aws_iam_policy_document" "this" {
199+
count = var.create && var.create_cluster_policy ? 1 : 0
200+
201+
source_policy_documents = var.cluster_source_policy_documents
202+
override_policy_documents = var.cluster_override_policy_documents
203+
204+
dynamic "statement" {
205+
for_each = var.cluster_policy_statements
206+
207+
content {
208+
sid = try(statement.value.sid, null)
209+
actions = try(statement.value.actions, null)
210+
not_actions = try(statement.value.not_actions, null)
211+
effect = try(statement.value.effect, null)
212+
resources = try(statement.value.resources, [aws_msk_cluster.this[0].arn])
213+
not_resources = try(statement.value.not_resources, null)
214+
215+
dynamic "principals" {
216+
for_each = try(statement.value.principals, [])
217+
218+
content {
219+
type = principals.value.type
220+
identifiers = principals.value.identifiers
221+
}
222+
}
223+
224+
dynamic "not_principals" {
225+
for_each = try(statement.value.not_principals, [])
226+
227+
content {
228+
type = not_principals.value.type
229+
identifiers = not_principals.value.identifiers
230+
}
231+
}
232+
233+
dynamic "condition" {
234+
for_each = try(statement.value.conditions, [])
235+
236+
content {
237+
test = condition.value.test
238+
values = condition.value.values
239+
variable = condition.value.variable
240+
}
241+
}
242+
}
243+
}
196244
}
197245

198246
################################################################################

variables.tf

+15-3
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,21 @@ variable "create_cluster_policy" {
234234
default = false
235235
}
236236

237-
variable "cluster_policy" {
238-
description = "Resource policy for cluster"
239-
type = string
237+
variable "cluster_source_policy_documents" {
238+
description = "Source policy documents for cluster policy"
239+
type = list(string)
240+
default = null
241+
}
242+
243+
variable "cluster_override_policy_documents" {
244+
description = "Override policy documents for cluster policy"
245+
type = list(string)
246+
default = null
247+
}
248+
249+
variable "cluster_policy_statements" {
250+
description = "Map of policy statements for cluster policy"
251+
type = any
240252
default = null
241253
}
242254

0 commit comments

Comments
 (0)