Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nfra into update-trace-id-queries-for-new-format-handling
  • Loading branch information
uolter committed Jan 11, 2024
2 parents cc1e821 + 563d1fe commit acf7f7b
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 303 deletions.
19 changes: 0 additions & 19 deletions src/main/.terraform.lock.hcl

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

1 change: 1 addition & 0 deletions src/main/06-task-person.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ resource "aws_ecs_task_definition" "person" {
{
"name": "${local.project}-xray-daemon-container",
"image": "${aws_ecr_repository.main[2].repository_url}:${var.x_ray_daemon_image_version}",
"command": ["--log-level", "error"],
"cpu": ${var.x_ray_daemon_container_cpu},
"memoryReservation": ${var.x_ray_daemon_container_memory},
"logConfiguration": {
Expand Down
1 change: 1 addition & 0 deletions src/main/07-task-user-registry.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ resource "aws_ecs_task_definition" "user_registry" {
{
"name": "${local.project}-xray-daemon-container",
"image": "${aws_ecr_repository.main[2].repository_url}:${var.x_ray_daemon_image_version}",
"command": ["--log-level", "error"],
"cpu": ${var.x_ray_daemon_container_cpu},
"memoryReservation": ${var.x_ray_daemon_container_memory},
"logConfiguration": {
Expand Down
34 changes: 6 additions & 28 deletions src/main/13-dynamodb-person.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
# Person
dynamodb_table_person = "Person"
dynamodb_gsi_person_name = keys(var.table_person_autoscling_indexes)[0]
dynamodb_gsi_person_name = "gsi_namespaced_id"
}

# Table Person
Expand All @@ -13,11 +13,9 @@ module "dynamodb_table_person" {
range_key = "SK"
stream_enabled = var.dynamodb_region_replication_enable
point_in_time_recovery_enabled = var.dynamodb_point_in_time_recovery_enabled
billing_mode = "PROVISIONED"
billing_mode = "PAY_PER_REQUEST"
stream_view_type = var.dynamodb_region_replication_enable ? "NEW_AND_OLD_IMAGES" : null
autoscaling_enabled = true
read_capacity = var.table_person_read_capacity
write_capacity = var.table_person_write_capacity


attributes = [
{
Expand All @@ -33,43 +31,23 @@ module "dynamodb_table_person" {
name = "namespacedId"
type = "S"
},
/*
{
name = "familyName"
type = "S"
},
{
name = "email"
type = "S"
},
{
name = "birthDate"
type = "S"
},
{
name = "workContacts"
type = "S"
},
*/
]

global_secondary_indexes = [
{
name = local.dynamodb_gsi_person_name
hash_key = "namespacedId"
projection_type = "KEYS_ONLY"
write_capacity = var.table_person_autoscling_indexes[local.dynamodb_gsi_person_name]["write_min_capacity"]
read_capacity = var.table_person_autoscling_indexes[local.dynamodb_gsi_person_name]["read_min_capacity"]
# write_capacity = var.table_person_autoscling_indexes[local.dynamodb_gsi_person_name]["write_min_capacity"]
# read_capacity = var.table_person_autoscling_indexes[local.dynamodb_gsi_person_name]["read_min_capacity"]
}
]


server_side_encryption_enabled = true
server_side_encryption_kms_key_arn = aws_kms_alias.dynamo_db.target_key_arn

autoscaling_read = var.table_person_autoscaling_read
autoscaling_write = var.table_person_autoscaling_write
autoscaling_indexes = var.table_person_autoscling_indexes


replica_regions = var.dynamodb_region_replication_enable ? [{
region_name = "eu-central-1"
Expand Down
100 changes: 0 additions & 100 deletions src/main/14-dynamodb-alarms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,106 +56,6 @@ module "dynamo_successful_request_latency" {
alarm_actions = [aws_sns_topic.alarms.arn]
}

## Read capacity units
module "dynamodb_read_capacity_units_limit_alarm" {
source = "git::https://github.com/terraform-aws-modules/terraform-aws-cloudwatch.git//modules/metric-alarms-by-multiple-dimensions?ref=60cf981e0f1ae033699e5b274440867e48289967"


alarm_name = "dynamodb-read-capacity-units-"
actions_enabled = var.env_short == "p" ? true : false
alarm_description = "Alarm when read capacity reaches 80% of provisioned read capacity"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 1
threshold = var.table_person_read_capacity - (var.table_person_read_capacity * 0.2)
period = 60

namespace = "AWS/DynamoDB"
metric_name = "ConsumedReadCapacityUnits"
statistic = "Average"

dimensions = {
"person" = {
TableName = local.dynamodb_table_person
},
}

alarm_actions = [aws_sns_topic.alarms.arn]
}

## Write capacity units
module "dynamodb_write_capacity_units_limit_alarm" {
source = "git::https://github.com/terraform-aws-modules/terraform-aws-cloudwatch.git//modules/metric-alarms-by-multiple-dimensions?ref=60cf981e0f1ae033699e5b274440867e48289967"

alarm_name = "dynamodb-write-capacity-units-"
actions_enabled = var.env_short == "p" ? true : false
alarm_description = "Alarm when write capacity reaches 80% of provisioned read capacity"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 1
threshold = var.table_person_write_capacity - (var.table_person_write_capacity * 0.2)
period = 60

namespace = "AWS/DynamoDB"
metric_name = "ConsumedWriteCapacityUnits"
statistic = "Average"

dimensions = {
"person" = {
TableName = local.dynamodb_table_person
},
}

alarm_actions = [aws_sns_topic.alarms.arn]
}

### Global secondary index read capacity.
module "gsi_index_read_capacity_units_limit_alarm" {
source = "git::https://github.com/terraform-aws-modules/terraform-aws-cloudwatch.git//modules/metric-alarms-by-multiple-dimensions?ref=60cf981e0f1ae033699e5b274440867e48289967"

alarm_name = "read-capacity-units-"
actions_enabled = var.env_short == "p" ? true : false
alarm_description = "Alarm when read capacity reaches 80% of provisioned read capacity"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 1
threshold = var.table_person_autoscling_indexes[local.dynamodb_gsi_person_name]["read_max_capacity"] - (var.table_person_autoscling_indexes[local.dynamodb_gsi_person_name]["read_max_capacity"] * 0.2)
period = 60

namespace = "AWS/DynamoDB"
metric_name = "ConsumedReadCapacityUnits"
statistic = "Average"

dimensions = {
"gsi_index" = {
GlobalSecondaryIndexName = local.dynamodb_gsi_person_name
},
}

alarm_actions = [aws_sns_topic.alarms.arn]
}

### Global secondary write read capacity.
module "gsi_index_write_capacity_units_limit_alarm" {
source = "git::https://github.com/terraform-aws-modules/terraform-aws-cloudwatch.git//modules/metric-alarms-by-multiple-dimensions?ref=60cf981e0f1ae033699e5b274440867e48289967"

alarm_name = "write-capacity-units-"
actions_enabled = var.env_short == "p" ? true : false
alarm_description = "Alarm when read capacity reaches 80% of provisioned read capacity"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 1
threshold = var.table_person_autoscling_indexes[local.dynamodb_gsi_person_name]["write_max_capacity"] - (var.table_person_autoscling_indexes[local.dynamodb_gsi_person_name]["write_max_capacity"] * 0.2)
period = 60

namespace = "AWS/DynamoDB"
metric_name = "ConsumedWriteCapacityUnits"
statistic = "Average"

dimensions = {
"gsi_index" = {
GlobalSecondaryIndexName = local.dynamodb_gsi_person_name
},
}

alarm_actions = [aws_sns_topic.alarms.arn]
}

#ExceedingThroughput
module "dynamodb_request_exceeding_throughput_alarm" {
Expand Down
5 changes: 5 additions & 0 deletions src/main/97-refactor.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ moved {
moved {
from = aws_api_gateway_api_key.main["INTEROP"]
to = aws_api_gateway_api_key.additional["INTEROP"]
}

moved {
from = module.dynamodb_table_person.aws_dynamodb_table.autoscaled[0]
to = module.dynamodb_table_person.aws_dynamodb_table.this[0]
}
36 changes: 0 additions & 36 deletions src/main/98-variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -384,42 +384,6 @@ variable "dynamodb_point_in_time_recovery_enabled" {
default = false
}

## Table Person
variable "table_person_read_capacity" {
type = number
description = "Table person read capacity."
}

variable "table_person_write_capacity" {
type = number
description = "Table person read capacity."
}

variable "table_person_autoscaling_read" {
type = object({
scale_in_cooldown = number
scale_out_cooldown = number
target_value = number
max_capacity = number
})
description = "Read autoscaling settings table person."
}

variable "table_person_autoscaling_write" {
type = object({
scale_in_cooldown = number
scale_out_cooldown = number
target_value = number
max_capacity = number
})
description = "Write autoscaling settings table person."
}

variable "table_person_autoscling_indexes" {
type = any
description = "Autoscaling gsi configurations"
}

variable "create_cloudhsm" {
type = bool
description = "Create cloudhsm cluster to enctypt dynamodb tables"
Expand Down
Loading

0 comments on commit acf7f7b

Please sign in to comment.