Skip to content

Commit 5612974

Browse files
feat: Add support for multi-vpc private connectivity (#13)
Co-authored-by: Bryant Biggs <[email protected]>
1 parent eaab9e1 commit 5612974

File tree

13 files changed

+144
-17
lines changed

13 files changed

+144
-17
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.81.0
3+
rev: v1.83.2
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module
128128
| Name | Version |
129129
|------|---------|
130130
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
131-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
131+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.12 |
132132

133133
## Providers
134134

135135
| Name | Version |
136136
|------|---------|
137-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
137+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.12 |
138138

139139
## Modules
140140

@@ -152,6 +152,7 @@ No modules.
152152
| [aws_msk_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_cluster) | resource |
153153
| [aws_msk_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_configuration) | resource |
154154
| [aws_msk_scram_secret_association.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_scram_secret_association) | resource |
155+
| [aws_msk_vpc_connection.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_vpc_connection) | resource |
155156
| [aws_mskconnect_custom_plugin.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/mskconnect_custom_plugin) | resource |
156157
| [aws_mskconnect_worker_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/mskconnect_worker_configuration) | resource |
157158

@@ -209,6 +210,7 @@ No modules.
209210
| <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 |
210211
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to assign to the resources created | `map(string)` | `{}` | no |
211212
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Create, update, and delete timeout configurations for the cluster | `map(string)` | `{}` | no |
213+
| <a name="input_vpc_connections"></a> [vpc\_connections](#input\_vpc\_connections) | Map of VPC Connections to create | `any` | `{}` | no |
212214

213215
## Outputs
214216

@@ -233,6 +235,7 @@ No modules.
233235
| <a name="output_schema_registries"></a> [schema\_registries](#output\_schema\_registries) | A map of output attributes for the schema registries created |
234236
| <a name="output_schemas"></a> [schemas](#output\_schemas) | A map of output attributes for the schemas created |
235237
| <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 |
238+
| <a name="output_vpc_connections"></a> [vpc\_connections](#output\_vpc\_connections) | A map of output attributes for the VPC connections created |
236239
| <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 |
237240
| <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 |
238241
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/basic/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ Note that this example may create resources which will incur monetary charges on
2323
| Name | Version |
2424
|------|---------|
2525
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
26-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
26+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.12 |
2727

2828
## Providers
2929

3030
| Name | Version |
3131
|------|---------|
32-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
32+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.12 |
3333

3434
## Modules
3535

examples/basic/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.0"
7+
version = ">= 5.12"
88
}
99
}
1010
}

examples/complete/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ Note that this example may create resources which will incur monetary charges on
2222
| Name | Version |
2323
|------|---------|
2424
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
25-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
25+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.12 |
2626
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
2727

2828
## Providers
2929

3030
| Name | Version |
3131
|------|---------|
32-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
32+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.12 |
3333
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
3434

3535
## Modules
@@ -40,6 +40,8 @@ Note that this example may create resources which will incur monetary charges on
4040
| <a name="module_s3_logs_bucket"></a> [s3\_logs\_bucket](#module\_s3\_logs\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 3.0 |
4141
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.0 |
4242
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
43+
| <a name="module_vpc_connection"></a> [vpc\_connection](#module\_vpc\_connection) | terraform-aws-modules/vpc/aws | ~> 5.0 |
44+
| <a name="module_vpc_connection_security_group"></a> [vpc\_connection\_security\_group](#module\_vpc\_connection\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.0 |
4345

4446
## Resources
4547

examples/complete/main.tf

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ locals {
88
name = "ex-${basename(path.cwd)}"
99
region = "us-east-1"
1010

11-
vpc_cidr = "10.0.0.0/16"
12-
azs = slice(data.aws_availability_zones.available.names, 0, 3)
11+
vpc_cidr = "10.0.0.0/16"
12+
vpc_connection_cidr = "10.1.0.0/16"
13+
azs = slice(data.aws_availability_zones.available.names, 0, 3)
1314

1415
secrets = ["producer", "consumer"]
1516

@@ -32,13 +33,36 @@ module "msk_cluster" {
3233
number_of_broker_nodes = 3
3334
enhanced_monitoring = "PER_TOPIC_PER_PARTITION"
3435

35-
broker_node_client_subnets = module.vpc.private_subnets
36-
broker_node_instance_type = "kafka.t3.small"
36+
broker_node_client_subnets = module.vpc.private_subnets
37+
broker_node_connectivity_info = {
38+
public_access = {
39+
type = "DISABLED"
40+
}
41+
vpc_connectivity = {
42+
client_authentication = {
43+
tls = false
44+
sasl = {
45+
iam = false
46+
scram = true
47+
}
48+
}
49+
}
50+
}
51+
broker_node_instance_type = "kafka.m5.large"
3752
broker_node_security_groups = [module.security_group.security_group_id]
3853
broker_node_storage_info = {
3954
ebs_storage_info = { volume_size = 100 }
4055
}
4156

57+
vpc_connections = {
58+
connection_one = {
59+
authentication = "SASL_SCRAM"
60+
vpc_id = module.vpc_connection.vpc_id
61+
client_subnets = module.vpc_connection.private_subnets
62+
security_groups = [module.vpc_connection_security_group.security_group_id]
63+
}
64+
}
65+
4266
encryption_in_transit_client_broker = "TLS"
4367
encryption_in_transit_in_cluster = true
4468

@@ -233,3 +257,43 @@ module "s3_logs_bucket" {
233257

234258
tags = local.tags
235259
}
260+
261+
################################################################################
262+
# VPC Connections
263+
################################################################################
264+
265+
module "vpc_connection_security_group" {
266+
source = "terraform-aws-modules/security-group/aws"
267+
version = "~> 5.0"
268+
269+
name = "${local.name}-vpc-connection"
270+
description = "Security group for ${local.name} VPC Connection"
271+
vpc_id = module.vpc_connection.vpc_id
272+
273+
ingress_cidr_blocks = module.vpc_connection.private_subnets_cidr_blocks
274+
ingress_rules = [
275+
"kafka-broker-tcp",
276+
"kafka-broker-tls-tcp"
277+
]
278+
279+
tags = local.tags
280+
}
281+
282+
module "vpc_connection" {
283+
source = "terraform-aws-modules/vpc/aws"
284+
version = "~> 5.0"
285+
286+
name = "${local.name}-vpc-connection"
287+
cidr = local.vpc_connection_cidr
288+
289+
azs = local.azs
290+
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_connection_cidr, 8, k)]
291+
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_connection_cidr, 8, k + 3)]
292+
database_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_connection_cidr, 8, k + 6)]
293+
294+
create_database_subnet_group = true
295+
enable_nat_gateway = true
296+
single_nat_gateway = true
297+
298+
tags = local.tags
299+
}

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.0"
7+
version = ">= 5.12"
88
}
99
random = {
1010
source = "hashicorp/random"

examples/connect/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ Note that this example may create resources which will incur monetary charges on
2222
| Name | Version |
2323
|------|---------|
2424
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
25-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
25+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.12 |
2626
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 3.0 |
2727

2828
## Providers
2929

3030
| Name | Version |
3131
|------|---------|
32-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
32+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.12 |
3333
| <a name="provider_null"></a> [null](#provider\_null) | >= 3.0 |
3434

3535
## Modules

examples/connect/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.0"
7+
version = ">= 5.12"
88
}
99
null = {
1010
source = "hashicorp/null"

main.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,29 @@ resource "aws_msk_cluster" "this" {
2020
type = try(public_access.value.type, null)
2121
}
2222
}
23+
24+
dynamic "vpc_connectivity" {
25+
for_each = try([connectivity_info.value.vpc_connectivity], [])
26+
27+
content {
28+
dynamic "client_authentication" {
29+
for_each = try([vpc_connectivity.value.client_authentication], [])
30+
31+
content {
32+
dynamic "sasl" {
33+
for_each = try([client_authentication.value.sasl], [])
34+
35+
content {
36+
iam = try(sasl.value.iam, null)
37+
scram = try(sasl.value.scram, null)
38+
}
39+
}
40+
41+
tls = try(client_authentication.value.tls, null)
42+
}
43+
}
44+
}
45+
}
2346
}
2447
}
2548

@@ -145,6 +168,22 @@ resource "aws_msk_cluster" "this" {
145168
tags = var.tags
146169
}
147170

171+
################################################################################
172+
# VPC Connection
173+
################################################################################
174+
175+
resource "aws_msk_vpc_connection" "this" {
176+
for_each = { for k, v in var.vpc_connections : k => v if var.create }
177+
178+
authentication = each.value.authentication
179+
client_subnets = each.value.client_subnets
180+
security_groups = each.value.security_groups
181+
target_cluster_arn = aws_msk_cluster.this[0].arn
182+
vpc_id = each.value.vpc_id
183+
184+
tags = merge(var.tags, try(each.value.tags, {}))
185+
}
186+
148187
################################################################################
149188
# Configuration
150189
################################################################################

outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ output "zookeeper_connect_string_tls" {
5252
value = try(aws_msk_cluster.this[0].zookeeper_connect_string_tls, null)
5353
}
5454

55+
################################################################################
56+
# VPC Connection
57+
################################################################################
58+
59+
output "vpc_connections" {
60+
description = "A map of output attributes for the VPC connections created"
61+
value = aws_msk_vpc_connection.this
62+
}
63+
5564
################################################################################
5665
# Configuration
5766
################################################################################

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ variable "timeouts" {
158158
default = {}
159159
}
160160

161+
################################################################################
162+
# VPC Connection
163+
################################################################################
164+
165+
variable "vpc_connections" {
166+
description = "Map of VPC Connections to create"
167+
type = any
168+
default = {}
169+
}
170+
161171
################################################################################
162172
# Configuration
163173
################################################################################

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.0"
7+
version = ">= 5.12"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)