-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiot.tf
70 lines (52 loc) · 1.46 KB
/
iot.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
67
68
69
70
#--iot/main--
resource "aws_iot_thing" "iot_core" {
name = "your-iot-core-thing"
}
resource "aws_iot_certificate" "iot_certificate" {
active = true
}
resource "aws_iot_thing_principal_attachment" "iot_attachment" {
principal = aws_iot_certificate.iot_certificate.arn
thing = aws_iot_thing.iot_core.name
}
resource "aws_iot_topic_rule" "iot_rule" {
name = "iot_rule"
sql = "SELECT * FROM 'iot-core-topic'"
sql_version = "2016-03-23"
enabled = true
description = "Send data from the AWS IoT Core to AWS Timestream"
timestream {
database_name = aws_timestreamwrite_database.timestream_database.database_name
dimension {
name = "temperature"
value = "DOUBLE"
}
dimension {
name = "humidity"
value = "DOUBLE"
}
table_name = aws_timestreamwrite_table.timestream_table.table_name
role_arn = aws_iam_role.iot_role.arn
}
}
resource "aws_iot_policy" "iot_timestream_policy" {
name = "iot-timestream-policy"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"timestream:WriteRecords"
]
Resource = [
"${aws_timestreamwrite_database.timestream_database.arn}"
]
}
]
})
}
resource "aws_iot_policy_attachment" "iot_policy_attachment" {
policy = aws_iot_policy.iot_timestream_policy.name
target = aws_iot_certificate.iot_certificate.arn
}