Skip to content

Commit d49fed3

Browse files
authored
Add lattice-lambda-target-group (#14)
1 parent 0e74d67 commit d49fed3

File tree

18 files changed

+357
-4
lines changed

18 files changed

+357
-4
lines changed

.github/labeler.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
":floppy_disk: lattice-ip-target-group":
1818
- modules/lattice-ip-target-group/**/*
1919

20+
":floppy_disk: lattice-lambda-target-group":
21+
- modules/lattice-lambda-target-group/**/*
22+
2023
":floppy_disk: lattice-service-listener":
2124
- modules/lattice-service-listener/**/*
2225

.github/labels.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
- color: "fbca04"
5959
description: "This issue or pull request is related to lattice-ip-target-group module."
6060
name: ":floppy_disk: lattice-ip-target-group"
61+
- color: "fbca04"
62+
description: "This issue or pull request is related to lattice-lambda-target-group module."
63+
name: ":floppy_disk: lattice-lambda-target-group"
6164
- color: "fbca04"
6265
description: "This issue or pull request is related to lattice-service-listener module."
6366
name: ":floppy_disk: lattice-service-listener"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Terraform module which creates VPC Connectivity related resources (VPC Peering,
1212
- [lattice-alb-target-group](./modules/lattice-alb-target-group)
1313
- [lattice-instance-target-group](./modules/lattice-instance-target-group)
1414
- [lattice-ip-target-group](./modules/lattice-ip-target-group)
15+
- [lattice-lambda-target-group](./modules/lattice-lambda-target-group)
1516
- [lattice-service-listener](./modules/lattice-service-listener)
1617
- [lattice-service-network](./modules/lattice-service-network)
1718
- [lattice-service](./modules/lattice-service)
@@ -42,6 +43,7 @@ Terraform Modules from [this package](https://github.com/tedilabs/terraform-aws-
4243
- ALB Target Group
4344
- Instance Target Group
4445
- IP Target Group
46+
- Lambda Target Group
4547
- **AWS DX (Direct Connect)**
4648
- Connection
4749
- Gateway
@@ -61,6 +63,7 @@ Terraform Modules from [this package](https://github.com/tedilabs/terraform-aws-
6163
- [lattice-alb-target-group](./examples/lattice-alb-target-group)
6264
- [lattice-instance-target-group](./examples/lattice-instance-target-group)
6365
- [lattice-ip-target-group](./examples/lattice-ip-target-group)
66+
- [lattice-lambda-target-group](./examples/lattice-lambda-target-group)
6467

6568
### Network Manager
6669

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def lambda_handler(event, context):
2+
print("Hello from app1!")
3+
4+
return event
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
###################################################
2+
# Lambda Function
3+
###################################################
4+
5+
module "lambda_function" {
6+
source = "terraform-aws-modules/lambda/aws"
7+
version = "~> 6.0.0"
8+
9+
publish = true
10+
11+
function_name = "lambda-function-for-vpc-lattice"
12+
source_path = "${path.root}/function/"
13+
handler = "index.lambda_handler"
14+
runtime = "python3.8"
15+
16+
tags = {
17+
"project" = "terraform-aws-vpc-connectivity-examples"
18+
}
19+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
provider "aws" {
2+
region = "us-east-1"
3+
}
4+
5+
6+
###################################################
7+
# Lambda Target Group
8+
###################################################
9+
10+
module "target_group" {
11+
source = "../../modules/lattice-lambda-target-group"
12+
# source = "tedilabs/vpc-connectivity/aws//modules/lattice-lambda-target-group"
13+
# version = "~> 0.2.0"
14+
15+
name = "lambda-hello"
16+
17+
18+
## Targets
19+
targets = [
20+
{
21+
name = "lambda-function-for-vpc-lattice"
22+
lambda_function = module.lambda_function.lambda_function_arn
23+
}
24+
]
25+
26+
27+
tags = {
28+
"project" = "terraform-aws-vpc-connectivity-examples"
29+
}
30+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "target_group" {
2+
description = "The ALB target group of VPC Lattice."
3+
value = module.target_group
4+
}
5+
6+
output "lambda_function" {
7+
description = "The Lambda function for VPC Lattice."
8+
value = module.lambda_function
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = "~> 1.5"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = "~> 5.0"
8+
}
9+
}
10+
}

modules/lattice-alb-target-group/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ This module creates following resources.
6161
| <a name="output_protocol_version"></a> [protocol\_version](#output\_protocol\_version) | The protocol version. |
6262
| <a name="output_status"></a> [status](#output\_status) | The status of the target group. |
6363
| <a name="output_targets"></a> [targets](#output\_targets) | The list of targets of the target group.<br> `name` - The name of the target. This value is only used internally within Terraform code.<br> `alb` - The Amazon Resource Name (ARN) of the target ALB (Application Load Balancer).<br> `port` - The port on which the target is listening. |
64-
| <a name="output_type"></a> [type](#output\_type) | The type of target group. Always `IP`. |
64+
| <a name="output_type"></a> [type](#output\_type) | The type of target group. Always `ALB`. |
6565
| <a name="output_vpc"></a> [vpc](#output\_vpc) | The ID of the VPC which the target group belongs to. |
6666
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/lattice-alb-target-group/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ output "vpc" {
1919
}
2020

2121
output "type" {
22-
description = "The type of target group. Always `IP`."
22+
description = "The type of target group. Always `ALB`."
2323
value = aws_vpclattice_target_group.this.type
2424
}
2525

modules/lattice-instance-target-group/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ This module creates following resources.
6363
| <a name="output_protocol_version"></a> [protocol\_version](#output\_protocol\_version) | The protocol version. |
6464
| <a name="output_status"></a> [status](#output\_status) | The status of the target group. |
6565
| <a name="output_targets"></a> [targets](#output\_targets) | The list of targets of the target group.<br> `name` - The name of the target. This value is only used internally within Terraform code.<br> `instance` - This is the Instance ID for an instance.<br> `port` - The port on which the target is listening. |
66-
| <a name="output_type"></a> [type](#output\_type) | The type of target group. Always `IP`. |
66+
| <a name="output_type"></a> [type](#output\_type) | The type of target group. Always `INSTANCE`. |
6767
| <a name="output_vpc"></a> [vpc](#output\_vpc) | The ID of the VPC which the target group belongs to. |
6868
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/lattice-instance-target-group/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ output "vpc" {
1919
}
2020

2121
output "type" {
22-
description = "The type of target group. Always `IP`."
22+
description = "The type of target group. Always `INSTANCE`."
2323
value = aws_vpclattice_target_group.this.type
2424
}
2525

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# lattice-lambda-target-group
2+
3+
This module creates following resources.
4+
5+
- `aws_vpclattice_target_group`
6+
- `aws_vpclattice_target_group_attachment` (optional)
7+
8+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
9+
## Requirements
10+
11+
| Name | Version |
12+
|------|---------|
13+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5 |
14+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.12 |
15+
16+
## Providers
17+
18+
| Name | Version |
19+
|------|---------|
20+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.17.0 |
21+
22+
## Modules
23+
24+
| Name | Source | Version |
25+
|------|--------|---------|
26+
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | tedilabs/misc/aws//modules/resource-group | ~> 0.10.0 |
27+
28+
## Resources
29+
30+
| Name | Type |
31+
|------|------|
32+
| [aws_vpclattice_target_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpclattice_target_group) | resource |
33+
| [aws_vpclattice_target_group_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpclattice_target_group_attachment) | resource |
34+
35+
## Inputs
36+
37+
| Name | Description | Type | Default | Required |
38+
|------|-------------|------|---------|:--------:|
39+
| <a name="input_name"></a> [name](#input\_name) | (Required) The name of the target group. The name must be unique within the account. The valid characters are a-z, 0-9, and hyphens (-). You can't use a hyphen as the first or last character, or immediately after another hyphen. | `string` | n/a | yes |
40+
| <a name="input_module_tags_enabled"></a> [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no |
41+
| <a name="input_resource_group_description"></a> [resource\_group\_description](#input\_resource\_group\_description) | (Optional) The description of Resource Group. | `string` | `"Managed by Terraform."` | no |
42+
| <a name="input_resource_group_enabled"></a> [resource\_group\_enabled](#input\_resource\_group\_enabled) | (Optional) Whether to create Resource Group to find and group AWS resources which are created by this module. | `bool` | `true` | no |
43+
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | (Optional) The name of Resource Group. A Resource Group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`. | `string` | `""` | no |
44+
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) A map of tags to add to all resources. | `map(string)` | `{}` | no |
45+
| <a name="input_targets"></a> [targets](#input\_targets) | (Optional) A list of targets to add to the target group. Each value of `targets` block as defined below.<br> (Required) `name` - The name of the target. This value is only used internally within Terraform code.<br> (Required) `lambda_function` - The Amazon Resource Name (ARN) of the target Lambda function. If your ARN doesn't specify a version or alias, the latest version ($LATEST) is used by default. If the ARN specifies a version or alias, it appears as the last segment of the ARN separated by a colon. | <pre>list(object({<br> name = string<br> lambda_function = string<br> }))</pre> | `[]` | no |
46+
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | (Optional) How long to wait for the target group to be created/deleted. | <pre>object({<br> create = optional(string, "5m")<br> delete = optional(string, "5m")<br> })</pre> | `{}` | no |
47+
48+
## Outputs
49+
50+
| Name | Description |
51+
|------|-------------|
52+
| <a name="output_arn"></a> [arn](#output\_arn) | The ARN of the target group. |
53+
| <a name="output_id"></a> [id](#output\_id) | The ID of the target group. |
54+
| <a name="output_name"></a> [name](#output\_name) | The name of the target group. |
55+
| <a name="output_status"></a> [status](#output\_status) | The status of the target group. |
56+
| <a name="output_targets"></a> [targets](#output\_targets) | The list of targets of the target group.<br> `name` - The name of the target. This value is only used internally within Terraform code.<br> `lambda_function` - The Amazon Resource Name (ARN) of the target Lambda function. |
57+
| <a name="output_type"></a> [type](#output\_type) | The type of target group. Always `LAMBDA`. |
58+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
locals {
2+
metadata = {
3+
package = "terraform-aws-vpc-connectivity"
4+
version = trimspace(file("${path.module}/../../VERSION"))
5+
module = basename(path.module)
6+
name = var.name
7+
}
8+
module_tags = var.module_tags_enabled ? {
9+
"module.terraform.io/package" = local.metadata.package
10+
"module.terraform.io/version" = local.metadata.version
11+
"module.terraform.io/name" = local.metadata.module
12+
"module.terraform.io/full-name" = "${local.metadata.package}/${local.metadata.module}"
13+
"module.terraform.io/instance" = local.metadata.name
14+
} : {}
15+
}
16+
17+
18+
###################################################
19+
# Lambda Target Group for VPC Lattice Service
20+
###################################################
21+
22+
# INFO: Not supported attributes
23+
# - `config`
24+
resource "aws_vpclattice_target_group" "this" {
25+
name = var.name
26+
type = "LAMBDA"
27+
28+
timeouts {
29+
create = var.timeouts.create
30+
delete = var.timeouts.delete
31+
}
32+
33+
tags = merge(
34+
{
35+
"Name" = local.metadata.name
36+
},
37+
local.module_tags,
38+
var.tags,
39+
)
40+
}
41+
42+
43+
###################################################
44+
# Targets for Lambda Target Group
45+
###################################################
46+
47+
# INFO: Not supported attributes
48+
# - `target.port`
49+
resource "aws_vpclattice_target_group_attachment" "this" {
50+
for_each = {
51+
for target in var.targets :
52+
target.name => target
53+
}
54+
55+
target_group_identifier = aws_vpclattice_target_group.this.id
56+
57+
target {
58+
id = each.value.lambda_function
59+
}
60+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
output "id" {
2+
description = "The ID of the target group."
3+
value = aws_vpclattice_target_group.this.id
4+
}
5+
6+
output "arn" {
7+
description = "The ARN of the target group."
8+
value = aws_vpclattice_target_group.this.arn
9+
}
10+
11+
output "name" {
12+
description = "The name of the target group."
13+
value = aws_vpclattice_target_group.this.name
14+
}
15+
16+
output "type" {
17+
description = "The type of target group. Always `LAMBDA`."
18+
value = aws_vpclattice_target_group.this.type
19+
}
20+
21+
output "status" {
22+
description = "The status of the target group."
23+
value = aws_vpclattice_target_group.this.status
24+
}
25+
26+
output "targets" {
27+
description = <<EOF
28+
The list of targets of the target group.
29+
`name` - The name of the target. This value is only used internally within Terraform code.
30+
`lambda_function` - The Amazon Resource Name (ARN) of the target Lambda function.
31+
EOF
32+
value = {
33+
for name, target in aws_vpclattice_target_group_attachment.this :
34+
name => {
35+
name = name
36+
lambda_function = one(target.target[*].id)
37+
}
38+
}
39+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
locals {
2+
resource_group_name = (var.resource_group_name != ""
3+
? var.resource_group_name
4+
: join(".", [
5+
local.metadata.package,
6+
local.metadata.module,
7+
replace(local.metadata.name, "/[^a-zA-Z0-9_\\.-]/", "-"),
8+
])
9+
)
10+
}
11+
12+
13+
module "resource_group" {
14+
source = "tedilabs/misc/aws//modules/resource-group"
15+
version = "~> 0.10.0"
16+
17+
count = (var.resource_group_enabled && var.module_tags_enabled) ? 1 : 0
18+
19+
name = local.resource_group_name
20+
description = var.resource_group_description
21+
22+
query = {
23+
resource_tags = local.module_tags
24+
}
25+
26+
module_tags_enabled = false
27+
tags = merge(
28+
local.module_tags,
29+
var.tags,
30+
)
31+
}

0 commit comments

Comments
 (0)