Skip to content

Commit d0a0684

Browse files
committed
separate module for serverless
1 parent 6d91838 commit d0a0684

File tree

9 files changed

+179
-81
lines changed

9 files changed

+179
-81
lines changed

README.md

-5
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ No modules.
155155
| [aws_msk_cluster_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_cluster_policy) | resource |
156156
| [aws_msk_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_configuration) | resource |
157157
| [aws_msk_scram_secret_association.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_scram_secret_association) | resource |
158-
| [aws_msk_serverless_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_serverless_cluster) | resource |
159158
| [aws_msk_vpc_connection.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_vpc_connection) | resource |
160159
| [aws_mskconnect_custom_plugin.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/mskconnect_custom_plugin) | resource |
161160
| [aws_mskconnect_worker_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/mskconnect_worker_configuration) | resource |
@@ -197,7 +196,6 @@ No modules.
197196
| <a name="input_create_connect_worker_configuration"></a> [create\_connect\_worker\_configuration](#input\_create\_connect\_worker\_configuration) | Determines whether to create connect worker configuration | `bool` | `false` | no |
198197
| <a name="input_create_schema_registry"></a> [create\_schema\_registry](#input\_create\_schema\_registry) | Determines whether to create a Glue schema registry for managing Avro schemas for the cluster | `bool` | `true` | no |
199198
| <a name="input_create_scram_secret_association"></a> [create\_scram\_secret\_association](#input\_create\_scram\_secret\_association) | Determines whether to create SASL/SCRAM secret association | `bool` | `false` | no |
200-
| <a name="input_create_serverless_cluster"></a> [create\_serverless\_cluster](#input\_create\_serverless\_cluster) | Determine whether to create a serverless cluster | `bool` | `false` | no |
201199
| <a name="input_enable_storage_autoscaling"></a> [enable\_storage\_autoscaling](#input\_enable\_storage\_autoscaling) | Determines whether autoscaling is enabled for storage | `bool` | `true` | no |
202200
| <a name="input_encryption_at_rest_kms_key_arn"></a> [encryption\_at\_rest\_kms\_key\_arn](#input\_encryption\_at\_rest\_kms\_key\_arn) | You may specify a KMS key short ID or ARN (it will always output an ARN) to use for encrypting your data at rest. If no key is specified, an AWS managed KMS ('aws/msk' managed service) key will be used for encrypting the data at rest | `string` | `null` | no |
203201
| <a name="input_encryption_in_transit_client_broker"></a> [encryption\_in\_transit\_client\_broker](#input\_encryption\_in\_transit\_client\_broker) | Encryption setting for data in transit between clients and brokers. Valid values: `TLS`, `TLS_PLAINTEXT`, and `PLAINTEXT`. Default value is `TLS` | `string` | `null` | no |
@@ -219,7 +217,6 @@ No modules.
219217
| <a name="input_schema_registries"></a> [schema\_registries](#input\_schema\_registries) | A map of schema registries to be created | `map(any)` | `{}` | no |
220218
| <a name="input_schemas"></a> [schemas](#input\_schemas) | A map schemas to be created within the schema registry | `map(any)` | `{}` | no |
221219
| <a name="input_scram_secret_association_secret_arn_list"></a> [scram\_secret\_association\_secret\_arn\_list](#input\_scram\_secret\_association\_secret\_arn\_list) | List of AWS Secrets Manager secret ARNs to associate with SCRAM | `list(string)` | `[]` | no |
222-
| <a name="input_serverless_vpc_config"></a> [serverless\_vpc\_config](#input\_serverless\_vpc\_config) | Serverless cluster VPC configurations | `any` | `{}` | no |
223220
| <a name="input_storage_mode"></a> [storage\_mode](#input\_storage\_mode) | Controls storage mode for supported storage tiers. Valid values are: `LOCAL` or `TIERED` | `string` | `null` | no |
224221
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to assign to the resources created | `map(string)` | `{}` | no |
225222
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Create, update, and delete timeout configurations for the cluster | `map(string)` | `{}` | no |
@@ -249,8 +246,6 @@ No modules.
249246
| <a name="output_schema_registries"></a> [schema\_registries](#output\_schema\_registries) | A map of output attributes for the schema registries created |
250247
| <a name="output_schemas"></a> [schemas](#output\_schemas) | A map of output attributes for the schemas created |
251248
| <a name="output_scram_secret_association_id"></a> [scram\_secret\_association\_id](#output\_scram\_secret\_association\_id) | Amazon Resource Name (ARN) of the MSK cluster |
252-
| <a name="output_serverless_arn"></a> [serverless\_arn](#output\_serverless\_arn) | The ARN of the serverless cluster |
253-
| <a name="output_serverless_cluster_uuid"></a> [serverless\_cluster\_uuid](#output\_serverless\_cluster\_uuid) | UUID of the serverless cluster, for use in IAM policies |
254249
| <a name="output_vpc_connections"></a> [vpc\_connections](#output\_vpc\_connections) | A map of output attributes for the VPC connections created |
255250
| <a name="output_zookeeper_connect_string"></a> [zookeeper\_connect\_string](#output\_zookeeper\_connect\_string) | A comma separated list of one or more hostname:port pairs to use to connect to the Apache Zookeeper cluster. The returned values are sorted alphabetically |
256251
| <a name="output_zookeeper_connect_string_tls"></a> [zookeeper\_connect\_string\_tls](#output\_zookeeper\_connect\_string\_tls) | A comma separated list of one or more hostname:port pairs to use to connect to the Apache Zookeeper cluster via TLS. The returned values are sorted alphabetically |

examples/serverless/main.tf

+4-7
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@ locals {
1919
}
2020

2121
module "msk_serverless_cluster" {
22-
source = "../.."
22+
source = "../../modules/serverless"
2323

24-
name = local.name
25-
create_serverless_cluster = true
24+
name = local.name
2625

27-
serverless_vpc_config = {
28-
security_group_ids = [module.security_group.security_group_id]
29-
subnet_ids = module.vpc.private_subnets
30-
}
26+
security_group_ids = [module.security_group.security_group_id]
27+
subnet_ids = module.vpc.private_subnets
3128

3229
create_cluster_policy = true
3330
cluster_policy_statements = {

main.tf

+10-39
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
################################################################################
44

55
resource "aws_msk_cluster" "this" {
6-
count = var.create && !var.create_serverless_cluster ? 1 : 0
6+
count = var.create ? 1 : 0
77

88
broker_node_group_info {
99
az_distribution = var.broker_node_az_distribution
@@ -173,7 +173,7 @@ resource "aws_msk_cluster" "this" {
173173
################################################################################
174174

175175
resource "aws_msk_vpc_connection" "this" {
176-
for_each = { for k, v in var.vpc_connections : k => v if var.create && !var.create_serverless_cluster }
176+
for_each = { for k, v in var.vpc_connections : k => v if var.create }
177177

178178
authentication = each.value.authentication
179179
client_subnets = each.value.client_subnets
@@ -191,7 +191,7 @@ resource "aws_msk_vpc_connection" "this" {
191191
resource "aws_msk_cluster_policy" "this" {
192192
count = var.create && var.create_cluster_policy ? 1 : 0
193193

194-
cluster_arn = !var.create_serverless_cluster ? aws_msk_cluster.this[0].arn : aws_msk_serverless_cluster.this[0].arn
194+
cluster_arn = aws_msk_cluster.this[0].arn
195195
policy = data.aws_iam_policy_document.this[0].json
196196
}
197197

@@ -248,13 +248,13 @@ data "aws_iam_policy_document" "this" {
248248
################################################################################
249249

250250
resource "random_id" "this" {
251-
count = var.create && var.create_configuration && !var.create_serverless_cluster ? 1 : 0
251+
count = var.create && var.create_configuration ? 1 : 0
252252

253253
byte_length = 8
254254
}
255255

256256
resource "aws_msk_configuration" "this" {
257-
count = var.create && var.create_configuration && !var.create_serverless_cluster ? 1 : 0
257+
count = var.create && var.create_configuration ? 1 : 0
258258

259259
name = format("%s-%s", coalesce(var.configuration_name, var.name), random_id.this[0].dec)
260260
description = var.configuration_description
@@ -271,7 +271,7 @@ resource "aws_msk_configuration" "this" {
271271
################################################################################
272272

273273
resource "aws_msk_scram_secret_association" "this" {
274-
count = var.create && var.create_scram_secret_association && try(var.client_authentication.sasl.scram, false) && !var.create_serverless_cluster ? 1 : 0
274+
count = var.create && var.create_scram_secret_association && try(var.client_authentication.sasl.scram, false) ? 1 : 0
275275

276276
cluster_arn = aws_msk_cluster.this[0].arn
277277
secret_arn_list = var.scram_secret_association_secret_arn_list
@@ -282,11 +282,11 @@ resource "aws_msk_scram_secret_association" "this" {
282282
################################################################################
283283

284284
locals {
285-
cloudwatch_log_group = var.create && var.create_cloudwatch_log_group && !var.create_serverless_cluster ? aws_cloudwatch_log_group.this[0].name : var.cloudwatch_log_group_name
285+
cloudwatch_log_group = var.create && var.create_cloudwatch_log_group ? aws_cloudwatch_log_group.this[0].name : var.cloudwatch_log_group_name
286286
}
287287

288288
resource "aws_cloudwatch_log_group" "this" {
289-
count = var.create && var.create_cloudwatch_log_group && !var.create_serverless_cluster ? 1 : 0
289+
count = var.create && var.create_cloudwatch_log_group ? 1 : 0
290290

291291
name = coalesce(var.cloudwatch_log_group_name, "/aws/msk/${var.name}")
292292
retention_in_days = var.cloudwatch_log_group_retention_in_days
@@ -300,7 +300,7 @@ resource "aws_cloudwatch_log_group" "this" {
300300
################################################################################
301301

302302
resource "aws_appautoscaling_target" "this" {
303-
count = var.create && var.enable_storage_autoscaling && !var.create_serverless_cluster ? 1 : 0
303+
count = var.create && var.enable_storage_autoscaling ? 1 : 0
304304

305305
max_capacity = var.scaling_max_capacity
306306
min_capacity = 1
@@ -311,7 +311,7 @@ resource "aws_appautoscaling_target" "this" {
311311
}
312312

313313
resource "aws_appautoscaling_policy" "this" {
314-
count = var.create && var.enable_storage_autoscaling && !var.create_serverless_cluster ? 1 : 0
314+
count = var.create && var.enable_storage_autoscaling ? 1 : 0
315315

316316
name = "${var.name}-broker-storage-scaling"
317317
policy_type = "TargetTrackingScaling"
@@ -353,32 +353,3 @@ resource "aws_glue_schema" "this" {
353353

354354
tags = merge(var.tags, try(each.value.tags, {}))
355355
}
356-
357-
################################################################################
358-
# Serverless Cluster
359-
################################################################################
360-
361-
resource "aws_msk_serverless_cluster" "this" {
362-
count = var.create && var.create_serverless_cluster ? 1 : 0
363-
364-
client_authentication {
365-
sasl {
366-
iam {
367-
enabled = true
368-
}
369-
}
370-
}
371-
372-
cluster_name = var.name
373-
374-
dynamic "vpc_config" {
375-
for_each = try([var.serverless_vpc_config], [])
376-
377-
content {
378-
security_group_ids = try(vpc_config.value.security_group_ids, null)
379-
subnet_ids = vpc_config.value.subnet_ids
380-
}
381-
}
382-
383-
tags = var.tags
384-
}

modules/serverless/main.tf

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
}

modules/serverless/outputs.tf

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
################################################################################
2+
# Serverless Cluster
3+
################################################################################
4+
5+
output "serverless_arn" {
6+
description = "The ARN of the serverless cluster"
7+
value = try(aws_msk_serverless_cluster.this[0].arn, null)
8+
}
9+
10+
output "serverless_cluster_uuid" {
11+
description = "UUID of the serverless cluster, for use in IAM policies"
12+
value = try(aws_msk_serverless_cluster.this[0].cluster_uuid, null)
13+
}

modules/serverless/variables.tf

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
################################################################################
2+
# Serverless Cluster
3+
################################################################################
4+
variable "create" {
5+
description = "Determines whether cluster resources will be created"
6+
type = bool
7+
default = true
8+
}
9+
10+
variable "name" {
11+
description = "Name of the MSK serverless cluster"
12+
type = string
13+
default = null
14+
}
15+
16+
variable "security_group_ids" {
17+
description = "Specifies up to five security groups that control inbound and outbound traffic for the serverless cluster"
18+
type = list(string)
19+
default = null
20+
}
21+
22+
variable "subnet_ids" {
23+
description = "A list of subnets in at least two different Availability Zones that host your client applications"
24+
type = list(string)
25+
default = null
26+
}
27+
28+
variable "tags" {
29+
description = "A map of tags to assign to the resources created"
30+
type = map(string)
31+
default = {}
32+
}
33+
34+
################################################################################
35+
# Cluster Policy
36+
################################################################################
37+
38+
variable "create_cluster_policy" {
39+
description = "Determines whether to create an MSK cluster policy"
40+
type = bool
41+
default = false
42+
}
43+
44+
variable "cluster_source_policy_documents" {
45+
description = "Source policy documents for cluster policy"
46+
type = list(string)
47+
default = null
48+
}
49+
50+
variable "cluster_override_policy_documents" {
51+
description = "Override policy documents for cluster policy"
52+
type = list(string)
53+
default = null
54+
}
55+
56+
variable "cluster_policy_statements" {
57+
description = "Map of policy statements for cluster policy"
58+
type = any
59+
default = null
60+
}

modules/serverless/versions.tf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.21"
8+
}
9+
}
10+
}

outputs.tf

-14
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,3 @@ output "connect_worker_configuration_latest_revision" {
153153
description = "An ID of the latest successfully created revision of the worker configuration"
154154
value = try(aws_mskconnect_worker_configuration.this[0].latest_revision, null)
155155
}
156-
157-
################################################################################
158-
# Serverless Cluster
159-
################################################################################
160-
161-
output "serverless_arn" {
162-
description = "The ARN of the serverless cluster"
163-
value = try(aws_msk_serverless_cluster.this[0].arn, null)
164-
}
165-
166-
output "serverless_cluster_uuid" {
167-
description = "UUID of the serverless cluster, for use in IAM policies"
168-
value = try(aws_msk_serverless_cluster.this[0].cluster_uuid, null)
169-
}

variables.tf

-16
Original file line numberDiff line numberDiff line change
@@ -375,19 +375,3 @@ variable "connect_worker_config_properties_file_content" {
375375
type = string
376376
default = null
377377
}
378-
379-
################################################################################
380-
# Serverless Cluster
381-
################################################################################
382-
383-
variable "create_serverless_cluster" {
384-
description = "Determine whether to create a serverless cluster"
385-
type = bool
386-
default = false
387-
}
388-
389-
variable "serverless_vpc_config" {
390-
description = "Serverless cluster VPC configurations"
391-
type = any
392-
default = {}
393-
}

0 commit comments

Comments
 (0)