-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocals.tf
51 lines (44 loc) · 1.73 KB
/
locals.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
data "aws_region" "current" {}
locals {
prefix = "${var.namespace}-${var.environment}"
internet_gateway_name = var.internet_geteway_name != null ? "${var.namespace}-${var.environment}-igw" : var.internet_geteway_name
nat_gateway_data = { for key, value in local.subnet_map : key => merge(value, { key = key })
if value.create_nat_gateway }
nat_gw_routes = { for key, value in local.subnet_map : key => value if value.attach_nat_gateway }
internet_gw_routes = { for key, value in local.subnet_map : key => value if value.attach_internet_gateway }
additional_routes = flatten([for key, value in local.subnet_map : [for route in value.additional_routes : merge({ key : key }, route)] if length(value.additional_routes) > 0])
additional_routes_map = { for route in local.additional_routes : route.id => route }
subnet_map = var.subnet_map == null ? tomap(local.subnet_map_auto) : var.subnet_map
enable_vpc_flow_log = var.vpc_flow_log_config.enable
##### KMS policy for
kms_policy = jsonencode({
Version = "2012-10-17"
Id = "VPCFlowLogsPolicy"
Statement = [
{
Sid = "AllowRootAccount"
Effect = "Allow"
Principal = {
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
}
Action = "kms:*"
Resource = "*"
},
{
Sid = "AllowCloudWatchLogs"
Effect = "Allow"
Principal = {
Service = "logs.${data.aws_region.current.name}.amazonaws.com"
}
Action = [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
]
Resource = "*"
}
]
})
}