File tree Expand file tree Collapse file tree 8 files changed +93
-6
lines changed Expand file tree Collapse file tree 8 files changed +93
-6
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ let corsOrigin: string;
18
18
if ( process . env [ 'NODE_ENV' ] === 'local' ) {
19
19
corsOrigin = 'http://localhost:4200' ;
20
20
} else {
21
- corsOrigin = 'http ://dev.interviewprep.onyxdevtutorials.com' ;
21
+ corsOrigin = 'https ://dev.interviewprep.onyxdevtutorials.com' ;
22
22
}
23
23
24
24
const corsOptions = {
Original file line number Diff line number Diff line change @@ -152,6 +152,9 @@ module "load_balancer" {
152
152
vpc_id = module. vpc . vpc_id
153
153
frontend_health_check_path = " /health"
154
154
backend_health_check_path = " /health"
155
+ frontend_domain_name = " dev.interviewprep.onyxdevtutorials.com"
156
+ zone_id = aws_route53_zone. onyxdevtutorials_com . zone_id
157
+ frontend_cert_arn = module. dns . frontend_cert_arn
155
158
}
156
159
157
160
module "dns" {
@@ -163,6 +166,7 @@ module "dns" {
163
166
lb_zone_id = module. load_balancer . lb_zone_id
164
167
custom_domain_name = module. api_gateway . custom_domain_name
165
168
custom_domain_zone_id = module. api_gateway . custom_domain_zone_id
169
+ environment = var. environment
166
170
}
167
171
168
172
module "api_gateway" {
@@ -172,5 +176,5 @@ module "api_gateway" {
172
176
lb_dns_name = module. load_balancer . lb_dns_name
173
177
region = var. region
174
178
certificate_arn = var. certificate_arn
175
- cors_origin = " http ://dev.interviewprep.onyxdevtutorials.com"
179
+ cors_origin = " https ://dev.interviewprep.onyxdevtutorials.com"
176
180
}
Original file line number Diff line number Diff line change @@ -137,3 +137,8 @@ output "backend_target_group_arn" {
137
137
description = " The ARN of the backend target group"
138
138
value = module. load_balancer . backend_target_group_arn
139
139
}
140
+
141
+ output "frontend_cert_arn" {
142
+ description = " The ARN of the frontend certificate"
143
+ value = module. dns . frontend_cert_arn
144
+ }
Original file line number Diff line number Diff line change @@ -20,4 +20,40 @@ resource "aws_route53_record" "backend" {
20
20
zone_id = var. custom_domain_zone_id
21
21
evaluate_target_health = false
22
22
}
23
- }
23
+ }
24
+
25
+ resource "aws_acm_certificate" "frontend_cert" {
26
+ domain_name = var. frontend_record_name
27
+ validation_method = " DNS"
28
+
29
+ tags = {
30
+ Name = " ${ var . environment } -frontend-cert"
31
+ Environment = var.environment
32
+ }
33
+ }
34
+
35
+ resource "aws_route53_record" "frontend_cert_validation" {
36
+ for_each = {
37
+ for dvo in aws_acm_certificate . frontend_cert . domain_validation_options : dvo . domain_name => {
38
+ name = dvo.resource_record_name
39
+ type = dvo.resource_record_type
40
+ record = dvo.resource_record_value
41
+ }
42
+ }
43
+
44
+ zone_id = var. zone_id
45
+ name = each. value . name
46
+ type = each. value . type
47
+ records = [each . value . record ]
48
+ ttl = 60
49
+
50
+ lifecycle {
51
+ create_before_destroy = true
52
+ }
53
+ }
54
+
55
+ resource "aws_acm_certificate_validation" "frontend_cert_validation" {
56
+ certificate_arn = aws_acm_certificate. frontend_cert . arn
57
+ validation_record_fqdns = [for record in aws_route53_record . frontend_cert_validation : record . fqdn ]
58
+ }
59
+
Original file line number Diff line number Diff line change @@ -6,4 +6,9 @@ output "frontend_record_name" {
6
6
output "backend_record_name" {
7
7
description = " The DNS record name for the backend service"
8
8
value = aws_route53_record. backend . name
9
+ }
10
+
11
+ output "frontend_cert_arn" {
12
+ description = " The ARN of the frontend certificate"
13
+ value = aws_acm_certificate. frontend_cert . arn
9
14
}
Original file line number Diff line number Diff line change
1
+ variable "environment" {
2
+ description = " The environment in which the resources are being created"
3
+ type = string
4
+ }
5
+
1
6
variable "zone_id" {
2
7
description = " The ID of the Route 53 hosted zone"
3
8
type = string
@@ -31,4 +36,4 @@ variable "custom_domain_name" {
31
36
variable "custom_domain_zone_id" {
32
37
description = " The custom domain zone ID for api"
33
38
type = string
34
- }
39
+ }
Original file line number Diff line number Diff line change @@ -59,14 +59,31 @@ resource "aws_lb_target_group" "backend" {
59
59
}
60
60
}
61
61
62
+ resource "aws_lb_listener" "https_frontend" {
63
+ load_balancer_arn = aws_lb. this . arn
64
+ port = 443
65
+ protocol = " HTTPS"
66
+ ssl_policy = " ELBSecurityPolicy-2016-08"
67
+ certificate_arn = var. frontend_cert_arn
68
+
69
+ default_action {
70
+ type = " forward"
71
+ target_group_arn = aws_lb_target_group. frontend . arn
72
+ }
73
+ }
74
+
62
75
resource "aws_lb_listener" "http_frontend" {
63
76
load_balancer_arn = aws_lb. this . arn
64
77
port = 80
65
78
protocol = " HTTP"
66
79
67
80
default_action {
68
- type = " forward"
69
- target_group_arn = aws_lb_target_group. frontend . arn # Refer to the ECS module to see how the target group ARN is passed to the ECS service.
81
+ type = " redirect"
82
+ redirect {
83
+ port = " 443"
84
+ protocol = " HTTPS"
85
+ status_code = " HTTP_301"
86
+ }
70
87
}
71
88
}
72
89
Original file line number Diff line number Diff line change @@ -29,3 +29,18 @@ variable "backend_health_check_path" {
29
29
type = string
30
30
default = " /"
31
31
}
32
+
33
+ variable "frontend_domain_name" {
34
+ description = " The domain name for the frontend"
35
+ type = string
36
+ }
37
+
38
+ variable "zone_id" {
39
+ description = " The Route 53 zone ID for the domain"
40
+ type = string
41
+ }
42
+
43
+ variable "frontend_cert_arn" {
44
+ description = " The ARN of the certificate for the frontend"
45
+ type = string
46
+ }
You can’t perform that action at this time.
0 commit comments