Skip to content

Commit

Permalink
fix: Fixed apigateway trigger to use source_arn (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbabenko authored Jan 14, 2021
1 parent f1abf32 commit 835b701
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ module "lambda_function" {
allowed_triggers = {
APIGatewayAny = {
service = "apigateway"
arn = "arn:aws:execute-api:eu-west-1:135367859851:aqnku8akd0"
service = "apigateway"
source_arn = "arn:aws:execute-api:eu-west-1:135367859851:aqnku8akd0/*/*/*"
},
APIGatewayDevPost = {
service = "apigateway"
Expand All @@ -292,8 +292,6 @@ module "lambda_function" {
}
```

Note: `service = "apigateway" with arn` is a short form to allow invocations of a Lambda Function from any stage, any method, any resource of an API Gateway.

## Conditional creation

Sometimes you need to have a way to create resources conditionally but Terraform does not allow usage of `count` inside `module` block, so the solution is to specify `create` arguments.
Expand Down
12 changes: 6 additions & 6 deletions examples/alias/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module "lambda_function" {

allowed_triggers = {
APIGatewayAny = {
service = "apigateway"
arn = "arn:aws:execute-api:eu-west-1:135367859851:aqnku8akd0"
service = "apigateway"
source_arn = "arn:aws:execute-api:eu-west-1:135367859851:aqnku8akd0/*/*/*"
}
}

Expand Down Expand Up @@ -62,8 +62,8 @@ module "alias_no_refresh" {

allowed_triggers = {
AnotherAPIGatewayAny = { # keys should be unique
service = "apigateway"
arn = "arn:aws:execute-api:eu-west-1:135367859851:abcdedfgse"
service = "apigateway"
source_arn = "arn:aws:execute-api:eu-west-1:135367859851:abcdedfgse/*/*/*"
}
}

Expand Down Expand Up @@ -94,8 +94,8 @@ module "alias_existing" {

allowed_triggers = {
ThirdAPIGatewayAny = {
service = "apigateway"
arn = "arn:aws:execute-api:eu-west-1:135367859851:aqnku8akd0"
service = "apigateway"
source_arn = "arn:aws:execute-api:eu-west-1:135367859851:aqnku8akd0/*/*/*"
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ module "lambda_function" {

allowed_triggers = {
APIGatewayAny = {
service = "apigateway"
arn = "arn:aws:execute-api:eu-west-1:135367859851:aqnku8akd0"
service = "apigateway"
source_arn = "arn:aws:execute-api:eu-west-1:135367859851:aqnku8akd0/*/*/*"
},
APIGatewayDevPost = {
service = "apigateway"
Expand Down
4 changes: 2 additions & 2 deletions examples/deploy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ module "lambda_function" {

allowed_triggers = {
APIGatewayAny = {
service = "apigateway"
arn = "arn:aws:execute-api:eu-west-1:135367859851:aqnku8akd0"
service = "apigateway"
source_arn = "arn:aws:execute-api:eu-west-1:135367859851:aqnku8akd0/*/*/*"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ resource "aws_lambda_permission" "current_version_triggers" {
statement_id = lookup(each.value, "statement_id", each.key)
action = lookup(each.value, "action", "lambda:InvokeFunction")
principal = lookup(each.value, "principal", format("%s.amazonaws.com", lookup(each.value, "service", "")))
source_arn = lookup(each.value, "source_arn", lookup(each.value, "service", null) == "apigateway" ? "${lookup(each.value, "arn", "")}/*/*/*" : null)
source_arn = lookup(each.value, "source_arn", null)
source_account = lookup(each.value, "source_account", null)
event_source_token = lookup(each.value, "event_source_token", null)
}
Expand All @@ -200,7 +200,7 @@ resource "aws_lambda_permission" "unqualified_alias_triggers" {
statement_id = lookup(each.value, "statement_id", each.key)
action = lookup(each.value, "action", "lambda:InvokeFunction")
principal = lookup(each.value, "principal", format("%s.amazonaws.com", lookup(each.value, "service", "")))
source_arn = lookup(each.value, "source_arn", lookup(each.value, "service", null) == "apigateway" ? "${lookup(each.value, "arn", "")}/*/*/*" : null)
source_arn = lookup(each.value, "source_arn", null)
source_account = lookup(each.value, "source_account", null)
event_source_token = lookup(each.value, "event_source_token", null)
}
8 changes: 4 additions & 4 deletions modules/alias/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ module "alias_no_refresh" {
allowed_triggers = {
AnotherAPIGatewayAny = {
service = "apigateway"
arn = "arn:aws:execute-api:eu-west-1:135367859851:abcdedfgse"
service = "apigateway"
source_arn = "arn:aws:execute-api:eu-west-1:135367859851:abcdedfgse/*/*/*"
}
}
}
Expand Down Expand Up @@ -76,8 +76,8 @@ module "alias_existing" {
allowed_triggers = {
AnotherAwesomeAPIGateway = {
service = "apigateway"
arn = "arn:aws:execute-api:eu-west-1:999967859851:aqnku8akd0"
service = "apigateway"
source_arn = "arn:aws:execute-api:eu-west-1:999967859851:aqnku8akd0/*/*/*"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/alias/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ resource "aws_lambda_permission" "version_triggers" {
statement_id = lookup(each.value, "statement_id", each.key)
action = lookup(each.value, "action", "lambda:InvokeFunction")
principal = lookup(each.value, "principal", format("%s.amazonaws.com", lookup(each.value, "service", "")))
source_arn = lookup(each.value, "source_arn", lookup(each.value, "service", null) == "apigateway" ? "${lookup(each.value, "arn", "")}/*/*/*" : null)
source_arn = lookup(each.value, "source_arn", null)
source_account = lookup(each.value, "source_account", null)
event_source_token = lookup(each.value, "event_source_token", null)
}
Expand All @@ -104,7 +104,7 @@ resource "aws_lambda_permission" "qualified_alias_triggers" {
statement_id = lookup(each.value, "statement_id", each.key)
action = lookup(each.value, "action", "lambda:InvokeFunction")
principal = lookup(each.value, "principal", format("%s.amazonaws.com", lookup(each.value, "service", "")))
source_arn = lookup(each.value, "source_arn", lookup(each.value, "service", null) == "apigateway" ? "${lookup(each.value, "arn", "")}/*/*/*" : null)
source_arn = lookup(each.value, "source_arn", null)
source_account = lookup(each.value, "source_account", null)
event_source_token = lookup(each.value, "event_source_token", null)
}

0 comments on commit 835b701

Please sign in to comment.