1
+ locals {
2
+ cdash_db_name = " cdash"
3
+ cdash_db_user = " cdash"
4
+ cdash_db_port = " 5432"
5
+ }
6
+
1
7
resource "aws_db_subnet_group" "cdash_db" {
2
8
name = " spack-cdash${ local . suffix } "
3
9
subnet_ids = module. vpc . private_subnets
@@ -12,17 +18,17 @@ module "cdash_db" {
12
18
source = " terraform-aws-modules/rds/aws"
13
19
version = " 6.10.0"
14
20
15
- identifier = " spack-cdash${ local . suffix } "
21
+ identifier = " spack-cdash-postgres ${ local . suffix } "
16
22
17
- engine = " mysql"
18
- engine_version = " 8.0.40"
19
- family = " mysql8.0"
20
- major_engine_version = " 8.0"
23
+ engine = " postgres"
24
+ family = " postgres17"
25
+ major_engine_version = " 17"
21
26
instance_class = var. cdash_db_instance_class
22
27
23
- username = " admin "
24
- port = " 3306 "
28
+ db_name = local . cdash_db_name
29
+ username = local . cdash_db_user
25
30
password = random_password. cdash_db_password . result
31
+ port = local. cdash_db_port
26
32
manage_master_user_password = false
27
33
28
34
publicly_accessible = false
@@ -37,29 +43,142 @@ module "cdash_db" {
37
43
skip_final_snapshot = true
38
44
deletion_protection = true
39
45
40
- allocated_storage = 300
46
+ allocated_storage = 400
41
47
storage_type = " gp3"
42
- iops = 3000 # 3,000 is the minimum IOPs for <400 GB storage. We can increase this as needed.
43
- storage_throughput = 125 # 125 is the minimum throughput for <400 GB storage. We can increase this as needed.
48
+ iops = 12000 # 3,000 is the minimum IOPs for <400 GB storage. We can increase this as needed.
49
+ storage_throughput = 500 # 500 is the minimum throughput for >=400 GB storage. We can increase this as needed.
50
+
51
+ vpc_security_group_ids = [module . postgres_security_group . security_group_id ]
52
+ }
53
+
54
+ resource "aws_s3_bucket" "cdash" {
55
+ bucket = " spack-cdash${ local . suffix } "
56
+ lifecycle {
57
+ prevent_destroy = true
58
+ }
59
+ }
60
+
61
+ # Bucket policy that prevents deletion of CDash bucket.
62
+ resource "aws_s3_bucket_policy" "cdash" {
63
+ bucket = aws_s3_bucket. cdash . id
64
+
65
+ policy = jsonencode ({
66
+ " Version" : " 2012-10-17" ,
67
+ " Statement" : [
68
+ {
69
+ " Principal" : " *"
70
+ " Effect" : " Deny" ,
71
+ " Action" : [
72
+ " s3:DeleteBucket" ,
73
+ ],
74
+ " Resource" : aws_s3_bucket.cdash.arn
75
+ }
76
+ ]
77
+ })
78
+ }
44
79
45
- vpc_security_group_ids = [module . mysql_security_group . security_group_id ]
80
+ resource "aws_iam_role" "cdash" {
81
+ name = " CDashS3Role-${ var . deployment_name } -${ var . deployment_stage } "
82
+ description = " Managed by Terraform. Role for CDash to assume so that it can access relevant S3 buckets."
83
+ assume_role_policy = jsonencode ({
84
+ " Version" : " 2012-10-17" ,
85
+ " Statement" : [
86
+ {
87
+ " Effect" : " Allow" ,
88
+ " Principal" : {
89
+ " Federated" : module.eks.oidc_provider_arn,
90
+ },
91
+ " Action" : " sts:AssumeRoleWithWebIdentity" ,
92
+ " Condition" : {
93
+ " StringEquals" : {
94
+ " ${ module . eks . oidc_provider } :aud" : " sts.amazonaws.com"
95
+ }
96
+ }
97
+ }
98
+ ]
99
+ })
46
100
}
47
101
48
- module "mysql_security_group" {
49
- source = " terraform-aws-modules/security-group/aws"
50
- version = " 5.2.0"
51
-
52
- name = " mysql_sg"
53
- description = " Security group for RDS MySQL database"
54
- vpc_id = module. vpc . vpc_id
55
-
56
- ingress_with_cidr_blocks = [
57
- {
58
- from_port = 3306
59
- to_port = 3306
60
- protocol = " tcp"
61
- description = " MySQL access from within VPC"
62
- cidr_blocks = module.vpc.vpc_cidr_block
63
- },
102
+ resource "aws_iam_policy" "cdash" {
103
+ name = " CDashS3Role-${ var . deployment_name } -${ var . deployment_stage } "
104
+ description = " Managed by Terraform. Grants required permissions for CDash to read/write to relevant S3 buckets."
105
+ policy = jsonencode ({
106
+ " Version" : " 2012-10-17" ,
107
+ " Statement" : [
108
+ {
109
+ " Effect" : " Allow" ,
110
+ " Action" : [
111
+ " s3:GetBucketLocation" ,
112
+ " s3:ListBucket"
113
+ ],
114
+ " Resource" : aws_s3_bucket.cdash.arn
115
+ },
116
+ {
117
+ " Effect" : " Allow" ,
118
+ " Action" : [
119
+ " s3:DeleteObject" ,
120
+ " s3:DeleteObjectVersion" ,
121
+ " s3:GetObject" ,
122
+ " s3:GetObjectAcl" ,
123
+ " s3:GetObjectVersion" ,
124
+ " s3:PutObject" ,
125
+ " s3:PutObjectAcl" ,
126
+ " s3:ReplicateObject"
127
+ ],
128
+ " Resource" : [
129
+ aws_s3_bucket.cdash.arn,
130
+ " ${ aws_s3_bucket . cdash . arn } /*"
131
+ ]
132
+ }
133
+ ]
134
+ })
135
+ }
136
+
137
+ resource "aws_iam_role_policy_attachment" "cdash" {
138
+ role = aws_iam_role. cdash . name
139
+ policy_arn = aws_iam_policy. cdash . arn
140
+ }
141
+
142
+ resource "kubectl_manifest" "cdash_service_account" {
143
+ yaml_body = <<- YAML
144
+ apiVersion: v1
145
+ kind: ServiceAccount
146
+ metadata:
147
+ name: cdash
148
+ namespace: cdash
149
+ annotations:
150
+ eks.amazonaws.com/role-arn: ${ aws_iam_role . cdash . arn }
151
+ YAML
152
+ depends_on = [
153
+ aws_iam_role_policy_attachment . cdash ,
64
154
]
65
155
}
156
+
157
+ resource "kubectl_manifest" "cdash_s3_secret" {
158
+ yaml_body = <<- YAML
159
+ apiVersion: v1
160
+ kind: Secret
161
+ metadata:
162
+ name: cdash-s3
163
+ namespace: cdash
164
+ stringData:
165
+ region: "${ data . aws_region . current . name } "
166
+ bucket: "${ aws_s3_bucket . cdash . id } "
167
+ YAML
168
+ }
169
+
170
+ resource "kubectl_manifest" "cdash_db_secret" {
171
+ yaml_body = <<- YAML
172
+ apiVersion: v1
173
+ kind: Secret
174
+ metadata:
175
+ name: cdash-db
176
+ namespace: cdash
177
+ stringData:
178
+ host: "${ module . cdash_db . db_instance_address } "
179
+ database: "${ local . cdash_db_name } "
180
+ username: "${ local . cdash_db_user } "
181
+ password: "${ random_password . cdash_db_password . result } "
182
+ port: "${ local . cdash_db_port } "
183
+ YAML
184
+ }
0 commit comments