File tree Expand file tree Collapse file tree 8 files changed +48
-43
lines changed Expand file tree Collapse file tree 8 files changed +48
-43
lines changed Original file line number Diff line number Diff line change @@ -170,14 +170,15 @@ module "dns" {
170
170
backend_record_name = " api.dev.interviewprep.onyxdevtutorials.com"
171
171
lb_dns_name = module. load_balancer . lb_dns_name
172
172
lb_zone_id = module. load_balancer . lb_zone_id
173
- api_invoke_url = replace (module. api_gateway . api_invoke_url , " /dev" , " " )
173
+ custom_domain_name = module. api_gateway . custom_domain_name
174
+ custom_domain_zone_id = module. api_gateway . custom_domain_zone_id
174
175
}
175
176
176
177
module "api_gateway" {
177
178
source = " ../../modules/api_gateway"
178
179
environment = var. environment
179
- # backend_dns_name = module.dns.backend_record_name
180
180
cloudwatch_role_arn = module. iam . api_gateway_cloudwatch_role_arn
181
181
lb_dns_name = module. load_balancer . lb_dns_name
182
182
region = var. region
183
+ certificate_arn = var. certificate_arn
183
184
}
Original file line number Diff line number Diff line change @@ -139,13 +139,3 @@ output "backend_target_group_arn" {
139
139
description = " The ARN of the backend target group"
140
140
value = module. load_balancer . backend_target_group_arn
141
141
}
142
-
143
- # output "api_key_id" {
144
- # description = "The ID of the API Gateway API key"
145
- # value = module.api_gateway.api_key_id
146
- # }
147
-
148
- output "api_invoke_url" {
149
- description = " The invoke URL of the API Gateway"
150
- value = module. api_gateway . api_invoke_url
151
- }
Original file line number Diff line number Diff line change @@ -107,4 +107,9 @@ variable "key_name" {
107
107
variable "lambda_package_migrate" {
108
108
description = " The path to the ZIP file containing the Lambda function code"
109
109
type = string
110
+ }
111
+
112
+ variable "certificate_arn" {
113
+ description = " The ARN of the certificate to use for the custom domain"
114
+ type = string
110
115
}
Original file line number Diff line number Diff line change @@ -160,23 +160,18 @@ resource "aws_iam_role_policy_attachment" "api_gateway_cloudwatch_policy_attachm
160
160
role = aws_iam_role. api_gateway_cloudwatch_role . name
161
161
}
162
162
163
- # resource "aws_api_gateway_api_key" "api_key" {
164
- # name = "${var.environment}-interview-prep-api-key"
165
- # description = "API Key for Interview Prep ${var.environment} environment"
166
- # enabled = true
167
- # }
168
-
169
- # resource "aws_api_gateway_usage_plan" "usage_plan" {
170
- # name = "${var.environment}-interview-prep-usage-plan"
171
- # description = "Usage Plan for Interview Prep ${var.environment} environment"
172
- # api_stages {
173
- # api_id = aws_api_gateway_rest_api.api.id
174
- # stage = aws_api_gateway_stage.api_stage.stage_name
175
- # }
176
- # }
177
-
178
- # resource "aws_api_gateway_usage_plan_key" "usage_plan_key" {
179
- # key_id = aws_api_gateway_api_key.api_key.id
180
- # key_type = "API_KEY"
181
- # usage_plan_id = aws_api_gateway_usage_plan.usage_plan.id
182
- # }
163
+ resource "aws_api_gateway_domain_name" "custom_domain" {
164
+ domain_name = " api.dev.interviewprep.onyxdevtutorials.com"
165
+
166
+ endpoint_configuration {
167
+ types = [" EDGE" ]
168
+ }
169
+
170
+ certificate_arn = var. certificate_arn
171
+ }
172
+
173
+ resource "aws_api_gateway_base_path_mapping" "custom_domain_mapping" {
174
+ api_id = aws_api_gateway_rest_api. api . id
175
+ stage_name = aws_api_gateway_stage. api_stage . stage_name
176
+ domain_name = aws_api_gateway_domain_name. custom_domain . domain_name
177
+ }
Original file line number Diff line number Diff line change 1
- output "api_invoke_url" {
2
- value = " https://${ aws_api_gateway_rest_api . api . id } .execute-api.${ var . region } .amazonaws.com/dev"
1
+ output "custom_domain_name" {
2
+ description = " The custom domain name"
3
+ value = aws_api_gateway_domain_name. custom_domain . cloudfront_domain_name
3
4
}
4
5
5
- # output "api_key_id" {
6
- # value = aws_api_gateway_api_key.api_key.id
7
- # }
6
+ output "custom_domain_zone_id" {
7
+ description = " The custom domain zone ID"
8
+ value = aws_api_gateway_domain_name. custom_domain . cloudfront_zone_id
9
+ }
Original file line number Diff line number Diff line change @@ -16,4 +16,9 @@ variable "cloudwatch_role_arn" {
16
16
variable "lb_dns_name" {
17
17
description = " The DNS name of the load balancer"
18
18
type = string
19
+ }
20
+
21
+ variable "certificate_arn" {
22
+ description = " The ARN of the certificate to use for the custom domain"
23
+ type = string
19
24
}
Original file line number Diff line number Diff line change @@ -13,8 +13,11 @@ resource "aws_route53_record" "frontend" {
13
13
resource "aws_route53_record" "backend" {
14
14
zone_id = var. zone_id
15
15
name = var. backend_record_name
16
- type = " CNAME "
16
+ type = " A "
17
17
18
- records = [replace (var. api_invoke_url , " https://" , " " )]
19
- ttl = 300
18
+ alias {
19
+ name = var. custom_domain_name
20
+ zone_id = var. custom_domain_zone_id
21
+ evaluate_target_health = false
22
+ }
20
23
}
Original file line number Diff line number Diff line change @@ -23,8 +23,12 @@ variable "lb_zone_id" {
23
23
type = string
24
24
}
25
25
26
- variable "api_invoke_url" {
27
- description = " The invoke URL of the API Gateway"
26
+ variable "custom_domain_name" {
27
+ description = " The custom domain name for api"
28
+ type = string
29
+ }
30
+
31
+ variable "custom_domain_zone_id" {
32
+ description = " The custom domain zone ID for api"
28
33
type = string
29
- default = " placeholder"
30
34
}
You can’t perform that action at this time.
0 commit comments