-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for MSK Source Configuration (#10)
- Loading branch information
Showing
13 changed files
with
393 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ generate-toc: | |
gh-md-toc README.md | ||
|
||
pre-commit: | ||
/usr/local/bin/pre-commit run -a | ||
pre-commit run -a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Kinesis Firehose: Kinesis Data Source To S3 | ||
|
||
Basic Configuration in this directory creates kinesis firehose stream with MSK Cluster as source and S3 bucket as destination with a basic configuration. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 5.0 | | ||
| <a name="requirement_random"></a> [random](#requirement\_random) | ~> 3.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 5.0 | | ||
| <a name="provider_random"></a> [random](#provider\_random) | ~> 3.0 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_firehose"></a> [firehose](#module\_firehose) | ../../../ | n/a | | ||
| <a name="module_msk_cluster"></a> [msk\_cluster](#module\_msk\_cluster) | terraform-aws-modules/msk-kafka-cluster/aws | 2.3.0 | | ||
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.0 | | ||
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_msk_cluster_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_cluster_policy) | resource | | ||
| [aws_s3_bucket.s3](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource | | ||
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource | | ||
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_name_prefix"></a> [name\_prefix](#input\_name\_prefix) | Name prefix to use in resources | `string` | `"msk-to-s3-basic"` | no | | ||
|
||
## Outputs | ||
|
||
No outputs. | ||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
data "aws_availability_zones" "available" {} | ||
|
||
locals { | ||
vpc_cidr = "10.0.0.0/16" | ||
azs = slice(data.aws_availability_zones.available.names, 0, 2) | ||
} | ||
|
||
resource "random_pet" "this" { | ||
length = 2 | ||
} | ||
|
||
resource "aws_s3_bucket" "s3" { | ||
bucket = "${var.name_prefix}-destination-bucket-${random_pet.this.id}" | ||
force_destroy = true | ||
} | ||
|
||
module "vpc" { | ||
source = "terraform-aws-modules/vpc/aws" | ||
version = "~> 5.0" | ||
name = "${var.name_prefix}-vpc" | ||
cidr = local.vpc_cidr | ||
azs = local.azs | ||
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)] | ||
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 3)] | ||
database_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 6)] | ||
create_database_subnet_group = true | ||
enable_nat_gateway = true | ||
single_nat_gateway = true | ||
} | ||
|
||
module "security_group" { | ||
source = "terraform-aws-modules/security-group/aws" | ||
version = "~> 5.0" | ||
|
||
name = "${var.name_prefix}-sg" | ||
description = "Security group for ${var.name_prefix}-sg" | ||
vpc_id = module.vpc.vpc_id | ||
|
||
ingress_cidr_blocks = module.vpc.private_subnets_cidr_blocks | ||
ingress_rules = [ | ||
"kafka-broker-tcp", | ||
"kafka-broker-tls-tcp" | ||
] | ||
} | ||
|
||
module "msk_cluster" { | ||
source = "terraform-aws-modules/msk-kafka-cluster/aws" | ||
version = "2.3.0" | ||
name = "${var.name_prefix}-msk" | ||
kafka_version = "3.4.0" | ||
number_of_broker_nodes = 2 | ||
broker_node_client_subnets = module.vpc.public_subnets | ||
broker_node_instance_type = "kafka.m5.large" | ||
broker_node_security_groups = [module.security_group.security_group_id] | ||
broker_node_connectivity_info = { | ||
public_access = { | ||
# type = "SERVICE_PROVIDED_EIPS" | ||
type = "DISABLED" | ||
} | ||
vpc_connectivity = { | ||
client_authentication = { | ||
tls = false | ||
sasl = { | ||
iam = true | ||
scram = false | ||
} | ||
} | ||
} | ||
} | ||
client_authentication = { | ||
sasl = { iam = true } | ||
} | ||
enable_storage_autoscaling = false | ||
create_cloudwatch_log_group = false | ||
cloudwatch_logs_enabled = false | ||
s3_logs_enabled = false | ||
configuration_name = "${var.name_prefix}-msk-configuration" | ||
configuration_description = "${var.name_prefix} MSK configuration" | ||
configuration_server_properties = { | ||
"allow.everyone.if.no.acl.found" = false | ||
} | ||
} | ||
|
||
resource "aws_msk_cluster_policy" "this" { | ||
cluster_arn = module.msk_cluster.arn | ||
policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [{ | ||
Sid = "FirehoseMskClusterPolicy" | ||
Effect = "Allow" | ||
Principal = { | ||
"Service" = "firehose.amazonaws.com" | ||
} | ||
Action = [ | ||
"kafka:Describe*", | ||
"kafka:Get*", | ||
"kafka:CreateVpcConnection", | ||
"kafka:GetBootstrapBrokers", | ||
] | ||
Resource = module.msk_cluster.arn | ||
}] | ||
}) | ||
} | ||
|
||
module "firehose" { | ||
source = "../../../" | ||
name = "${var.name_prefix}-delivery-stream" | ||
input_source = "msk" | ||
msk_source_cluster_arn = module.msk_cluster.arn | ||
msk_source_topic_name = "test" | ||
destination = "s3" | ||
s3_bucket_arn = aws_s3_bucket.s3.arn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#output "kinesis_firehose_arn" { | ||
# description = "The ARN of the Kinesis Firehose Stream" | ||
# value = module.firehose.kinesis_firehose_arn | ||
#} | ||
# | ||
#output "kinesis_data_stream_name" { | ||
# description = "The name of the Kinesis Firehose Stream" | ||
# value = module.firehose.kinesis_firehose_name | ||
#} | ||
# | ||
#output "kinesis_firehose_destination_id" { | ||
# description = "The Destination id of the Kinesis Firehose Stream" | ||
# value = module.firehose.kinesis_firehose_destination_id | ||
#} | ||
# | ||
#output "kinesis_firehose_version_id" { | ||
# description = "The Version id of the Kinesis Firehose Stream" | ||
# value = module.firehose.kinesis_firehose_version_id | ||
#} | ||
# | ||
#output "kinesis_firehose_role_arn" { | ||
# description = "The ARN of the IAM role created for Kinesis Firehose Stream" | ||
# value = module.firehose.kinesis_firehose_role_arn | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
variable "name_prefix" { | ||
description = "Name prefix to use in resources" | ||
type = string | ||
default = "msk-to-s3-basic" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
terraform { | ||
required_version = ">= 0.13.1" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.0" | ||
} | ||
random = { | ||
source = "hashicorp/random" | ||
version = "~> 3.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.