@@ -10,15 +10,60 @@ data "aws_eks_cluster" "techchallenge_cluster" {
10
10
# DATABASE
11
11
# #############################
12
12
13
+
14
+ resource "aws_dynamodb_table" "payment_orders_replica" {
15
+ name = " Payment-OrdersReplica"
16
+ billing_mode = " PAY_PER_REQUEST"
17
+ hash_key = " Id"
18
+ stream_enabled = false
19
+
20
+ attribute {
21
+ name = " Id"
22
+ type = " S"
23
+ }
24
+
25
+ ttl {
26
+ attribute_name = " ExpireAt"
27
+ }
28
+ }
29
+
30
+ resource "aws_dynamodb_table" "payments_table" {
31
+ name = " Payments"
32
+ billing_mode = " PAY_PER_REQUEST"
33
+ hash_key = " Id"
34
+ stream_enabled = false
35
+
36
+ attribute {
37
+ name = " Id"
38
+ type = " S"
39
+ }
40
+ attribute {
41
+ name = " ExternalReference"
42
+ type = " S"
43
+ }
44
+
45
+ global_secondary_index {
46
+ name = " ExternalReference-index"
47
+ hash_key = " ExternalReference"
48
+ projection_type = " ALL"
49
+ write_capacity = 1
50
+ read_capacity = 1
51
+ }
52
+ }
53
+
13
54
locals {
14
- jwt_issuer = var. jwt_issuer
15
- jwt_aud = var. jwt_aud
16
- docker_image = var. api_docker_image
55
+ jwt_issuer = var. jwt_issuer
56
+ jwt_aud = var. jwt_aud
57
+ docker_image = var. api_docker_image
58
+ aws_access_key = var. api_access_key_id
59
+ aws_secret_access_key = var. api_secret_access_key
60
+ aws_region = " us-east-1"
61
+ jwt_signing_key = var. jwt_signing_key
17
62
}
18
63
19
64
20
65
# #############################
21
- # CONFIGS/SECRETS
66
+ # NAMESPACE
22
67
# #############################
23
68
24
69
resource "kubernetes_namespace" "payment" {
@@ -27,40 +72,44 @@ resource "kubernetes_namespace" "payment" {
27
72
}
28
73
}
29
74
75
+ # #############################
76
+ # CONFIGS/SECRETS
77
+ # #############################
78
+
79
+
30
80
resource "kubernetes_config_map_v1" "config_map_api" {
31
81
metadata {
32
- name = " configmap-api"
82
+ name = " configmap-payment -api"
33
83
namespace = " payment"
34
84
labels = {
35
- " app" = " api"
85
+ " app" = " payment- api"
36
86
" terraform" = true
37
87
}
38
88
}
39
89
data = {
40
90
" ASPNETCORE_ENVIRONMENT" = " Development"
91
+ " MercadoPago__NotificationUrl" = " "
41
92
" Serilog__WriteTo__2__Args__serverUrl" = " http://svc-seq:80"
42
93
" Serilog__WriteTo__2__Args__formatter" = " Serilog.Formatting.Json.JsonFormatter, Serilog"
43
- " MercadoPago__NotificationUrl" = " "
44
94
" Serilog__Enrich__0" = " FromLogContext"
45
95
" HybridCache__Expiration" = " 01:00:00"
46
96
" HybridCache__LocalCacheExpiration" = " 01:00:00"
47
97
" HybridCache__Flags" = " DisableDistributedCache"
48
98
" JwtOptions__Issuer" = local.jwt_issuer
49
99
" JwtOptions__Audience" = local.jwt_aud
50
- " JwtOptions__SigningKey" = var.jwt_signing_key
51
100
" JwtOptions__ExpirationSeconds" = 3600
52
101
" JwtOptions__UseAccessToken" = true
53
- # "SqsSettings__QueueName " = local.events_queue_name
54
- " SqsSettings__Enabled " = true
55
- " SqsSettings__Region " = " us-east-1 "
56
- " SqsSettings__ClientId " = var.api_access_key_id
57
- " SqsSettings__ClientSecret " = var.api_secret_access_key
102
+ " JwtOptions__SigningKey " = local.jwt_signing_key
103
+ " AwsSettings__Region " = local.aws_region
104
+ " AwsSettings__ClientSecret " = local.aws_secret_access_key
105
+ " AwsSettings__ClientId " = local.aws_access_key
106
+
58
107
}
59
108
}
60
109
61
- resource "kubernetes_secret" "secret_mercadopago " {
110
+ resource "kubernetes_secret" "secret_api " {
62
111
metadata {
63
- name = " secret-mercadopago "
112
+ name = " secret-payment-api "
64
113
namespace = " payment"
65
114
labels = {
66
115
app = " api-pod"
@@ -78,10 +127,9 @@ resource "kubernetes_secret" "secret_mercadopago" {
78
127
# API
79
128
# ###################################
80
129
81
-
82
130
resource "kubernetes_service" "payment-api-svc" {
83
131
metadata {
84
- name = var. internal_elb_name
132
+ name = var. internal_elb_name
85
133
namespace = " payment"
86
134
annotations = {
87
135
" service.beta.kubernetes.io/aws-load-balancer-type" = " nlb"
@@ -97,40 +145,46 @@ resource "kubernetes_service" "payment-api-svc" {
97
145
}
98
146
type = " LoadBalancer"
99
147
selector = {
100
- app : " api"
148
+ app : " payment- api"
101
149
}
102
150
}
103
151
}
104
152
105
153
resource "kubernetes_deployment" "deployment_payment_api" {
106
- depends_on = [kubernetes_secret . secret_mercadopago , kubernetes_config_map_v1 . config_map_api ]
154
+ depends_on = [
155
+ kubernetes_secret . secret_api ,
156
+ kubernetes_config_map_v1 . config_map_api ,
157
+ # aws_dynamodb_table.payments_table,
158
+ # aws_dynamodb_table.payment_orders_replica
159
+ ]
160
+
107
161
metadata {
108
- name = " deployment-payment-api"
162
+ name = " deployment-payment-api"
109
163
namespace = " payment"
110
164
labels = {
111
- app = " api"
165
+ app = " payment- api"
112
166
" terraform" = true
113
167
}
114
168
}
115
169
spec {
116
170
replicas = 1
117
171
selector {
118
172
match_labels = {
119
- app = " api"
173
+ app = " payment- api"
120
174
}
121
175
}
122
176
template {
123
177
metadata {
124
- name = " pod-api"
178
+ name = " pod-payment- api"
125
179
labels = {
126
- app = " api"
180
+ app = " payment- api"
127
181
" terraform" = true
128
182
}
129
183
}
130
184
spec {
131
185
automount_service_account_token = false
132
186
container {
133
- name = " api-container"
187
+ name = " payment- api-container"
134
188
image = local. docker_image
135
189
port {
136
190
name = " liveness-port"
@@ -172,12 +226,12 @@ resource "kubernetes_deployment" "deployment_payment_api" {
172
226
}
173
227
env_from {
174
228
config_map_ref {
175
- name = " configmap-api"
229
+ name = " configmap-payment- api"
176
230
}
177
231
}
178
232
env_from {
179
233
secret_ref {
180
- name = " secret-mercadopago "
234
+ name = " secret-payment-api "
181
235
}
182
236
}
183
237
}
@@ -188,7 +242,7 @@ resource "kubernetes_deployment" "deployment_payment_api" {
188
242
189
243
resource "kubernetes_horizontal_pod_autoscaler_v2" "hpa_api" {
190
244
metadata {
191
- name = " hpa-api"
245
+ name = " hpa-payment -api"
192
246
namespace = " payment"
193
247
}
194
248
spec {
@@ -203,7 +257,7 @@ resource "kubernetes_horizontal_pod_autoscaler_v2" "hpa_api" {
203
257
metric {
204
258
type = " ContainerResource"
205
259
container_resource {
206
- container = " api-container"
260
+ container = " payment- api-container"
207
261
name = " cpu"
208
262
target {
209
263
average_utilization = 65
@@ -220,7 +274,7 @@ resource "kubernetes_horizontal_pod_autoscaler_v2" "hpa_api" {
220
274
221
275
resource "kubernetes_service" "svc_seq" {
222
276
metadata {
223
- name = " svc-seq"
277
+ name = " svc-seq"
224
278
namespace = " payment"
225
279
labels = {
226
280
" terraform" = true
@@ -240,7 +294,7 @@ resource "kubernetes_service" "svc_seq" {
240
294
241
295
resource "kubernetes_deployment" "deployment_seq" {
242
296
metadata {
243
- name = " deployment-seq"
297
+ name = " deployment-seq"
244
298
namespace = " payment"
245
299
labels = {
246
300
app = " seq"
@@ -295,4 +349,4 @@ resource "kubernetes_deployment" "deployment_seq" {
295
349
}
296
350
}
297
351
}
298
- }
352
+ }
0 commit comments