forked from barneyparker/terraform-aws-api-sns
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
64 lines (52 loc) · 1.55 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
data "aws_region" "current" {}
module "sns_integration" {
source = "github.com/DemystData/terraform-aws-api-generic"
version = "1.0.3"
api_id = var.api_id
resource_id = var.resource_id
http_method = var.http_method
authorization = var.authorization
method_request_parameters = var.method_request_parameters
name = var.name
integration_http_method = "POST"
type = "AWS"
uri = "arn:aws:apigateway:${data.aws_region.current.name}:sns:path//"
credentials = aws_iam_role.sns_publish.arn
integration_request_parameters = {
"integration.request.header.Content-Type" = "'application/x-www-form-urlencoded'"
}
request_templates = {
"application/json" = "Action=Publish&TopicArn=$util.urlEncode('${var.topic_arn}')&Message=$util.urlEncode($input.body)"
}
responses = var.responses
}
resource "aws_iam_role" "sns_publish" {
name = "${var.name}-sns-publish"
assume_role_policy = data.aws_iam_policy_document.apigw.json
}
data "aws_iam_policy_document" "apigw" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"apigateway.amazonaws.com"
]
}
}
}
resource "aws_iam_role_policy" "sns_publish" {
name = "SNS-Publish"
role = aws_iam_role.sns_publish.id
policy = data.aws_iam_policy_document.sns_publish.json
}
data "aws_iam_policy_document" "sns_publish" {
statement {
actions = [
"sns:Publish",
]
resources = [
"${var.topic_arn}",
]
}
}