Skip to content

Commit

Permalink
created module for kinesis data stream
Browse files Browse the repository at this point in the history
  • Loading branch information
pransh62390 committed Nov 28, 2024
1 parent 4c838f0 commit cda61cf
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 15 deletions.
21 changes: 21 additions & 0 deletions modules/kinesis/data_stream/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
resource "aws_kinesis_stream" "kinesis_stream" {
name = var.kinesis_stream_name
shard_count = var.kinesis_stream_shard_count
retention_period = var.kinesis_stream_retention_period

shard_level_metrics = var.kinesis_stream_shard_level_metrics

enforce_consumer_deletion = var.kinesis_stream_enforce_consumer_deletion
encryption_type = var.kinesis_stream_encryption_type

kms_key_id = var.kinesis_stream_kms_key_id

dynamic "stream_mode_details" {
for_each = length(var.kinesis_stream_mode_details) > 0 ? [var.kinesis_stream_mode_details] : []
content {
stream_mode = stream_mode_details.value.KINESIS_STREAM_MODE
}
}

tags = merge(var.kinesis_stream_tags, tomap({"Name" = var.kinesis_stream_name}))
}
35 changes: 35 additions & 0 deletions modules/kinesis/data_stream/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
variable "kinesis_stream_name" {
type = string
}

variable "kinesis_stream_shard_count" {
type = number
}

variable "kinesis_stream_retention_period" {
type = number
}

variable "kinesis_stream_shard_level_metrics" {
type = list(string)
}

variable "kinesis_stream_enforce_consumer_deletion" {
type = bool
}

variable "kinesis_stream_encryption_type" {
type = string
}

variable "kinesis_stream_kms_key_id" {
type = string
}

variable "kinesis_stream_tags" {
}

variable "kinesis_stream_mode_details" {
type = map(string)
default = {}
}
13 changes: 13 additions & 0 deletions templates/kinesis/data_stream/kinesis.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module "kinesis_stream" {
source = "../..//modules/kinesis/data_stream"
for_each = var.KINESIS_STREAM_LIST
kinesis_stream_name = "${var.SHORT_ENV}-${each.key}"
kinesis_stream_tags = local.common_tags
kinesis_stream_shard_count = each.value.KINESIS_STREAM_SHARD_COUNT
kinesis_stream_retention_period = each.value.KINESIS_STREAM_RETENTION_PERIOD
kinesis_stream_shard_level_metrics = each.value.KINESIS_STREAM_SHARD_LEVEL_METRICS
kinesis_stream_enforce_consumer_deletion = each.value.KINESIS_STREAM_ENFORCE_CONSUMER_DELETION
kinesis_stream_encryption_type = each.value.KINESIS_STREAM_ENCRYPTION_TYPE
kinesis_stream_kms_key_id = each.value.KINESIS_STREAM_KMS_KEY_ID
kinesis_stream_mode_details = each.value.KINESIS_STREAM_MODE_DETAILS
}
12 changes: 12 additions & 0 deletions templates/kinesis/data_stream/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
variable "KINESIS_STREAM_LIST" {
type = map(object({
KINESIS_STREAM_SHARD_COUNT = optional(number, 0) # If the stream_mode is PROVISIONED, this field is required
KINESIS_STREAM_RETENTION_PERIOD = optional(number, 0)
KINESIS_STREAM_SHARD_LEVEL_METRICS = optional(list(string), [])
KINESIS_STREAM_ENFORCE_CONSUMER_DELETION = optional(bool, false)
KINESIS_STREAM_ENCRYPTION_TYPE = optional(string, "NONE")
KINESIS_STREAM_KMS_KEY_ID = optional(string, "")
KINESIS_STREAM_MODE_DETAILS = optional(map(string), {})
}))
default = {}
}
2 changes: 1 addition & 1 deletion templates/lambda/lambda.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "lambda_function" {
source = "../../../..//modules/lambda/lambda_new"
source = "../..//modules/lambda/lambda_new"
for_each = var.LAMBDA_FUNCTION_LIST
lambda_name = "${var.SHORT_ENV}-${each.key}"
lambda_assume_role_policy = each.value.LAMBDA_FUNCTION_ASSUME_ROLE_POLICY
Expand Down
2 changes: 1 addition & 1 deletion templates/lambda/lambda_layers.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "lambda_layers" {
source = "../../../..//modules/lambda/lambda_layers"
source = "../..//modules/lambda/lambda_layers"
for_each = var.LAMBDA_LAYERS_LIST
lambda_layer_name = "${var.SHORT_ENV}-${each.key}"
lambda_layer_compatible_runtimes = each.value.LAMBDA_LAYER_COMPATIBLE_RUNTIMES
Expand Down
2 changes: 1 addition & 1 deletion templates/vpc/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "vpc" {
source = "../../../..//modules/vpc/vpc_new"
source = "../..//modules/vpc/vpc_new"
vpc_cidr = var.VPC_CIDR
vpc_enable_dns_support = var.VPC_ENABLE_DNS_SUPPORT
vpc_enable_dns_hostnames = var.VPC_ENABLE_DNS_HOSTNAMES
Expand Down
52 changes: 52 additions & 0 deletions tfvars/kinesis/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
terraform {
source = "../..//tftemplates/kinesis/data_stream"
extra_arguments "common_vars" {
commands = ["init","plan", "apply"]
}
}

inputs = {
KINESIS_STREAM_LIST = {
dynamo-ut-stream = {
KINESIS_STREAM_MODE_DETAILS = {
KINESIS_STREAM_MODE = "PROVISIONED"
}
KINESIS_STREAM_SHARD_COUNT = 2
KINESIS_STREAM_RETENTION_PERIOD = 24
}
}
}

generate "backend" {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
terraform {
backend "s3" {
bucket = "staging-setup-cloud-platform"
key = "stage.terraform.tfstate/ap-south-1/kinesis/data_stream/terraform.tfstate"
region = "ap-south-1"
}
}
EOF
}

generate "provider" {
path = "provider.tf"
if_exists = "overwrite_terragrunt"

contents = <<EOF
terraform {
required_version = ">= 1.4.2"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.21.0"
}
}
}
provider "aws" {
region = "ap-south-1"
}
EOF
}
12 changes: 1 addition & 11 deletions tfvars/lambda/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
source = "../../../../../../..//tftemplates/stage/data/ec2_infra"
source = "../..//tftemplates/lambda"
extra_arguments "common_vars" {
commands = ["init","plan", "apply"]
}
Expand Down Expand Up @@ -54,16 +54,6 @@ inputs = {
# LAMBDA_LAYERS_ARNS = [dependency.lambda_layer_arn_list.outputs.LAMBDA_LAYER_ARN[0]]
}
}

KINESIS_STREAM_LIST = {
dynamo-ut-stream = {
KINESIS_STREAM_MODE_DETAILS = {
KINESIS_STREAM_MODE = "PROVISIONED"
}
KINESIS_STREAM_SHARD_COUNT = 2
KINESIS_STREAM_RETENTION_PERIOD = 24
}
}
}

generate "backend" {
Expand Down
2 changes: 1 addition & 1 deletion tfvars/vpc/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
source = "../../../../../..//tftemplates/stage/common/vpc/"
source = "../..//tftemplates/vpc/"
extra_arguments "common_vars" {
commands = ["init","plan", "apply"]
}
Expand Down

0 comments on commit cda61cf

Please sign in to comment.