-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DMVP-1050): subscription module which can link topic with lambda (…
…#1) * feat(DMVP-1050): subscription module which can link topic with lambda * fix(DMVP-1050): adjust docs/examples * chore(DMVP-1050): updated documentation
- Loading branch information
1 parent
4b3f14c
commit 0363ffa
Showing
14 changed files
with
183 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.terraform* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.50.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.26.0 | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_sns_topic_subscription.user_updates_sqs_target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_subscription) | resource | | ||
| [aws_lambda_alias.lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/lambda_alias) | data source | | ||
| [aws_sns_topic.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/sns_topic) | data source | | ||
| [aws_sqs_queue.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/sqs_queue) | data source | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_endpoint"></a> [endpoint](#input\_endpoint) | Endpoint of subscription messages will be delivered to (SQS name in case of sqs). | `any` | n/a | yes | | ||
| <a name="input_protocol"></a> [protocol](#input\_protocol) | Protocol of subscription (lambda, sqs, ...). | `any` | n/a | yes | | ||
| <a name="input_topic"></a> [topic](#input\_topic) | The name of SNS topic subscription should be attached to (not arn). | `any` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
No outputs. | ||
<!-- END_TF_DOCS --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
locals { | ||
endpoint = var.protocol == "lambda" ? data.aws_lambda_alias.lambda[0].arn : var.endpoint | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module "topic" { | ||
source = "terraform-aws-modules/sns/aws" | ||
version = "~> 3.0" | ||
|
||
name = "my-topic" | ||
} | ||
|
||
module "lambda" { | ||
source = "terraform-aws-modules/lambda/aws" | ||
version = "3.3.1" | ||
|
||
function_name = "my-lambda1" | ||
# description = "My awesome lambda function" | ||
# handler = "index.lambda_handler" | ||
# runtime = "python3.8" | ||
|
||
source_path = "./lambda-source" | ||
} | ||
|
||
module "subscription" { | ||
topic = "my-topic" | ||
protocol = "lambda" | ||
endpotin = "my-lambda1" | ||
|
||
// this is necessary as otherwise resource will not be create | ||
depends_on = [ | ||
module.topic, | ||
module.lambda | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
data "aws_lambda_alias" "lambda" { | ||
count = var.protocol == "lambda" ? 1 : 0 | ||
function_name = var.endpoint | ||
name = var.endpoint | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
data "aws_sqs_queue" "example" { | ||
count = var.protocol == "sqs" ? 1 : 0 | ||
|
||
name = var.endpoint | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
resource "aws_sns_topic_subscription" "user_updates_sqs_target" { | ||
topic_arn = local.topic_arn | ||
protocol = var.protocol | ||
endpoint = local.endpoint | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
locals { | ||
topic_arn = data.aws_sns_topic.main.arn | ||
} | ||
|
||
data "aws_sns_topic" "main" { | ||
name = var.topic | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
variable "topic" { | ||
description = "The name of SNS topic subscription should be attached to (not arn)." | ||
} | ||
|
||
variable "protocol" { | ||
description = "Protocol of subscription (lambda, sqs, ...)." | ||
|
||
validation { | ||
condition = can(regex("^lambda$|^sqs$", var.protocol)) | ||
error_message = "Protocol value must be in (lambda, sqs, ...)." | ||
} | ||
} | ||
|
||
variable "endpoint" { | ||
description = "Endpoint of subscription messages will be delivered to (SQS name in case of sqs)." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 2.50.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters