-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
129 lines (110 loc) · 2.62 KB
/
main.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
# Infrastructure
locals {
tags = {
CreatedBy = "Terraform"
Environment = var.tag_environment
}
}
provider "aws" {
region = var.aws_region
}
provider "aws" {
alias = "us-east-1"
region = "us-east-1"
}
# GuardDuty
module "guardduty" {
source = "./guardduty"
regions = var.regions
}
# IAM Access Analyzer
module "analyzer" {
source = "./analyzer"
regions = var.regions
tag_name = var.tag_name
tag_environment = var.tag_environment
tags_shared = var.tags_shared
}
# Security Hub
module "securityhub" {
source = "./securityhub"
regions = var.regions
}
# IAM
data "aws_iam_policy_document" "sns" {
statement {
effect = "Allow"
actions = ["SNS:Publish"]
principals {
type = "Service"
identifiers = ["events.amazonaws.com"]
}
resources = [aws_sns_topic.main.arn]
}
}
# SNS
resource "aws_sns_topic" "main" {
name = "top${var.tag_name}${var.tag_environment}"
tags = merge(
local.tags,
var.tags_shared,
{
"Name" = "top${var.tag_name}${var.tag_environment}"
}
)
}
resource "aws_sns_topic_policy" "main" {
arn = aws_sns_topic.main.arn
policy = data.aws_iam_policy_document.sns.json
}
resource "aws_sns_topic" "ue1" {
provider = aws.us-east-1
name = "top${var.tag_name}${var.tag_environment}"
tags = merge(
local.tags,
var.tags_shared,
{
"Name" = "top${var.tag_name}${var.tag_environment}"
}
)
}
resource "aws_sns_topic_policy" "ue1" {
provider = aws.us-east-1
arn = aws_sns_topic.ue1.arn
policy = data.aws_iam_policy_document.sns.json
}
# CloudWatch
resource "aws_cloudwatch_event_rule" "main" {
name = "ruleSecHub${var.tag_name}${var.tag_environment}"
description = "Security Hub"
event_pattern = file("${path.module}/patterns/securityhub.json")
tags = merge(
local.tags,
var.tags_shared,
{
"Name" = "ruleSecHub${var.tag_name}${var.tag_environment}"
}
)
}
resource "aws_cloudwatch_event_target" "main" {
rule = aws_cloudwatch_event_rule.main.name
arn = aws_sns_topic.main.arn
}
resource "aws_cloudwatch_event_rule" "console" {
provider = aws.us-east-1
name = "ruleConsole${var.tag_name}${var.tag_environment}"
description = "Console Sign-in"
event_pattern = file("${path.module}/patterns/console.json")
tags = merge(
local.tags,
var.tags_shared,
{
"Name" = "ruleConsole${var.tag_name}${var.tag_environment}"
}
)
}
resource "aws_cloudwatch_event_target" "console" {
provider = aws.us-east-1
rule = aws_cloudwatch_event_rule.console.name
arn = aws_sns_topic.ue1.arn
}