Skip to content

Commit

Permalink
Added vpc config and route variables (#10)
Browse files Browse the repository at this point in the history
<!-- markdownlint-disable-next-line first-line-heading -->
## Description
This pr adds vpc config and route variables to the module to allow for
more fine grained control of the underlying resources.
Now the lamdba can be added to a vpc and the api gateway can have a
different default route and HTTP method.
<!-- Describe your changes in detail. -->

## Context

<!-- Why is this change required? What problem does it solve? -->

## Type of changes

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply. -->

- [ ] Refactoring (non-breaking change)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would change existing
functionality)
- [ ] Bug fix (non-breaking change which fixes an issue)

## Checklist

<!-- Go over all the following points, and put an `x` in all the boxes
that apply. -->

- [ ] I am familiar with the [contributing
guidelines](../docs/CONTRIBUTING.md)
- [ ] I have followed the code style of the project
- [ ] I have added tests to cover my changes
- [ ] I have updated the documentation accordingly
- [ ] This PR is a result of pair or mob programming

---

## Sensitive Information Declaration

To ensure the utmost confidentiality and protect your and others
privacy, we kindly ask you to NOT including [PII (Personal Identifiable
Information) / PID (Personal Identifiable
Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public)
or any other sensitive data in this PR (Pull Request) and the codebase
changes. We will remove any PR that do contain any sensitive
information. We really appreciate your cooperation in this matter.

- [ ] I confirm that neither PII/PID nor sensitive data are included in
this PR and the codebase changes.
  • Loading branch information
amaanibn-nasar1-nhs authored Oct 18, 2024
1 parent 8b4c0ec commit f2c739e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
11 changes: 10 additions & 1 deletion terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ resource "aws_lambda_function" "get_method_lambda" {
variables = var.lambda_environment_variables
}
}

dynamic "vpc_config" {
for_each = length(keys(var.lambda_vpc_config)) == 0 ? [] : [true]
content {
subnet_ids = var.lambda_vpc_config.subnet_ids
security_group_ids = var.lambda_vpc_config.security_group_ids
}
}

}

resource "aws_cloudwatch_log_group" "get_method_lambda_log_group" {
Expand All @@ -59,7 +68,7 @@ resource "aws_apigatewayv2_integration" "get_method_lambda_integration" {

resource "aws_apigatewayv2_route" "get_method_route" {
api_id = aws_apigatewayv2_api.get_method_api.id
route_key = "GET /"
route_key = "${var.api_route_method} ${var.api_route_path}"
target = "integrations/${aws_apigatewayv2_integration.get_method_lambda_integration.id}"
}

Expand Down
25 changes: 25 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,28 @@ variable "log_retention_days" {
description = "The number of days to retain log events in the CloudWatch Logs Log Group."
default = 14
}

variable "lambda_vpc_config" {
description = "VPC configuration for the Lambda function."
type = object({
security_group_ids = list(string)
subnet_ids = list(string)
})
default = {
security_group_ids = []
subnet_ids = []
}
}

variable "api_route_method" {
description = "The route method for the API Gateway."
type = string
default = "GET"
}

variable "api_route_path" {
description = "The path for the API Gateway."
type = string
default = "/"

}

0 comments on commit f2c739e

Please sign in to comment.