Skip to content

Commit

Permalink
Creating dynamo table for install activity data (#911)
Browse files Browse the repository at this point in the history
* Adding activity tables

* Fixing dynamo source version

* Fixing dynamo version supported by terraform version

* Updating output module reference

* Adding IAM permissions for dynamo to backend lambda
  • Loading branch information
manasaV3 authored Feb 22, 2023
1 parent a88aa77 commit b8617f1
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .happy/terraform/modules/dynamo/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module dynamodb {
source = "terraform-aws-modules/dynamodb-table/aws"
version = "1.3.0"

name = var.table_name

hash_key = var.hash_key
range_key = var.range_key
attributes = var.attributes

table_class = var.table_class

point_in_time_recovery_enabled = var.tags.env == "prod" ? true : false

autoscaling_enabled = var.autoscaling_enabled
create_table = var.create_table

tags = var.tags
}
4 changes: 4 additions & 0 deletions .happy/terraform/modules/dynamo/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output table_arn {
description = "ARN of the DynamoDB table"
value = module.dynamodb.dynamodb_table_arn
}
43 changes: 43 additions & 0 deletions .happy/terraform/modules/dynamo/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
variable attributes {
type = list(map(string))
description = "Please provide the attributes list for the keys"
default = []
}

variable autoscaling_enabled {
type = bool
description = "Please provide if autoscaling is enabled"
default = false
}

variable create_table {
type = bool
description = "Please provide if table should be created"
default = false
}

variable hash_key {
type = string
description = "Please provide the hash key for table"
}

variable range_key {
type = string
description = "Please provide the range key for table"
default = null
}

variable table_class {
type = string
description = "Please provide table_class"
default = "STANDARD"
}

variable table_name {
type = string
description = "Please provide name for dynamo table"
}

variable tags {
type = map(string)
}
29 changes: 29 additions & 0 deletions .happy/terraform/modules/ecs-stack/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@ module frontend_service {
resource "random_uuid" "api_key" {
}

module install_dynamodb_table {
source = "../dynamo"
table_name = "${local.custom_stack_name}-install-activity"
hash_key = "plugin_name"
range_key = "type_timestamp"
attributes = [
{
name = "plugin_name"
type = "S"
},
{
name = "type_timestamp"
type = "S"
}
]
autoscaling_enabled = var.env == "dev" ? false : true
create_table = true
tags = var.tags
}

module backend_lambda {
source = "../lambda-container"
function_name = local.backend_function_name
Expand Down Expand Up @@ -255,6 +275,15 @@ data aws_iam_policy_document backend_policy {
resources = ["${local.data_bucket_arn}/*"]
}

statement {
actions = [
"dynamodb:GetItem",
"dynamodb:Query",
]

resources = [module.install_dynamodb_table.table_arn]
}

statement {
actions = [
"lambda:InvokeFunction"
Expand Down

0 comments on commit b8617f1

Please sign in to comment.