@@ -9,30 +9,48 @@ terraform {
99 }
1010}
1111
12- # Create API Gateway
13- resource "aws_apigatewayv2_api" "my_api " {
14- name = " secure-api-101 "
12+ # Create an HTTP API
13+ resource "aws_apigatewayv2_api" "example " {
14+ name = " example-http-api "
1515 protocol_type = " HTTP"
16+ description = " Example HTTP API Gateway"
1617}
1718
18- # Create API Gateway Stage
19- resource "aws_apigatewayv2_stage" "dev" {
20- api_id = aws_apigatewayv2_api. my_api . id
21- name = " dev"
22- auto_deploy = true
19+ # "/api/v1/hi" route
20+ resource "aws_apigatewayv2_route" "api_v1_hi_route" {
21+ api_id = aws_apigatewayv2_api. example . id
22+ route_key = " GET /api/v1/hi"
23+ target = " integrations/${ aws_apigatewayv2_integration . api_v1_hi_integration . id } "
24+ }
25+
26+ # "/" route
27+ resource "aws_apigatewayv2_route" "root_route" {
28+ api_id = aws_apigatewayv2_api. example . id
29+ route_key = " GET /"
30+ target = " integrations/${ aws_apigatewayv2_integration . root_integration . id } "
2331}
2432
25- # Attach API Gateway to ALB
26- resource "aws_apigatewayv2_integration" "alb " {
27- api_id = aws_apigatewayv2_api. my_api . id
28- integration_type = " HTTP_PROXY "
33+ # Integration for the "/" route
34+ resource "aws_apigatewayv2_integration" "root_integration " {
35+ api_id = aws_apigatewayv2_api. example . id
36+ integration_type = " HTTP "
2937 integration_uri = var. alb_dns
30- integration_method = " ANY"
38+ integration_method = " GET"
39+ payload_format_version = " 1.0"
3140}
3241
33- # Create Route for API Gateway
34- resource "aws_apigatewayv2_route" "hello_route" {
35- api_id = aws_apigatewayv2_api. my_api . id
36- route_key = " GET /api/v1/hi"
37- target = " integrations/${ aws_apigatewayv2_integration . alb . id } "
42+ # Integration for the "/api/v1/hi" route
43+ resource "aws_apigatewayv2_integration" "api_v1_hi_integration" {
44+ api_id = aws_apigatewayv2_api. example . id
45+ integration_type = " HTTP"
46+ integration_uri = " ${ var . alb_dns } /api/v1/hi"
47+ integration_method = " GET"
48+ payload_format_version = " 1.0"
49+ }
50+
51+ # "dev" stage for the HTTP API
52+ resource "aws_apigatewayv2_stage" "dev_stage" {
53+ api_id = aws_apigatewayv2_api. example . id
54+ stage_name = " dev"
55+ auto_deploy = true
3856}
0 commit comments