-
Notifications
You must be signed in to change notification settings - Fork 7
/
sns.tf
66 lines (59 loc) · 1.43 KB
/
sns.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
65
66
# Create an sns topic
resource "aws_sns_topic" "beamtest_topic" {
name = "soracom_beamtest_topic"
}
# Subscribe to sns topic with endpoint of our phone number
resource "aws_sns_topic_subscription" "beamtest_notification_target" {
topic_arn = aws_sns_topic.beamtest_topic.arn
protocol = "sms"
endpoint = var.phone_number
}
# Create iot topic rule that forwards all iot messages to sns
resource "aws_iot_topic_rule" "beamtest_topic_rule" {
name = "SoracomBeamTestTopicRule"
enabled = true
sql_version = "2016-03-23"
sql = "SELECT * FROM 'beamtest'"
sns {
message_format = "RAW"
role_arn = aws_iam_role.beamtest_role.arn
target_arn = aws_sns_topic.beamtest_topic.arn
}
}
# The role for the sns topic
resource "aws_iam_role" "beamtest_role" {
name = "SoracomBeamTestRole"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "iot.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
# Policy that allows our iot thing to access our sns topic
resource "aws_iam_role_policy" "beamtest_role_policy" {
name = "beamtest_sns_policy"
role = aws_iam_role.beamtest_role.id
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sns:Publish"
],
"Resource": "${aws_sns_topic.beamtest_topic.arn}"
}
]
}
EOF
}