Skip to content

Commit

Permalink
Merge pull request #55 from pablo19sc/main
Browse files Browse the repository at this point in the history
Updating Lambda configuration
  • Loading branch information
pablo19sc authored May 20, 2024
2 parents 50e177a + 8dd0721 commit 376eb2a
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 145 deletions.
50 changes: 23 additions & 27 deletions .header.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ You can create more than 1 Target Groups with this module, as this variable expe

The `config` attribute *- map(any) -* supports the following:

- `port` = (number) Port on which the targets are listening.
- `protocol` = (string) Protocol to use for routing traffic to the targets. Valid values: `HTTP` and `HTTPS`.
- `vpc_identifier` = (string) VPC ID.
- `ip_address_type` = (Optional|string) IP address type for the target group. Valid values: `IPV4` and `IPV6`. If type is set to `ALB`, this parameter should not be specified.
- `protocol_version` = (Optional|string) Protocol version. Valid values: `HTTP1` (default), `HTTP2`, `GRPC`.
- `port` = (number) Port on which the targets are listening. Not supported if type is set to `LAMBDA`.
- `protocol` = (string) Protocol to use for routing traffic to the targets. Valid values: `HTTP` and `HTTPS`. Not supported if type is set to `LAMBDA`.
- `vpc_identifier` = (string) VPC ID. Not supported if type is set to `LAMBDA`.
- `ip_address_type` = (Optional|string) IP address type for the target group. Valid values: `IPV4` and `IPV6`. Not supported if type is set to `LAMBDA` or `ALB`.
- `protocol_version` = (Optional|string) Protocol version. Valid values: `HTTP1` (default), `HTTP2`, `GRPC`. Not supported if type is set to `LAMBDA`.
- `lambda_event_structure_version` = (Optional|string) The version of the event structure that the Lambda function receives. Valid values: `V1`and `V2` (default). Supported only if type is set to `LAMBDA`.

The `health_check` attribute *- map(any) -* supports the following:

Expand All @@ -124,33 +125,15 @@ The `targets` attribute *- map(any) -* supports the following:
- `id` = (Required|string) The ID of the target. If the target type of the target group is INSTANCE, this is an instance ID. If the target type is IP , this is an IP address. If the target type is LAMBDA, this is the ARN of the Lambda function. If the target type is ALB, this is the ARN of the Application Load Balancer.
- `port` = (Optional|number) The port on which the target is listening. For HTTP, the default is 80. For HTTPS, the default is 443. Attribute not needed with target type of `LAMBDA`.

Example of a `LAMBDA` type target group:
Example of an `LAMBDA` and `IP` type target groups:

```hcl
target_groups = {
lambdatarget = {
name = "lambdatarget"
type = "LAMBDA"
}
}
```

Example of an `INSTANCE` and `IP` type target groups (without health checks): **(TO ADD TARGETS WHEN AVAILABLE)**

```hcl
target_groups = {
instancetarget = {
type = "INSTANCE"
config = {
port = 80
protocol = "HTTP"
vpc_identifier = "vpc-XXX"
ip_address_type = "IPV4"
}
health_check = {
enabled = false
targets = {
mylambda = { id = aws_lambda_function.lambda.arn }
}
targets = {}
}
iptarget = {
Expand All @@ -164,7 +147,20 @@ target_groups = {
health_check = {
enabled = false
}
targets = {}
targets = {
ip1 = {
id = "10.0.0.10"
port = 80
}
ip2 = {
id = "10.0.0.20"
port = 80
}
ip3 = {
id = "10.0.0.30"
port = 80
}
}
}
}
```
Expand Down
50 changes: 23 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ You can create more than 1 Target Groups with this module, as this variable expe

The `config` attribute *- map(any) -* supports the following:

- `port` = (number) Port on which the targets are listening.
- `protocol` = (string) Protocol to use for routing traffic to the targets. Valid values: `HTTP` and `HTTPS`.
- `vpc_identifier` = (string) VPC ID.
- `ip_address_type` = (Optional|string) IP address type for the target group. Valid values: `IPV4` and `IPV6`. If type is set to `ALB`, this parameter should not be specified.
- `protocol_version` = (Optional|string) Protocol version. Valid values: `HTTP1` (default), `HTTP2`, `GRPC`.
- `port` = (number) Port on which the targets are listening. Not supported if type is set to `LAMBDA`.
- `protocol` = (string) Protocol to use for routing traffic to the targets. Valid values: `HTTP` and `HTTPS`. Not supported if type is set to `LAMBDA`.
- `vpc_identifier` = (string) VPC ID. Not supported if type is set to `LAMBDA`.
- `ip_address_type` = (Optional|string) IP address type for the target group. Valid values: `IPV4` and `IPV6`. Not supported if type is set to `LAMBDA` or `ALB`.
- `protocol_version` = (Optional|string) Protocol version. Valid values: `HTTP1` (default), `HTTP2`, `GRPC`. Not supported if type is set to `LAMBDA`.
- `lambda_event_structure_version` = (Optional|string) The version of the event structure that the Lambda function receives. Valid values: `V1`and `V2` (default). Supported only if type is set to `LAMBDA`.

The `health_check` attribute *- map(any) -* supports the following:

Expand All @@ -125,33 +126,15 @@ The `targets` attribute *- map(any) -* supports the following:
- `id` = (Required|string) The ID of the target. If the target type of the target group is INSTANCE, this is an instance ID. If the target type is IP , this is an IP address. If the target type is LAMBDA, this is the ARN of the Lambda function. If the target type is ALB, this is the ARN of the Application Load Balancer.
- `port` = (Optional|number) The port on which the target is listening. For HTTP, the default is 80. For HTTPS, the default is 443. Attribute not needed with target type of `LAMBDA`.

Example of a `LAMBDA` type target group:
Example of an `LAMBDA` and `IP` type target groups:

```hcl
target_groups = {
lambdatarget = {
name = "lambdatarget"
type = "LAMBDA"
}
}
```

Example of an `INSTANCE` and `IP` type target groups (without health checks): **(TO ADD TARGETS WHEN AVAILABLE)**

```hcl
target_groups = {
instancetarget = {
type = "INSTANCE"
config = {
port = 80
protocol = "HTTP"
vpc_identifier = "vpc-XXX"
ip_address_type = "IPV4"
}
health_check = {
enabled = false
targets = {
mylambda = { id = aws_lambda_function.lambda.arn }
}
targets = {}
}
iptarget = {
Expand All @@ -165,7 +148,20 @@ target_groups = {
health_check = {
enabled = false
}
targets = {}
targets = {
ip1 = {
id = "10.0.0.10"
port = 80
}
ip2 = {
id = "10.0.0.20"
port = 80
}
ip3 = {
id = "10.0.0.30"
port = 80
}
}
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.0.0
v0.1.0
11 changes: 8 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ resource "aws_vpclattice_target_group" "lambda_lattice_target_group" {
name = try(each.value.name, each.key)
type = each.value.type

config {
lambda_event_structure_version = try(each.value.config.lambda_event_structure_version, "V2")
}

tags = module.tags.tags_aws
}

Expand Down Expand Up @@ -134,13 +138,14 @@ resource "aws_vpclattice_target_group" "lattice_target_group" {
# VPC Lattice Targets
module "targets" {
for_each = {
for k, v in var.target_groups : k => v.targets
for k, v in var.target_groups : k => v
if contains(keys(v), "targets")
}
source = "./modules/targets"

target_group_identifier = try(aws_vpclattice_target_group.lambda_lattice_target_group[each.key].id, aws_vpclattice_target_group.lattice_target_group[each.key].id)
targets = each.value
target_type = each.value.type
target_group_identifier = try(aws_vpclattice_target_group.lambda_lattice_target_group[each.key].arn, aws_vpclattice_target_group.lattice_target_group[each.key].arn)
targets = each.value.targets
}

# ---------- LISTENERS AND RULES ----------
Expand Down
14 changes: 14 additions & 0 deletions modules/targets/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,18 @@ resource "aws_vpclattice_target_group_attachment" "target_attachment" {
id = try(each.value.id, null)
port = try(each.value.port, null)
}
}

# AWS Lambda permission (only if LAMDBA type)
resource "aws_lambda_permission" "lambda_target_vpclattice" {
for_each = {
for k, v in var.targets : k => v
if var.target_type == "LAMBDA"
}

statement_id = "AllowExecutionFromVpcLattice"
action = "lambda:InvokeFunction"
function_name = split(":", each.value.id)[6]
principal = "vpc-lattice.amazonaws.com"
source_arn = var.target_group_identifier
}
5 changes: 5 additions & 0 deletions modules/targets/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# --- modules/targets/variables.tf ---

variable "target_type" {
type = string
description = "Target type."
}

variable "target_group_identifier" {
type = string
description = "Target group identifier."
Expand Down
17 changes: 0 additions & 17 deletions test/examples_service_association_test.go

This file was deleted.

17 changes: 0 additions & 17 deletions test/examples_service_network_test.go

This file was deleted.

17 changes: 0 additions & 17 deletions test/examples_service_test.go

This file was deleted.

17 changes: 0 additions & 17 deletions test/examples_target_groups_test.go

This file was deleted.

17 changes: 0 additions & 17 deletions test/examples_vpc_associations_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions tests/01_mandatory.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
run "mandatory_plan_basic" {
command = plan
module {
source = "./examples/service"
source = "./examples/service_network"
}
}

run "mandatory_apply_basic" {
command = apply
module {
source = "./examples/service"
source = "./examples/service_network"
}
}
14 changes: 14 additions & 0 deletions tests/02_service.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

run "plan_service" {
command = plan
module {
source = "./examples/service"
}
}

run "apply_service" {
command = apply
module {
source = "./examples/service"
}
}
14 changes: 14 additions & 0 deletions tests/03_service_association
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

run "plan_service_association" {
command = plan
module {
source = "./examples/service_association"
}
}

run "apply_service_association" {
command = apply
module {
source = "./examples/service_association"
}
}
14 changes: 14 additions & 0 deletions tests/04_target_groups
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

run "plan_target_groups" {
command = plan
module {
source = "./examples/target_groups"
}
}

run "apply_target_groups" {
command = apply
module {
source = "./examples/target_groups"
}
}
14 changes: 14 additions & 0 deletions tests/05_vpc_associations
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

run "plan_vpc_associations" {
command = plan
module {
source = "./examples/vpc_associations"
}
}

run "apply_vpc_associations" {
command = apply
module {
source = "./examples/vpc_associations"
}
}

0 comments on commit 376eb2a

Please sign in to comment.