@@ -10,9 +10,12 @@ resource "aws_api_gateway_rest_api" "api" {
1010}
1111
1212resource "aws_api_gateway_deployment" "stage" {
13- depends_on = [" aws_api_gateway_integration.root_method_integration" , " aws_api_gateway_integration.integration" ]
13+ depends_on = [
14+ " aws_api_gateway_integration.root_method_integration" ,
15+ " aws_api_gateway_integration.integration"
16+ ]
1417 rest_api_id = " ${ aws_api_gateway_rest_api . api . id } "
15- stage_name = var. env
18+ stage_name = var. env
1619}
1720
1821# Create only if root-resource is not empty
@@ -30,63 +33,63 @@ resource "aws_api_gateway_method" "root_method" {
3033resource "aws_api_gateway_integration" "root_method_integration" {
3134 count = " ${ var . root-resource == true ? 1 : 0 } "
3235
33- rest_api_id = aws_api_gateway_rest_api. api . id
34- resource_id = aws_api_gateway_rest_api. api . root_resource_id
35- http_method = var. root-resource-method
36+ rest_api_id = aws_api_gateway_rest_api. api . id
37+ resource_id = aws_api_gateway_rest_api. api . root_resource_id
38+ http_method = var. root-resource-method
3639 integration_http_method = var. root-resource-method
37- type = " AWS_PROXY"
38- uri = aws_lambda_function. lambda . invoke_arn
40+ type = " AWS_PROXY"
41+ uri = aws_lambda_function. lambda . invoke_arn
3942}
4043
4144resource "aws_api_gateway_resource" "resource" {
4245 count = " ${ length (var. method-paths )} "
43- path_part = " ${ var . method-paths [count . index ]} "
44- parent_id = aws_api_gateway_rest_api. api . root_resource_id
46+ path_part = " ${ var . method-paths [count . index ]} "
47+ parent_id = aws_api_gateway_rest_api. api . root_resource_id
4548 rest_api_id = aws_api_gateway_rest_api. api . id
4649}
4750
4851resource "aws_api_gateway_method" "method" {
4952 count = " ${ length (var. method-paths )} "
50- rest_api_id = aws_api_gateway_rest_api. api . id
51- resource_id = " ${ aws_api_gateway_resource . resource [count . index ]. id } "
52- http_method = " ${ var . method-types [count . index ]} "
53+ rest_api_id = aws_api_gateway_rest_api. api . id
54+ resource_id = " ${ aws_api_gateway_resource . resource [count . index ]. id } "
55+ http_method = " ${ var . method-types [count . index ]} "
5356 authorization = var. resource-authorization
5457 request_parameters = var. resource-request-params
5558}
5659
5760resource "aws_api_gateway_integration" "integration" {
5861 count = " ${ length (var. method-paths )} "
59- rest_api_id = aws_api_gateway_rest_api. api . id
60- resource_id = " ${ aws_api_gateway_resource . resource [count . index ]. id } "
61- http_method = " ${ aws_api_gateway_method . method [count . index ]. http_method } "
62+ rest_api_id = aws_api_gateway_rest_api. api . id
63+ resource_id = " ${ aws_api_gateway_resource . resource [count . index ]. id } "
64+ http_method = " ${ aws_api_gateway_method . method [count . index ]. http_method } "
6265 integration_http_method = " POST"
63- type = " AWS_PROXY"
64- uri = aws_lambda_function. lambda . invoke_arn
66+ type = " AWS_PROXY"
67+ uri = aws_lambda_function. lambda . invoke_arn
6568}
6669
6770resource "aws_lambda_permission" "apigw_lambda" {
68- statement_id = " AllowExecutionFromAPIGateway"
69- action = " lambda:InvokeFunction"
71+ statement_id = " AllowExecutionFromAPIGateway"
72+ action = " lambda:InvokeFunction"
7073 function_name = aws_lambda_function. lambda . function_name
71- principal = " apigateway.amazonaws.com"
74+ principal = " apigateway.amazonaws.com"
7275
7376 source_arn = " arn:aws:execute-api:us-west-2:${ var . account-id } :${ aws_api_gateway_rest_api . api . id } /*"
7477}
7578
7679resource "aws_api_gateway_domain_name" "api_domain" {
7780 certificate_arn = data. aws_ssm_parameter . us-east-1-cert . value
78- domain_name = " ${ var . dns-name } .${ substr (module. acs . route53_zone . name , 0 , length (module. acs . route53_zone . name )- 1 )} "
81+ domain_name = " ${ var . dns-name } .${ substr (module. acs . route53_zone . name , 0 , length (module. acs . route53_zone . name )- 1 )} "
7982}
8083
8184resource "aws_route53_record" "a_record" {
82- name = aws_api_gateway_domain_name. api_domain . domain_name
83- type = " A"
85+ name = aws_api_gateway_domain_name. api_domain . domain_name
86+ type = " A"
8487 zone_id = module. acs . route53_zone . zone_id
8588
8689 alias {
8790 evaluate_target_health = true
88- name = aws_api_gateway_domain_name. api_domain . cloudfront_domain_name
89- zone_id = aws_api_gateway_domain_name. api_domain . cloudfront_zone_id
91+ name = aws_api_gateway_domain_name. api_domain . cloudfront_domain_name
92+ zone_id = aws_api_gateway_domain_name. api_domain . cloudfront_zone_id
9093 }
9194}
9295
@@ -153,7 +156,9 @@ resource "aws_security_group" "vpc_sec" {
153156 from_port = 0
154157 protocol = " -1"
155158 to_port = 0
156- cidr_blocks = [" 0.0.0.0/0" ]
159+ cidr_blocks = [
160+ " 0.0.0.0/0"
161+ ]
157162 }
158163
159164 lifecycle {
@@ -171,7 +176,8 @@ resource aws_lambda_function "lambda" {
171176 runtime = var. runtime
172177 timeout = var. timeout
173178 vpc_config {
174- security_group_ids = [" ${ aws_security_group . vpc_sec . id } " ]
179+ security_group_ids = [
180+ " ${ aws_security_group . vpc_sec . id } " ]
175181 subnet_ids = module. acs . private_subnet_ids
176182 }
177183 environment {
0 commit comments