Skip to content

Commit e0c41cd

Browse files
authored
feat: Suport MSK cluster policy resource and add cluster_uuid attribute (#23)
1 parent f85c9a5 commit e0c41cd

File tree

15 files changed

+181
-13
lines changed

15 files changed

+181
-13
lines changed

README.md

Lines changed: 9 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.12 |
131+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.21 |
132132

133133
## Providers
134134

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

139139
## Modules
140140

@@ -150,11 +150,13 @@ No modules.
150150
| [aws_glue_registry.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/glue_registry) | resource |
151151
| [aws_glue_schema.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/glue_schema) | resource |
152152
| [aws_msk_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_cluster) | resource |
153+
| [aws_msk_cluster_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_cluster_policy) | resource |
153154
| [aws_msk_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_configuration) | resource |
154155
| [aws_msk_scram_secret_association.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_scram_secret_association) | resource |
155156
| [aws_msk_vpc_connection.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_vpc_connection) | resource |
156157
| [aws_mskconnect_custom_plugin.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/mskconnect_custom_plugin) | resource |
157158
| [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 |
158160

159161
## Inputs
160162

@@ -171,6 +173,9 @@ No modules.
171173
| <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 |
172174
| <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 |
173175
| <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 |
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 |
174179
| <a name="input_configuration_arn"></a> [configuration\_arn](#input\_configuration\_arn) | ARN of an externally created configuration to use | `string` | `null` | no |
175180
| <a name="input_configuration_description"></a> [configuration\_description](#input\_configuration\_description) | Description of the configuration | `string` | `null` | no |
176181
| <a name="input_configuration_name"></a> [configuration\_name](#input\_configuration\_name) | Name of the configuration | `string` | `null` | no |
@@ -183,6 +188,7 @@ No modules.
183188
| <a name="input_connect_worker_config_properties_file_content"></a> [connect\_worker\_config\_properties\_file\_content](#input\_connect\_worker\_config\_properties\_file\_content) | Contents of connect-distributed.properties file. The value can be either base64 encoded or in raw format | `string` | `null` | no |
184189
| <a name="input_create"></a> [create](#input\_create) | Determines whether cluster resources will be created | `bool` | `true` | no |
185190
| <a name="input_create_cloudwatch_log_group"></a> [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group) | Determines whether to create a CloudWatch log group | `bool` | `true` | no |
191+
| <a name="input_create_cluster_policy"></a> [create\_cluster\_policy](#input\_create\_cluster\_policy) | Determines whether to create an MSK cluster policy | `bool` | `false` | no |
186192
| <a name="input_create_configuration"></a> [create\_configuration](#input\_create\_configuration) | Determines whether to create a configuration | `bool` | `true` | no |
187193
| <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 |
188194
| <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 |
@@ -226,6 +232,7 @@ No modules.
226232
| <a name="output_bootstrap_brokers_sasl_iam"></a> [bootstrap\_brokers\_sasl\_iam](#output\_bootstrap\_brokers\_sasl\_iam) | One or more DNS names (or IP addresses) and SASL IAM port pairs. This attribute will have a value if `encryption_in_transit_client_broker` is set to `TLS_PLAINTEXT` or `TLS` and `client_authentication_sasl_iam` is set to `true` |
227233
| <a name="output_bootstrap_brokers_sasl_scram"></a> [bootstrap\_brokers\_sasl\_scram](#output\_bootstrap\_brokers\_sasl\_scram) | One or more DNS names (or IP addresses) and SASL SCRAM port pairs. This attribute will have a value if `encryption_in_transit_client_broker` is set to `TLS_PLAINTEXT` or `TLS` and `client_authentication_sasl_scram` is set to `true` |
228234
| <a name="output_bootstrap_brokers_tls"></a> [bootstrap\_brokers\_tls](#output\_bootstrap\_brokers\_tls) | One or more DNS names (or IP addresses) and TLS port pairs. This attribute will have a value if `encryption_in_transit_client_broker` is set to `TLS_PLAINTEXT` or `TLS` |
235+
| <a name="output_cluster_uuid"></a> [cluster\_uuid](#output\_cluster\_uuid) | UUID of the MSK cluster, for use in IAM policies |
229236
| <a name="output_configuration_arn"></a> [configuration\_arn](#output\_configuration\_arn) | Amazon Resource Name (ARN) of the configuration |
230237
| <a name="output_configuration_latest_revision"></a> [configuration\_latest\_revision](#output\_configuration\_latest\_revision) | Latest revision of the configuration |
231238
| <a name="output_connect_custom_plugins"></a> [connect\_custom\_plugins](#output\_connect\_custom\_plugins) | A map of output attributes for the connect custom plugins created |

examples/basic/README.md

Lines changed: 3 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.12 |
26+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.21 |
2727

2828
## Providers
2929

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

3434
## Modules
3535

@@ -63,6 +63,7 @@ No inputs.
6363
| <a name="output_bootstrap_brokers_sasl_iam"></a> [bootstrap\_brokers\_sasl\_iam](#output\_bootstrap\_brokers\_sasl\_iam) | One or more DNS names (or IP addresses) and SASL IAM port pairs. This attribute will have a value if `encryption_in_transit_client_broker` is set to `TLS_PLAINTEXT` or `TLS` and `client_authentication_sasl_iam` is set to `true` |
6464
| <a name="output_bootstrap_brokers_sasl_scram"></a> [bootstrap\_brokers\_sasl\_scram](#output\_bootstrap\_brokers\_sasl\_scram) | One or more DNS names (or IP addresses) and SASL SCRAM port pairs. This attribute will have a value if `encryption_in_transit_client_broker` is set to `TLS_PLAINTEXT` or `TLS` and `client_authentication_sasl_scram` is set to `true` |
6565
| <a name="output_bootstrap_brokers_tls"></a> [bootstrap\_brokers\_tls](#output\_bootstrap\_brokers\_tls) | One or more DNS names (or IP addresses) and TLS port pairs. This attribute will have a value if `encryption_in_transit_client_broker` is set to `TLS_PLAINTEXT` or `TLS` |
66+
| <a name="output_cluster_uuid"></a> [cluster\_uuid](#output\_cluster\_uuid) | UUID of the MSK cluster, for use in IAM policies |
6667
| <a name="output_configuration_arn"></a> [configuration\_arn](#output\_configuration\_arn) | Amazon Resource Name (ARN) of the configuration |
6768
| <a name="output_configuration_latest_revision"></a> [configuration\_latest\_revision](#output\_configuration\_latest\_revision) | Latest revision of the configuration |
6869
| <a name="output_connect_custom_plugins"></a> [connect\_custom\_plugins](#output\_connect\_custom\_plugins) | A map of output attributes for the connect custom plugins created |

examples/basic/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ output "bootstrap_brokers_tls" {
3232
value = module.msk_cluster.bootstrap_brokers_tls
3333
}
3434

35+
output "cluster_uuid" {
36+
description = "UUID of the MSK cluster, for use in IAM policies"
37+
value = module.msk_cluster.cluster_uuid
38+
}
39+
3540
output "current_version" {
3641
description = "Current version of the MSK Cluster used for updates, e.g. `K13V1IB3VIYZZH`"
3742
value = module.msk_cluster.current_version

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.12"
7+
version = ">= 5.21"
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.12 |
25+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.21 |
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.12 |
32+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.21 |
3333
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
3434

3535
## Modules
@@ -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

@@ -71,6 +72,7 @@ No inputs.
7172
| <a name="output_bootstrap_brokers_sasl_iam"></a> [bootstrap\_brokers\_sasl\_iam](#output\_bootstrap\_brokers\_sasl\_iam) | One or more DNS names (or IP addresses) and SASL IAM port pairs. This attribute will have a value if `encryption_in_transit_client_broker` is set to `TLS_PLAINTEXT` or `TLS` and `client_authentication_sasl_iam` is set to `true` |
7273
| <a name="output_bootstrap_brokers_sasl_scram"></a> [bootstrap\_brokers\_sasl\_scram](#output\_bootstrap\_brokers\_sasl\_scram) | One or more DNS names (or IP addresses) and SASL SCRAM port pairs. This attribute will have a value if `encryption_in_transit_client_broker` is set to `TLS_PLAINTEXT` or `TLS` and `client_authentication_sasl_scram` is set to `true` |
7374
| <a name="output_bootstrap_brokers_tls"></a> [bootstrap\_brokers\_tls](#output\_bootstrap\_brokers\_tls) | One or more DNS names (or IP addresses) and TLS port pairs. This attribute will have a value if `encryption_in_transit_client_broker` is set to `TLS_PLAINTEXT` or `TLS` |
75+
| <a name="output_cluster_uuid"></a> [cluster\_uuid](#output\_cluster\_uuid) | UUID of the MSK cluster, for use in IAM policies |
7476
| <a name="output_configuration_arn"></a> [configuration\_arn](#output\_configuration\_arn) | Amazon Resource Name (ARN) of the configuration |
7577
| <a name="output_configuration_latest_revision"></a> [configuration\_latest\_revision](#output\_configuration\_latest\_revision) | Latest revision of the configuration |
7678
| <a name="output_connect_custom_plugins"></a> [connect\_custom\_plugins](#output\_connect\_custom\_plugins) | A map of output attributes for the connect custom plugins created |

examples/complete/main.tf

Lines changed: 51 additions & 1 deletion
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,16 @@ module "vpc_connection_security_group" {
275315
"kafka-broker-tcp",
276316
"kafka-broker-tls-tcp"
277317
]
318+
# multi-VPC network load balancer is listening on the 14001-14100 port ranges
319+
ingress_with_cidr_blocks = [
320+
{
321+
from_port = 14001
322+
to_port = 14003
323+
protocol = "tcp"
324+
description = "Service name"
325+
cidr_blocks = module.vpc_connection.vpc_cidr_block
326+
}
327+
]
278328

279329
tags = local.tags
280330
}

examples/complete/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ output "bootstrap_brokers_tls" {
3232
value = module.msk_cluster.bootstrap_brokers_tls
3333
}
3434

35+
output "cluster_uuid" {
36+
description = "UUID of the MSK cluster, for use in IAM policies"
37+
value = module.msk_cluster.cluster_uuid
38+
}
39+
3540
output "current_version" {
3641
description = "Current version of the MSK Cluster used for updates, e.g. `K13V1IB3VIYZZH`"
3742
value = module.msk_cluster.current_version

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.12"
7+
version = ">= 5.21"
88
}
99
random = {
1010
source = "hashicorp/random"

examples/connect/README.md

Lines changed: 3 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.12 |
25+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.21 |
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.12 |
32+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.21 |
3333
| <a name="provider_null"></a> [null](#provider\_null) | >= 3.0 |
3434

3535
## Modules
@@ -66,6 +66,7 @@ No inputs.
6666
| <a name="output_bootstrap_brokers_sasl_iam"></a> [bootstrap\_brokers\_sasl\_iam](#output\_bootstrap\_brokers\_sasl\_iam) | One or more DNS names (or IP addresses) and SASL IAM port pairs. This attribute will have a value if `encryption_in_transit_client_broker` is set to `TLS_PLAINTEXT` or `TLS` and `client_authentication_sasl_iam` is set to `true` |
6767
| <a name="output_bootstrap_brokers_sasl_scram"></a> [bootstrap\_brokers\_sasl\_scram](#output\_bootstrap\_brokers\_sasl\_scram) | One or more DNS names (or IP addresses) and SASL SCRAM port pairs. This attribute will have a value if `encryption_in_transit_client_broker` is set to `TLS_PLAINTEXT` or `TLS` and `client_authentication_sasl_scram` is set to `true` |
6868
| <a name="output_bootstrap_brokers_tls"></a> [bootstrap\_brokers\_tls](#output\_bootstrap\_brokers\_tls) | One or more DNS names (or IP addresses) and TLS port pairs. This attribute will have a value if `encryption_in_transit_client_broker` is set to `TLS_PLAINTEXT` or `TLS` |
69+
| <a name="output_cluster_uuid"></a> [cluster\_uuid](#output\_cluster\_uuid) | UUID of the MSK cluster, for use in IAM policies |
6970
| <a name="output_configuration_arn"></a> [configuration\_arn](#output\_configuration\_arn) | Amazon Resource Name (ARN) of the configuration |
7071
| <a name="output_configuration_latest_revision"></a> [configuration\_latest\_revision](#output\_configuration\_latest\_revision) | Latest revision of the configuration |
7172
| <a name="output_connect_custom_plugins"></a> [connect\_custom\_plugins](#output\_connect\_custom\_plugins) | A map of output attributes for the connect custom plugins created |

examples/connect/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ output "bootstrap_brokers_tls" {
3232
value = module.msk_cluster.bootstrap_brokers_tls
3333
}
3434

35+
output "cluster_uuid" {
36+
description = "UUID of the MSK cluster, for use in IAM policies"
37+
value = module.msk_cluster.cluster_uuid
38+
}
39+
3540
output "current_version" {
3641
description = "Current version of the MSK Cluster used for updates, e.g. `K13V1IB3VIYZZH`"
3742
value = module.msk_cluster.current_version

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.12"
7+
version = ">= 5.21"
88
}
99
null = {
1010
source = "hashicorp/null"

0 commit comments

Comments
 (0)