-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventbridge.tf
161 lines (136 loc) · 4.25 KB
/
eventbridge.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
resource "aws_cloudwatch_event_bus" "order" {
name = "Orders"
}
resource "aws_cloudwatch_event_rule" "order_dev_rule" {
name = "OrdersDevRule"
description = "Catchall rule for development purposes"
event_bus_name = aws_cloudwatch_event_bus.order.name
event_pattern = <<EOF
{
"account": ["${var.account_id}"],
"source": ["com.aws.orders"]
}
EOF
}
resource "aws_cloudwatch_log_group" "orders" {
name = "/aws/events/orders"
}
resource "aws_cloudwatch_event_target" "orders" {
rule = aws_cloudwatch_event_rule.order_dev_rule.name
arn = aws_cloudwatch_log_group.orders.arn
event_bus_name = aws_cloudwatch_event_bus.order.name
}
resource "aws_cloudwatch_event_connection" "api" {
name = "basic-auth-connection"
authorization_type = "BASIC"
auth_parameters {
basic {
username = "myUsername"
password = "myPassword"
}
}
}
resource "aws_cloudwatch_event_api_destination" "order_events_rule" {
name = "api-destination"
invocation_endpoint = var.apigw_url
http_method = "POST"
invocation_rate_limit_per_second = 20
connection_arn = aws_cloudwatch_event_connection.api.arn
}
resource "aws_cloudwatch_event_rule" "events" {
name = "OrdersEventsRule"
description = "Send com.aws.orders source events to API Destination"
event_bus_name = aws_cloudwatch_event_bus.order.name
event_pattern = <<EOF
{
"source": [
"com.aws.orders"
]
}
EOF
}
resource "aws_cloudwatch_event_target" "api" {
rule = aws_cloudwatch_event_rule.events.name
arn = aws_cloudwatch_event_api_destination.order_events_rule.arn
event_bus_name = aws_cloudwatch_event_bus.order.name
role_arn = aws_iam_role.invoke_api.arn
http_target {
header_parameters = {}
path_parameter_values = []
query_string_parameters = {}
}
}
resource "aws_cloudwatch_event_rule" "eu_order" {
name = "EUOrdersRule"
event_bus_name = aws_cloudwatch_event_bus.order.name
event_pattern = <<EOF
{
"detail": {
"location": [ { "prefix": "eu-" } ]
}
}
EOF
}
resource "aws_cloudwatch_event_target" "eu_order_cwlog" {
rule = aws_cloudwatch_event_rule.eu_order.name
arn = aws_cloudwatch_log_group.orders.arn
event_bus_name = aws_cloudwatch_event_bus.order.name
}
resource "aws_cloudwatch_event_target" "eu_order_sfn" {
rule = aws_cloudwatch_event_rule.eu_order.name
arn = data.aws_sfn_state_machine.order_process.arn
event_bus_name = aws_cloudwatch_event_bus.order.name
role_arn = aws_iam_role.invoke_sfn.arn
}
resource "aws_cloudwatch_event_rule" "us_lab" {
name = "USLabSupplyRule"
event_bus_name = aws_cloudwatch_event_bus.order.name
event_pattern = <<EOF
{
"detail": {
"category": [ "lab-supplies" ],
"location": [ { "prefix": "us-" } ]
}
}
EOF
}
resource "aws_cloudwatch_log_group" "us_lab" {
name = "/aws/events/us-lab"
}
resource "aws_cloudwatch_event_target" "us_lab_cwlog" {
rule = aws_cloudwatch_event_rule.us_lab.name
arn = aws_cloudwatch_log_group.us_lab.arn
event_bus_name = aws_cloudwatch_event_bus.order.name
}
resource "aws_cloudwatch_event_target" "us_lab_sns" {
rule = aws_cloudwatch_event_rule.us_lab.name
arn = data.aws_sns_topic.order.arn
event_bus_name = aws_cloudwatch_event_bus.order.name
}
resource "aws_cloudwatch_event_rule" "order_process" {
name = "OrderProcessingRule"
event_bus_name = aws_cloudwatch_event_bus.order.name
event_pattern = <<EOF
{
"source": [
"com.aws.orders"
],
"detail-type": [
"Order Processed"
]
}
EOF
}
resource "aws_cloudwatch_log_group" "order_process" {
name = "/aws/events/order-process"
}
resource "aws_cloudwatch_event_target" "order_process_cwlog" {
rule = aws_cloudwatch_event_rule.order_process.name
arn = aws_cloudwatch_log_group.order_process.arn
event_bus_name = aws_cloudwatch_event_bus.order.name
}
resource "aws_cloudwatch_event_target" "order_process_lambda" {
rule = aws_cloudwatch_event_rule.order_process.name
arn = data.aws_lambda_function.inventory.arn
event_bus_name = aws_cloudwatch_event_bus.order.name
}