-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity.tf
114 lines (97 loc) · 2.88 KB
/
security.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
data "aws_iam_policy_document" "default_policy_document" {
count = var.policy_json != null ? 0 : 1
statement {
actions = [
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
]
resources = ["*"]
}
statement {
actions = [
"logs:CreateLogGroup",
]
resources = [
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:*",
]
}
statement {
actions = [
"logs:PutLogEvents",
"logs:CreateLogStream",
]
resources = [
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:${local.log_group_name}:*",
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/aws/lambda-insights:*",
]
}
statement {
actions = [
"kms:Decrypt",
"ssm:GetParameter",
"ssm:GetParametersByPath",
]
resources = [
"arn:aws:ssm:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:parameter${local.ssm_path}",
"arn:aws:ssm:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:parameter${local.ssm_path}*"
]
}
dynamic "statement" {
for_each = local.create_security_group ? [local.create_security_group] : []
content {
actions = [
"ec2:DescribeNetworkInterfaces",
"ec2:CreateNetworkInterface",
"ec2:DeleteNetworkInterface",
"ec2:DescribeInstances",
"ec2:AttachNetworkInterface",
]
resources = ["*"]
}
}
dynamic "statement" {
for_each = var.allow_app_config_access ? [var.allow_app_config_access] : []
content {
actions = [
"appconfig:StartConfigurationSession",
"appconfig:GetLatestConfiguration",
]
resources = ["*"]
}
}
}
module "default_role" {
count = var.role_arn != null ? 0 : 1
source = "github.com/pbs/terraform-aws-iam-role-module?ref=0.2.1"
name = local.name
policy_json = local.policy_json
use_prefix = var.use_prefix
permissions_boundary_arn = var.permissions_boundary_arn
aws_services = ["lambda", "edgelambda"]
environment = var.environment
product = var.product
repo = var.repo
organization = var.organization
}
resource "aws_security_group" "sg" {
count = local.create_security_group ? 1 : 0
description = "Controls access to the ${local.name} lambda function"
vpc_id = local.vpc_id
name_prefix = "${local.name}-sg-"
tags = merge(
local.tags,
{ Name = "${local.name} SG" },
)
}
resource "aws_security_group_rule" "egress" {
count = local.create_security_group ? 1 : 0
description = "Allow all outbound traffic"
security_group_id = local.security_group_id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = [
"0.0.0.0/0",
]
}