Skip to content

Commit d635ee5

Browse files
committed
Added support for multiple HTTP methods
1 parent 79c6d54 commit d635ee5

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

api_gateway.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ resource "aws_api_gateway_resource" "resource" {
99
}
1010

1111
resource "aws_api_gateway_method" "method" {
12+
count = length(var.http_methods)
1213
rest_api_id = aws_api_gateway_rest_api.api.id
1314
resource_id = aws_api_gateway_resource.resource.id
14-
http_method = var.http_method
15+
http_method = var.http_methods[count.index]
1516
authorization = "NONE"
1617
}
1718

1819
resource "aws_api_gateway_integration" "integration" {
20+
count = length(var.http_methods)
1921
rest_api_id = aws_api_gateway_rest_api.api.id
2022
resource_id = aws_api_gateway_resource.resource.id
21-
http_method = aws_api_gateway_method.method.http_method
22-
integration_http_method = var.http_method
23+
integration_http_method = var.http_methods[count.index]
24+
http_method = var.http_methods[count.index]
2325
type = "AWS_PROXY"
2426
uri = aws_lambda_function.lambda.invoke_arn
2527
}
@@ -30,7 +32,7 @@ resource "aws_lambda_permission" "apigw_lambda" {
3032
function_name = aws_lambda_function.lambda.function_name
3133
principal = "apigateway.amazonaws.com"
3234

33-
source_arn = "arn:aws:execute-api:${var.region}:${local.account_id}:${aws_api_gateway_rest_api.api.id}/*/${aws_api_gateway_method.method.http_method}${aws_api_gateway_resource.resource.path}"
35+
source_arn = "arn:aws:execute-api:${var.region}:${local.account_id}:${aws_api_gateway_rest_api.api.id}/*/*"
3436
}
3537

3638
resource "aws_api_gateway_deployment" "deployment" {

variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ variable environment_variables {
1111
default = {}
1212
}
1313

14-
variable http_method {
15-
type = string
16-
default = "GET"
14+
variable http_methods {
15+
type = list(string)
16+
default = ["GET"]
1717
}
1818

1919
variable lambda_function_name {

0 commit comments

Comments
 (0)