Skip to content

Commit b4f1ef8

Browse files
authored
feat: Added support for API destinations (#27)
1 parent 48e63fb commit b4f1ef8

File tree

12 files changed

+587
-28
lines changed

12 files changed

+587
-28
lines changed

README.md

Lines changed: 97 additions & 25 deletions
Large diffs are not rendered by default.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# EventBridge API Destination Example
2+
3+
Configuration in this directory creates resources to control access to EventBridge using API destinations.
4+
5+
## Usage
6+
7+
To run this example you need to execute:
8+
9+
```bash
10+
$ terraform init
11+
$ terraform plan
12+
$ terraform apply
13+
```
14+
15+
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
16+
17+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
18+
## Requirements
19+
20+
| Name | Version |
21+
|------|---------|
22+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.44 |
24+
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3 |
25+
26+
## Providers
27+
28+
| Name | Version |
29+
|------|---------|
30+
| <a name="provider_random"></a> [random](#provider\_random) | >= 3 |
31+
32+
## Modules
33+
34+
| Name | Source | Version |
35+
|------|--------|---------|
36+
| <a name="module_eventbridge"></a> [eventbridge](#module\_eventbridge) | ../../ | |
37+
38+
## Resources
39+
40+
| Name | Type |
41+
|------|------|
42+
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
43+
44+
## Inputs
45+
46+
No inputs.
47+
48+
## Outputs
49+
50+
| Name | Description |
51+
|------|-------------|
52+
| <a name="output_eventbridge_api_destination_arns"></a> [eventbridge\_api\_destination\_arns](#output\_eventbridge\_api\_destination\_arns) | The EventBridge API Destination ARNs |
53+
| <a name="output_eventbridge_bus_arn"></a> [eventbridge\_bus\_arn](#output\_eventbridge\_bus\_arn) | The EventBridge Bus ARN |
54+
| <a name="output_eventbridge_connection_arns"></a> [eventbridge\_connection\_arns](#output\_eventbridge\_connection\_arns) | The EventBridge Connection ARNs |
55+
| <a name="output_eventbridge_connection_ids"></a> [eventbridge\_connection\_ids](#output\_eventbridge\_connection\_ids) | The EventBridge Connection IDs created |
56+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
provider "aws" {
2+
region = "ap-southeast-1"
3+
4+
# Make it faster by skipping something
5+
skip_get_ec2_platforms = true
6+
skip_metadata_api_check = true
7+
skip_region_validation = true
8+
skip_credentials_validation = true
9+
skip_requesting_account_id = true
10+
}
11+
12+
module "eventbridge" {
13+
source = "../../"
14+
15+
create_bus = true
16+
create_connections = true
17+
create_api_destinations = true
18+
19+
bus_name = "${random_pet.this.id}-bus"
20+
21+
attach_api_destination_policy = true
22+
23+
rules = {
24+
orders = {
25+
description = "Capture all order data"
26+
event_pattern = jsonencode({ "source" : ["myapp.orders"] })
27+
enabled = true
28+
}
29+
}
30+
31+
targets = {
32+
orders = [
33+
{
34+
name = "send-orders-to-requestbin"
35+
destination = "requestbin"
36+
attach_role_arn = true
37+
},
38+
{
39+
name = "send-orders-to-github"
40+
destination = "github"
41+
attach_role_arn = true
42+
}
43+
]
44+
}
45+
46+
connections = {
47+
requestbin = {
48+
authorization_type = "BASIC"
49+
auth_parameters = {
50+
51+
basic = {
52+
username = random_pet.this.id
53+
password = random_pet.this.id
54+
}
55+
56+
invocation_http_parameters = {
57+
body = [{
58+
key = "body-parameter-key"
59+
value = "body-parameter-value"
60+
is_value_secret = false
61+
}, {
62+
key = "body-secret-key"
63+
value = "body-secret-value"
64+
is_value_secret = true
65+
}
66+
]
67+
68+
header = [{
69+
key = "header-parameter-key1"
70+
value = "header-parameter-value1"
71+
is_value_secret = false
72+
}, {
73+
key = "header-parameter-key2"
74+
value = "header-parameter-value2"
75+
}]
76+
77+
query_string = [{
78+
key = "query-string-parameter-key1"
79+
value = "query-string-parameter-value1"
80+
is_value_secret = false
81+
}, {
82+
key = "query-string-parameter-key2"
83+
value = "query-string-parameter-value2"
84+
}]
85+
}
86+
}
87+
}
88+
89+
smee = {
90+
authorization_type = "OAUTH_CLIENT_CREDENTIALS"
91+
auth_parameters = {
92+
oauth = {
93+
authorization_endpoint = "https://smee.io/hgoubgoibwekt331"
94+
http_method = "GET"
95+
96+
client_parameters = {
97+
client_id = "1234567890"
98+
client_secret = "Pass1234!"
99+
}
100+
101+
oauth_http_parameters = {
102+
body = [{
103+
key = "body-parameter-key"
104+
value = "body-parameter-value"
105+
is_value_secret = false
106+
}]
107+
108+
header = [{
109+
key = "header-parameter-key1"
110+
value = "header-parameter-value1"
111+
}, {
112+
key = "header-parameter-key2"
113+
value = "header-parameter-value2"
114+
is_value_secret = true
115+
}]
116+
117+
query_string = [{
118+
key = "query-string-parameter-key"
119+
value = "query-string-parameter-value"
120+
is_value_secret = false
121+
}]
122+
}
123+
}
124+
}
125+
}
126+
127+
github = {
128+
authorization_type = "API_KEY"
129+
auth_parameters = {
130+
api_key = {
131+
key = "x-signature-id"
132+
value = random_pet.this.id
133+
}
134+
}
135+
}
136+
}
137+
138+
api_destinations = {
139+
smee = {
140+
description = "my smee endpoint"
141+
invocation_endpoint = "https://smee.io/hgoubgoibwekt331"
142+
http_method = "POST"
143+
invocation_rate_limit_per_second = 200
144+
}
145+
requestbin = {
146+
description = "my requestbin endpoint"
147+
invocation_endpoint = "https://smee.io/hgoubGoIbWEKt331"
148+
http_method = "POST"
149+
invocation_rate_limit_per_second = 20
150+
}
151+
github = {
152+
description = "my github endpoint"
153+
invocation_endpoint = "https://smee.io/hgoubGoIbWEKt331"
154+
http_method = "POST"
155+
invocation_rate_limit_per_second = 20
156+
}
157+
}
158+
}
159+
160+
##################
161+
# Extra resources
162+
##################
163+
164+
resource "random_pet" "this" {
165+
length = 2
166+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
output "eventbridge_bus_arn" {
2+
description = "The EventBridge Bus ARN"
3+
value = module.eventbridge.eventbridge_bus_arn
4+
}
5+
6+
# EventBridge Connection
7+
output "eventbridge_connection_ids" {
8+
description = "The EventBridge Connection IDs created"
9+
value = module.eventbridge.eventbridge_connection_ids
10+
}
11+
12+
output "eventbridge_connection_arns" {
13+
description = "The EventBridge Connection ARNs"
14+
value = module.eventbridge.eventbridge_connection_arns
15+
}
16+
17+
output "eventbridge_api_destination_arns" {
18+
description = "The EventBridge API Destination ARNs"
19+
value = module.eventbridge.eventbridge_api_destination_arns
20+
}

examples/with-api-destination/variables.tf

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
required_version = ">= 0.13.1"
3+
4+
required_providers {
5+
aws = ">= 3.44"
6+
random = ">= 3"
7+
}
8+
}

examples/with-ecs-scheduling/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,3 @@ resource "aws_ecs_task_definition" "hello_world" {
117117
resource "random_pet" "this" {
118118
length = 2
119119
}
120-

iam.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,36 @@ resource "aws_iam_policy_attachment" "sfn" {
257257
policy_arn = aws_iam_policy.sfn[0].arn
258258
}
259259

260+
#########################
261+
# API Destination Config
262+
#########################
263+
264+
data "aws_iam_policy_document" "api_destination" {
265+
count = local.create_role && var.attach_api_destination_policy ? 1 : 0
266+
267+
statement {
268+
sid = "APIDestinationAccess"
269+
effect = "Allow"
270+
actions = ["events:InvokeApiDestination"]
271+
resources = [for k, v in aws_cloudwatch_event_api_destination.this : v.arn]
272+
}
273+
}
274+
275+
resource "aws_iam_policy" "api_destination" {
276+
count = local.create_role && var.attach_api_destination_policy ? 1 : 0
277+
278+
name = "${local.role_name}-api-destination"
279+
policy = data.aws_iam_policy_document.api_destination[0].json
280+
}
281+
282+
resource "aws_iam_policy_attachment" "api_destination" {
283+
count = local.create_role && var.attach_api_destination_policy ? 1 : 0
284+
285+
name = "${local.role_name}-api-destination"
286+
roles = [aws_iam_role.eventbridge[0].name]
287+
policy_arn = aws_iam_policy.api_destination[0].arn
288+
}
289+
260290
####################
261291
# Cloudwatch Config
262292
####################

0 commit comments

Comments
 (0)