-
-
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.
- Loading branch information
Showing
18 changed files
with
357 additions
and
4 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
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,4 @@ | ||
def lambda_handler(event, context): | ||
print("Hello from app1!") | ||
|
||
return event |
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,19 @@ | ||
################################################### | ||
# Lambda Function | ||
################################################### | ||
|
||
module "lambda_function" { | ||
source = "terraform-aws-modules/lambda/aws" | ||
version = "~> 6.0.0" | ||
|
||
publish = true | ||
|
||
function_name = "lambda-function-for-vpc-lattice" | ||
source_path = "${path.root}/function/" | ||
handler = "index.lambda_handler" | ||
runtime = "python3.8" | ||
|
||
tags = { | ||
"project" = "terraform-aws-vpc-connectivity-examples" | ||
} | ||
} |
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 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
|
||
################################################### | ||
# Lambda Target Group | ||
################################################### | ||
|
||
module "target_group" { | ||
source = "../../modules/lattice-lambda-target-group" | ||
# source = "tedilabs/vpc-connectivity/aws//modules/lattice-lambda-target-group" | ||
# version = "~> 0.2.0" | ||
|
||
name = "lambda-hello" | ||
|
||
|
||
## Targets | ||
targets = [ | ||
{ | ||
name = "lambda-function-for-vpc-lattice" | ||
lambda_function = module.lambda_function.lambda_function_arn | ||
} | ||
] | ||
|
||
|
||
tags = { | ||
"project" = "terraform-aws-vpc-connectivity-examples" | ||
} | ||
} |
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,9 @@ | ||
output "target_group" { | ||
description = "The ALB target group of VPC Lattice." | ||
value = module.target_group | ||
} | ||
|
||
output "lambda_function" { | ||
description = "The Lambda function for VPC Lattice." | ||
value = module.lambda_function | ||
} |
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,10 @@ | ||
terraform { | ||
required_version = "~> 1.5" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.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
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
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,58 @@ | ||
# lattice-lambda-target-group | ||
|
||
This module creates following resources. | ||
|
||
- `aws_vpclattice_target_group` | ||
- `aws_vpclattice_target_group_attachment` (optional) | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.12 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.17.0 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | tedilabs/misc/aws//modules/resource-group | ~> 0.10.0 | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_vpclattice_target_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpclattice_target_group) | resource | | ||
| [aws_vpclattice_target_group_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpclattice_target_group_attachment) | resource | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <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 | | ||
| <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 | | ||
| <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 | | ||
| <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 | | ||
| <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 | | ||
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) A map of tags to add to all resources. | `map(string)` | `{}` | no | | ||
| <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 | | ||
| <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 | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_arn"></a> [arn](#output\_arn) | The ARN of the target group. | | ||
| <a name="output_id"></a> [id](#output\_id) | The ID of the target group. | | ||
| <a name="output_name"></a> [name](#output\_name) | The name of the target group. | | ||
| <a name="output_status"></a> [status](#output\_status) | The status of the target group. | | ||
| <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. | | ||
| <a name="output_type"></a> [type](#output\_type) | The type of target group. Always `LAMBDA`. | | ||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
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,60 @@ | ||
locals { | ||
metadata = { | ||
package = "terraform-aws-vpc-connectivity" | ||
version = trimspace(file("${path.module}/../../VERSION")) | ||
module = basename(path.module) | ||
name = var.name | ||
} | ||
module_tags = var.module_tags_enabled ? { | ||
"module.terraform.io/package" = local.metadata.package | ||
"module.terraform.io/version" = local.metadata.version | ||
"module.terraform.io/name" = local.metadata.module | ||
"module.terraform.io/full-name" = "${local.metadata.package}/${local.metadata.module}" | ||
"module.terraform.io/instance" = local.metadata.name | ||
} : {} | ||
} | ||
|
||
|
||
################################################### | ||
# Lambda Target Group for VPC Lattice Service | ||
################################################### | ||
|
||
# INFO: Not supported attributes | ||
# - `config` | ||
resource "aws_vpclattice_target_group" "this" { | ||
name = var.name | ||
type = "LAMBDA" | ||
|
||
timeouts { | ||
create = var.timeouts.create | ||
delete = var.timeouts.delete | ||
} | ||
|
||
tags = merge( | ||
{ | ||
"Name" = local.metadata.name | ||
}, | ||
local.module_tags, | ||
var.tags, | ||
) | ||
} | ||
|
||
|
||
################################################### | ||
# Targets for Lambda Target Group | ||
################################################### | ||
|
||
# INFO: Not supported attributes | ||
# - `target.port` | ||
resource "aws_vpclattice_target_group_attachment" "this" { | ||
for_each = { | ||
for target in var.targets : | ||
target.name => target | ||
} | ||
|
||
target_group_identifier = aws_vpclattice_target_group.this.id | ||
|
||
target { | ||
id = each.value.lambda_function | ||
} | ||
} |
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,39 @@ | ||
output "id" { | ||
description = "The ID of the target group." | ||
value = aws_vpclattice_target_group.this.id | ||
} | ||
|
||
output "arn" { | ||
description = "The ARN of the target group." | ||
value = aws_vpclattice_target_group.this.arn | ||
} | ||
|
||
output "name" { | ||
description = "The name of the target group." | ||
value = aws_vpclattice_target_group.this.name | ||
} | ||
|
||
output "type" { | ||
description = "The type of target group. Always `LAMBDA`." | ||
value = aws_vpclattice_target_group.this.type | ||
} | ||
|
||
output "status" { | ||
description = "The status of the target group." | ||
value = aws_vpclattice_target_group.this.status | ||
} | ||
|
||
output "targets" { | ||
description = <<EOF | ||
The list of targets of the target group. | ||
`name` - The name of the target. This value is only used internally within Terraform code. | ||
`lambda_function` - The Amazon Resource Name (ARN) of the target Lambda function. | ||
EOF | ||
value = { | ||
for name, target in aws_vpclattice_target_group_attachment.this : | ||
name => { | ||
name = name | ||
lambda_function = one(target.target[*].id) | ||
} | ||
} | ||
} |
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,31 @@ | ||
locals { | ||
resource_group_name = (var.resource_group_name != "" | ||
? var.resource_group_name | ||
: join(".", [ | ||
local.metadata.package, | ||
local.metadata.module, | ||
replace(local.metadata.name, "/[^a-zA-Z0-9_\\.-]/", "-"), | ||
]) | ||
) | ||
} | ||
|
||
|
||
module "resource_group" { | ||
source = "tedilabs/misc/aws//modules/resource-group" | ||
version = "~> 0.10.0" | ||
|
||
count = (var.resource_group_enabled && var.module_tags_enabled) ? 1 : 0 | ||
|
||
name = local.resource_group_name | ||
description = var.resource_group_description | ||
|
||
query = { | ||
resource_tags = local.module_tags | ||
} | ||
|
||
module_tags_enabled = false | ||
tags = merge( | ||
local.module_tags, | ||
var.tags, | ||
) | ||
} |
Oops, something went wrong.