-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
156 lines (136 loc) · 4.72 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
module "networking" {
source = "./modules/networking"
vpc_name = var.vpc_name
vpc_cidr = var.vpc_cidr
availability_zones = var.availability_zones
private_subnet_cidrs = var.private_subnet_cidrs
public_subnet_cidrs = var.public_subnet_cidrs
cluster_name = var.cluster_name
single_nat_gateway = var.single_nat_gateway
tags = var.tags
}
module "eks" {
source = "./modules/eks"
cluster_name = var.cluster_name
cluster_version = var.cluster_version
vpc_id = module.networking.vpc_id
private_subnet_ids = module.networking.private_subnet_ids
environment = var.environment
node_group_desired_size = var.node_group_desired_size
node_group_min_size = var.node_group_min_size
node_group_max_size = var.node_group_max_size
node_group_instance_types = var.node_group_instance_types
node_group_ami_type = var.node_group_ami_type
tags = var.tags
cluster_enabled_log_types = var.cluster_enabled_log_types
node_group_capacity_type = var.node_group_capacity_type
enable_cluster_creator_admin_permissions = var.enable_cluster_creator_admin_permissions
}
module "storage" {
source = "./modules/storage"
bucket_name = var.bucket_name
tags = var.tags
bucket_lifecycle_rules = var.bucket_lifecycle_rules
enable_bucket_encryption = var.enable_bucket_encryption
enable_bucket_versioning = var.enable_bucket_versioning
bucket_force_destroy = var.bucket_force_destroy
}
module "database" {
source = "./modules/database"
db_identifier = var.db_identifier
postgres_version = var.postgres_version
instance_class = var.db_instance_class
allocated_storage = var.db_allocated_storage
database_name = var.database_name
database_username = var.database_username
multi_az = var.db_multi_az
database_subnet_ids = module.networking.private_subnet_ids
vpc_id = module.networking.vpc_id
eks_security_group_id = module.eks.cluster_security_group_id
eks_node_security_group_id = module.eks.node_security_group_id
tags = var.tags
max_allocated_storage = var.db_max_allocated_storage
database_password = var.database_password
}
resource "aws_cloudwatch_log_group" "materialize" {
count = var.enable_monitoring ? 1 : 0
name = "/aws/${var.log_group_name_prefix}/${var.cluster_name}/${var.environment}"
retention_in_days = var.metrics_retention_days
tags = var.tags
}
resource "aws_iam_user" "materialize" {
name = "${var.environment}-${var.mz_iam_service_account_name}"
}
resource "aws_iam_access_key" "materialize_user" {
user = aws_iam_user.materialize.name
}
resource "aws_iam_user_policy" "materialize_s3" {
name = var.mz_iam_policy_name
user = aws_iam_user.materialize.name
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:ListBucket"
]
Resource = [
module.storage.bucket_arn,
"${module.storage.bucket_arn}/*"
]
}
]
})
}
resource "aws_iam_role" "materialize_s3" {
name = "${var.environment}-${var.mz_iam_role_name}"
# Trust policy allowing EKS to assume this role
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Principal = {
Federated = module.eks.oidc_provider_arn
}
Action = "sts:AssumeRoleWithWebIdentity"
Condition = {
StringEquals = {
"${trimprefix(module.eks.cluster_oidc_issuer_url, "https://")}:sub" : "system:serviceaccount:*:*",
"${trimprefix(module.eks.cluster_oidc_issuer_url, "https://")}:aud" : "sts.amazonaws.com"
}
}
}
]
})
tags = var.tags
depends_on = [
module.eks
]
}
resource "aws_iam_role_policy" "materialize_s3" {
name = var.mz_iam_policy_name
role = aws_iam_role.materialize_s3.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:ListBucket"
]
Resource = [
module.storage.bucket_arn,
"${module.storage.bucket_arn}/*"
]
}
]
})
}