Skip to content

Commit

Permalink
Initial draft
Browse files Browse the repository at this point in the history
  • Loading branch information
BSick7 committed Feb 26, 2025
1 parent e745382 commit 9070e47
Show file tree
Hide file tree
Showing 14 changed files with 281 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Nullstone
on:
push:
tags:
- 'v*'

env:
NULLSTONE_ORG: nullstone
NULLSTONE_API_KEY: ${{ secrets.NULLSTONE_API_KEY }}

jobs:
publish:
runs-on: ubuntu-latest

defaults:
run:
shell: bash

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Find version
id: version
run: echo ::set-output name=tag::${GITHUB_REF#refs/tags/v}

- name: Set up Nullstone
uses: nullstone-io/setup-nullstone-action@v0

- name: Publish module
run: |
nullstone modules publish --version=${{ steps.version.outputs.tag }}
13 changes: 13 additions & 0 deletions .nullstone/module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
org_name: nullstone
name: aws-msk
friendly_name: Kafka Cluster (AWS MSK)
description: Creates a Kafka cluster using AWS MSK
category: datastore
subcategory: ""
provider_types:
- aws
platform: kafka
subplatform: msk
type: ""
appCategories: []
is_public: true
76 changes: 76 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## 0.1.0 (Unreleased)
* Initial release
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lock-providers:
terraform providers lock -platform=linux_amd64 -platform=linux_arm64 -platform=darwin_amd64 -platform=darwin_arm64 -platform=windows_amd64
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# aws-msk

Creates a Kafka cluster using AWS MSK
5 changes: 5 additions & 0 deletions aws.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "aws_region" "this" {}

locals {
region = data.aws_region.this.name
}
30 changes: 30 additions & 0 deletions cluster.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
resource "aws_msk_cluster" "this" {
cluster_name = local.resource_name
kafka_version = var.kafka_version
number_of_broker_nodes = var.num_broker_nodes

broker_node_group_info {
instance_type = var.instance_type
client_subnets = local.private_subnet_ids
security_groups = [aws_security_group.this.id]

storage_info {
ebs_storage_info {
volume_size = var.storage_size
}
}
}

encryption_info {
encryption_at_rest_kms_key_arn = aws_kms_alias.this.arn

encryption_in_transit {
client_broker = "TLS"
in_cluster = true
}
}

client_authentication {
iam = true
}
}
11 changes: 11 additions & 0 deletions kms.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "aws_kms_key" "this" {
description = "KMS key for MSK cluster encryption (${local.resource_name})"
deletion_window_in_days = 30
enable_key_rotation = true
tags = local.tags
}

resource "aws_kms_alias" "this" {
name = "alias/${local.resource_name}"
target_key_id = aws_kms_key.this.id
}
9 changes: 9 additions & 0 deletions network.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
data "ns_connection" "network" {
name = "network"
contract = "network/aws/vpc"
}

locals {
vpc_id = data.ns_connection.network.outputs.vpc_id
private_subnet_ids = data.ns_connection.network.outputs.private_subnet_ids
}
24 changes: 24 additions & 0 deletions nullstone.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
terraform {
required_providers {
ns = {
source = "nullstone-io/ns"
}
}
}

data "ns_workspace" "this" {}

// Generate a random suffix to ensure uniqueness of resources
resource "random_string" "resource_suffix" {
length = 5
lower = true
upper = false
numeric = false
special = false
}

locals {
tags = data.ns_workspace.this.tags
block_name = data.ns_workspace.this.block_name
resource_name = "${data.ns_workspace.this.block_ref}-${random_string.resource_suffix.result}"
}
24 changes: 24 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
output "region" {
value = local.region
description = "string ||| The AWS Region that this instance is deployed"
}

output "cluster_arn" {
value = aws_msk_cluster.this.arn
description = "string ||| The ARN of the MSK Cluster"
}

output "cluster_name" {
value = aws_msk_cluster.this.cluster_name
description = "string ||| The name of the MSK Cluster"
}

output "bootstrap_brokers_tls" {
value = aws_msk_cluster.this.bootstrap_brokers_tls
description = "list(string) ||| The TLS-enabled Bootstrap Brokers of the MSK Cluster"
}

output "security_group_id" {
value = aws_security_group.this.id
description = "string ||| The ID of the security group attached to the Kafka cluster."
}
5 changes: 5 additions & 0 deletions security.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "aws_security_group" "this" {
name = local.resource_name
description = "MSK Security Group for ${local.resource_name}"
vpc_id = local.vpc_id
}
47 changes: 47 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
variable "kafka_version" {
type = string
default = "3.7.0"
description = <<EOF
The version of Apache Kafka.
For available versions, see https://docs.aws.amazon.com/msk/latest/developerguide/supported-kafka-versions.html
EOF
}

variable "instance_type" {
type = string
default = "kafka.m5.large"
description = <<EOF
The instance type to use for the kafka brokers.
It must be a valid Amazon MSK instance type. (e.g. `kafka.*.*`)
See https://docs.aws.amazon.com/msk/latest/developerguide/broker-instance-sizes.html
EOF
}

variable "num_broker_nodes" {
type = number
default = 2
description = <<EOF
The desired number of broker nodes in the kafka cluster.
It must be a multiple of the number of specified client subnets.
This module uses all private subnets of the connected network.
EOF
}

variable "storage_size" {
type = number
default = 100
description = <<EOF
The size of the EBS volume for each data volume in the broker nodes.
This is measured in GiB with a minimum of 1GiB and a maximum of 16 TiB.
EOF

validation {
condition = var.storage_size >= 1
error_message = "The storage size must be at least 1 GiB."
}

validation {
condition = var.storage_size <= 16384
error_message = "The storage size must be at most 16 TiB."
}
}

0 comments on commit 9070e47

Please sign in to comment.