Skip to content

Commit

Permalink
[#103] Add the template files for SNS module
Browse files Browse the repository at this point in the history
  • Loading branch information
longnd committed Oct 17, 2023
1 parent 61b8f85 commit fcd5c87
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
53 changes: 53 additions & 0 deletions templates/addons/aws/modules/sns/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
data "aws_iam_policy_document" "sns_platform_assume_role_policy" {
statement {
sid = "SnsPlatformAssumeRolePolicy"
effect = "Allow"
actions = ["sts:AssumeRole"]

principals {
type = "Service"
identifiers = ["sns.amazonaws.com"]
}
}
}

data "aws_iam_policy_document" "sns_platform_log_policy" {
statement {
sid = "LogMobilePushNotificationsPolicy"
effect = "Allow"

actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:PutMetricFilter",
"logs:PutRetentionPolicy"
]

resources = ["*"]
}
}

resource "aws_iam_role" "sns_platform_role" {
name = "${var.namespace}-sns-platform-log-role"

assume_role_policy = data.aws_iam_policy_document.sns_platform_assume_role_policy.json
}

resource "aws_iam_policy" "sns_platform_log_policy" {
name = "${var.namespace}-platform-log-policy"
policy = data.aws_iam_policy_document.sns_platform_log_policy.json
}

resource "aws_iam_role_policy_attachment" "sns_platform_log_policy" {
role = aws_iam_role.sns_platform_role.name
policy_arn = aws_iam_policy.sns_platform_log_policy.arn
}

resource "aws_sns_platform_application" "mobile_push_notifications" {
name = "${var.namespace}-mobile-push-notifications"
platform = "GCM"
failure_feedback_role_arn = aws_iam_role.sns_platform_role.arn
success_feedback_role_arn = aws_iam_role.sns_platform_role.arn
platform_credential = var.firebase_cloud_messaging_api_key
}
4 changes: 4 additions & 0 deletions templates/addons/aws/modules/sns/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "aws_sns_plaform_mobile_push_notifications_arn" {
description = "ARN of SNS Plaform for mobile push notifications"
value = aws_sns_platform_application.mobile_push_notifications.arn
}
9 changes: 9 additions & 0 deletions templates/addons/aws/modules/sns/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "namespace" {
description = "The namespace with environment for SNS"
type = string
}

variable "firebase_cloud_messaging_api_key" {
description = "Application Platform API key for FCM"
type = string
}

0 comments on commit fcd5c87

Please sign in to comment.