Skip to content

Commit 963753f

Browse files
authored
feat: Add state to aws_cloudwatch_event_rule (#100)
Co-authored-by: magreenbaum <magreenbaum>
1 parent 093fe38 commit 963753f

File tree

32 files changed

+164
-46
lines changed

32 files changed

+164
-46
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,13 @@ module "eventbridge" {
381381
| Name | Version |
382382
|------|---------|
383383
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
384-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.9 |
384+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.27 |
385385

386386
## Providers
387387

388388
| Name | Version |
389389
|------|---------|
390-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.9 |
390+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.27 |
391391

392392
## Modules
393393

examples/api-gateway-event-source/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ Note that this example may create resources which cost money. Run `terraform des
2020
| Name | Version |
2121
|------|---------|
2222
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.9 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.27 |
2424
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |
2525

2626
## Providers
2727

2828
| Name | Version |
2929
|------|---------|
30-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.9 |
30+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.27 |
3131
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |
3232

3333
## Modules

examples/api-gateway-event-source/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ provider "aws" {
55
skip_metadata_api_check = true
66
skip_region_validation = true
77
skip_credentials_validation = true
8-
skip_requesting_account_id = true
98
}
109

1110
module "eventbridge" {

examples/api-gateway-event-source/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.9"
7+
version = ">= 5.27"
88
}
99
random = {
1010
source = "hashicorp/random"

examples/complete/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,35 @@ Note that this example may create resources which cost money. Run `terraform des
2020
| Name | Version |
2121
|------|---------|
2222
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.9 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.27 |
2424
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
2525
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |
2626

2727
## Providers
2828

2929
| Name | Version |
3030
|------|---------|
31-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.9 |
31+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.27 |
3232
| <a name="provider_null"></a> [null](#provider\_null) | >= 2.0 |
3333
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |
3434

3535
## Modules
3636

3737
| Name | Source | Version |
3838
|------|--------|---------|
39+
| <a name="module_bucket"></a> [bucket](#module\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 3.0 |
3940
| <a name="module_disabled"></a> [disabled](#module\_disabled) | ../../ | n/a |
4041
| <a name="module_ecs"></a> [ecs](#module\_ecs) | terraform-aws-modules/ecs/aws | ~> 3.0 |
4142
| <a name="module_eventbridge"></a> [eventbridge](#module\_eventbridge) | ../../ | n/a |
4243
| <a name="module_lambda"></a> [lambda](#module\_lambda) | terraform-aws-modules/lambda/aws | ~> 6.0 |
44+
| <a name="module_sns"></a> [sns](#module\_sns) | terraform-aws-modules/sns/aws | ~> 6.0 |
4345
| <a name="module_step_function"></a> [step\_function](#module\_step\_function) | terraform-aws-modules/step-functions/aws | ~> 2.0 |
4446

4547
## Resources
4648

4749
| Name | Type |
4850
|------|------|
51+
| [aws_cloudtrail.trail](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudtrail) | resource |
4952
| [aws_cloudwatch_log_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
5053
| [aws_ecs_service.hello_world](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_service) | resource |
5154
| [aws_ecs_task_definition.hello_world](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition) | resource |
@@ -56,7 +59,10 @@ Note that this example may create resources which cost money. Run `terraform des
5659
| [aws_sqs_queue_policy.queue](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue_policy) | resource |
5760
| [null_resource.download_package](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
5861
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
62+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
63+
| [aws_iam_policy_document.bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
5964
| [aws_iam_policy_document.queue](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
65+
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
6066

6167
## Inputs
6268

examples/complete/main.tf

Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,25 @@ module "eventbridge" {
4444
orders = {
4545
description = "Capture all order data"
4646
event_pattern = jsonencode({ "source" : ["myapp.orders"] })
47-
enabled = false
47+
state = "DISABLED" # conflicts with enabled which is deprecated
4848
}
4949
emails = {
5050
description = "Capture all emails data"
5151
event_pattern = jsonencode({ "source" : ["myapp.emails"] })
52-
enabled = true
52+
state = "ENABLED" # conflicts with enabled which is deprecated
5353
}
5454
crons = {
5555
description = "Trigger for a Lambda"
5656
schedule_expression = "rate(5 minutes)"
5757
}
58+
ecs = {
59+
description = "Capture ECS events"
60+
event_pattern = jsonencode({
61+
"source" : ["aws.ecs"]
62+
})
63+
# https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event.html#eb-service-event-cloudtrail
64+
state = "ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS"
65+
}
5866
}
5967

6068
targets = {
@@ -121,6 +129,13 @@ module "eventbridge" {
121129
input = jsonencode({ "job" : "crons" })
122130
}
123131
]
132+
133+
ecs = [
134+
{
135+
name = "something-for-ecs"
136+
arn = module.sns.topic_arn
137+
}
138+
]
124139
}
125140

126141
######################
@@ -370,6 +385,110 @@ resource "null_resource" "download_package" {
370385
}
371386
}
372387

388+
#######
389+
# SNS
390+
#######
391+
392+
module "sns" {
393+
source = "terraform-aws-modules/sns/aws"
394+
version = "~> 6.0"
395+
396+
name = "${random_pet.this.id}-notifications"
397+
topic_policy_statements = {
398+
events = {
399+
actions = ["sns:publish"]
400+
principals = [{
401+
type = "Service"
402+
identifiers = ["events.amazonaws.com"]
403+
}]
404+
}
405+
}
406+
tags = {
407+
name = "${random_pet.this.id}-notifications"
408+
}
409+
}
410+
411+
##############
412+
# CloudTrail
413+
##############
414+
415+
# required for event rule state of ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS
416+
resource "aws_cloudtrail" "trail" {
417+
name = "${random_pet.this.id}-trail"
418+
s3_bucket_name = module.bucket.s3_bucket_id
419+
include_global_service_events = false
420+
421+
event_selector {
422+
exclude_management_event_sources = [
423+
"kms.amazonaws.com",
424+
"rdsdata.amazonaws.com"
425+
]
426+
read_write_type = "ReadOnly"
427+
}
428+
}
429+
430+
#######
431+
# s3
432+
#######
433+
434+
data "aws_region" "current" {}
435+
436+
data "aws_caller_identity" "current" {}
437+
438+
module "bucket" {
439+
source = "terraform-aws-modules/s3-bucket/aws"
440+
version = "~> 3.0"
441+
442+
bucket = "${random_pet.this.id}-bucket"
443+
attach_policy = true
444+
policy = data.aws_iam_policy_document.bucket_policy.json
445+
446+
force_destroy = true
447+
}
448+
449+
# https://docs.aws.amazon.com/awscloudtrail/latest/userguide/create-s3-bucket-policy-for-cloudtrail.html
450+
data "aws_iam_policy_document" "bucket_policy" {
451+
statement {
452+
sid = "AWSCloudTrailAclCheck"
453+
principals {
454+
identifiers = ["cloudtrail.amazonaws.com"]
455+
type = "Service"
456+
}
457+
actions = ["s3:GetBucketAcl"]
458+
resources = [
459+
"arn:aws:s3:::${random_pet.this.id}-bucket"
460+
]
461+
condition {
462+
test = "StringEquals"
463+
values = ["arn:aws:cloudtrail:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:trail/${random_pet.this.id}-trail"]
464+
variable = "aws:SourceArn"
465+
}
466+
}
467+
468+
statement {
469+
sid = "AWSCloudTrailWrite"
470+
principals {
471+
identifiers = ["cloudtrail.amazonaws.com"]
472+
type = "Service"
473+
}
474+
actions = ["s3:PutObject"]
475+
resources = [
476+
"arn:aws:s3:::${random_pet.this.id}-bucket/*"
477+
]
478+
condition {
479+
test = "StringEquals"
480+
values = ["bucket-owner-full-control"]
481+
variable = "s3:x-amz-acl"
482+
}
483+
condition {
484+
test = "StringEquals"
485+
values = ["arn:aws:cloudtrail:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:trail/${random_pet.this.id}-trail"]
486+
variable = "aws:SourceArn"
487+
}
488+
}
489+
490+
}
491+
373492
#######
374493
## Lambda
375494
#######

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.9"
7+
version = ">= 5.27"
88
}
99
random = {
1010
source = "hashicorp/random"

examples/default-bus/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ Note that this example may create resources which cost money. Run `terraform des
2020
| Name | Version |
2121
|------|---------|
2222
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.9 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.27 |
2424
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |
2525

2626
## Providers
2727

2828
| Name | Version |
2929
|------|---------|
30-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.9 |
30+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.27 |
3131
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |
3232

3333
## Modules

examples/default-bus/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ provider "aws" {
55
skip_metadata_api_check = true
66
skip_region_validation = true
77
skip_credentials_validation = true
8-
skip_requesting_account_id = true
98
}
109

1110
module "eventbridge" {

examples/default-bus/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.9"
7+
version = ">= 5.27"
88
}
99
random = {
1010
source = "hashicorp/random"

0 commit comments

Comments
 (0)