Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0b39287
eli-204 adding api-gateway module
eddalmond1 May 1, 2025
6109493
eli-204 adding api gateway to api layer stack, and added a simple moc…
eddalmond1 May 2, 2025
670e2ed
eli-204 adding _status method for healthcheck
eddalmond1 May 2, 2025
095dd8f
eli-204 adding main GET method and deployment stages for API gateway
eddalmond1 May 2, 2025
6c8f0db
eli-204 removing dupe policy, adding prevent_destroy
eddalmond1 May 2, 2025
4870804
eli-204 removing stack interdependency
eddalmond1 May 2, 2025
2409dfb
Merge branch 'main' into feature/eja-eli-204-add-api-gateway
eddalmond1 May 2, 2025
5c0243a
Merge branch 'main' into feature/eja-eli-204-add-api-gateway
eddalmond1 May 13, 2025
efe5f47
eli-204 adding mTLS + domain verification mechanisms plus lambda inte…
eddalmond1 May 15, 2025
6a065ae
eli-204 linting
eddalmond1 May 15, 2025
1af770b
Merge branch 'main' into feature/eja-eli-204-add-api-gateway
eddalmond1 May 15, 2025
274efbb
Merge branch 'main' into feature/eja-eli-204-add-api-gateway
eddalmond1 May 20, 2025
da0e0e0
eli-204 updating readme
eddalmond1 May 21, 2025
4c12e0c
eli-204 further additions to readme, to detail saving certificates
eddalmond1 May 21, 2025
c2559c0
eli-204 further documenting how to deal with mTLS certificates
eddalmond1 May 21, 2025
f61b994
Merge branch 'main' into feature/eja-eli-204-add-api-gateway
eddalmond1 May 21, 2025
dda63e0
eli-204 tidying up readme for networking layer
eddalmond1 May 21, 2025
aa0841b
eli-204 updating readme with a pointer to the specification repo
eddalmond1 May 22, 2025
bb824d9
eli-204 changes made responding to issues during deployment
eddalmond1 May 27, 2025
6370d35
Merge branch 'main' into feature/eja-eli-204-add-api-gateway
eddalmond1 May 27, 2025
963395c
adding in workflow
eddalmond1 May 28, 2025
255d0c2
bugfix
eddalmond1 May 28, 2025
d7389ac
eli-204 adding more base permissions
eddalmond1 May 29, 2025
c68bd6f
eli-204 changing stack name in locals for iams-developer-roles
eddalmond1 May 29, 2025
4923a2d
eli-204 finessing permissions and boundary permissions
eddalmond1 May 29, 2025
71033eb
eli-204 amending permissions boundary assignment
eddalmond1 May 29, 2025
2f2d6bb
eli-204 more permissions
eddalmond1 May 29, 2025
2128802
eli-204 hardocding kms key alias
eddalmond1 May 29, 2025
d229049
eli-204 adding explicit decryption
eddalmond1 May 29, 2025
b64dd92
eli-204 adding kms decrypt permissions
eddalmond1 May 29, 2025
e7d7114
eli-204 removing unneeded comment
eddalmond1 May 29, 2025
b62244d
Merge branch 'main' into feature/eja-eli-204-add-api-gateway
eddalmond1 May 29, 2025
2658871
eli-204 updating networking build
eddalmond1 May 29, 2025
5bae5fd
eli-204 adding permission for ssm
eddalmond1 May 29, 2025
682bfa1
eli-204 changing test job to terraform plan
eddalmond1 May 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions .github/workflows/github-oidc-test.yaml

This file was deleted.

71 changes: 71 additions & 0 deletions .github/workflows/manual-terraform-plan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Github OIDC test

on:
workflow_dispatch:
inputs:
environment:
description: Target environment
required: true
type: choice
options: [dev, test, preprod]

jobs:
plan-stacks:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
permissions:
id-token: write
contents: read

steps:
- name: "Setup Terraform"
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ vars.TF_VERSION }}

- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: '3.13'

- name: "Checkout Repository"
uses: actions/checkout@v4

- name: "Build lambda artefact"
run: |
make dependencies install-python
make build
- name: "Upload lambda artefact"
uses: actions/upload-artifact@v4
with:
name: lambda
path: dist/lambda.zip

- name: "Download Built Lambdas"
uses: actions/download-artifact@v4
with:
name: lambda
path: ./build

- name: "Configure AWS Credentials"
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/service-roles/github-actions-api-deployment-role
aws-region: eu-west-2

- name: "Terraform Plan Stacks"
env:
ENVIRONMENT: "dev"
WORKSPACE: "default"
TF_VAR_API_CA_CERT: ${{ secrets.API_CA_CERT }}
TF_VAR_API_CLIENT_CERT: ${{ secrets.API_CLIENT_CERT }}
TF_VAR_API_PRIVATE_KEY_CERT: ${{ secrets.API_PRIVATE_KEY_CERT }}

run: |
mkdir -p ./build
echo "Running: make terraform env=$ENVIRONMENT workspace=$ENVIRONMENT stack=networking tf-command=plan args=\"-auto-approve\""
make terraform env=$ENVIRONMENT stack=networking tf-command=plan workspace=$ENVIRONMENT
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=api-layer tf-command=plan args=\"-auto-approve\""
make terraform env=$ENVIRONMENT stack=api-layer tf-command=plan workspace=$WORKSPACE

working-directory: ./infrastructure
19 changes: 16 additions & 3 deletions infrastructure/modules/_shared/default_variables.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
# tflint-ignore: terraform_unused_declarations
variable "project_name" {
default = "eligibility-signposting-api"
type = string
}

# tflint-ignore: terraform_unused_declarations
variable "environment" {
description = "The purpose of the account dev/test/ref/prod or the workspace"
type = string
}

# tflint-ignore: terraform_unused_declarations
variable "tags" {
description = "A map of tags to assign to resources."
type = map(string)
default = {}
}

variable "workspace" {
description = "Usually the developer short code or the name of the environment."
type = string
}

variable "stack_name" {
description = "The name of the stack being deployed"
type = string
}

variable "region" {
type = string
description = "The aws region."
default = "eu-west-2"
}
18 changes: 18 additions & 0 deletions infrastructure/modules/api_gateway/api_gateway.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "aws_api_gateway_rest_api" "api_gateway" {
name = var.workspace == "default" ? "${var.api_gateway_name}-rest-api" : "${var.workspace}-${var.api_gateway_name}-rest-api"
description = "The API Gateway for ${var.project_name} ${var.environment} environment"

disable_execute_api_endpoint = var.disable_default_endpoint # We would want to disable this if we are using a custom domain name

lifecycle {
create_before_destroy = true
}

tags = {
Stack = var.stack_name
}
}

resource "aws_api_gateway_account" "api_gateway" {
cloudwatch_role_arn = aws_iam_role.api_gateway.arn
}
10 changes: 10 additions & 0 deletions infrastructure/modules/api_gateway/cloudwatch.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "aws_cloudwatch_log_group" "api_gateway" {
name = "/aws/apigateway/${var.workspace}-${var.api_gateway_name}"
retention_in_days = 14
tags = var.tags
kms_key_id = aws_kms_key.api_gateway.arn

lifecycle {
prevent_destroy = false
}
}
1 change: 1 addition & 0 deletions infrastructure/modules/api_gateway/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "aws_caller_identity" "current" {}
1 change: 1 addition & 0 deletions infrastructure/modules/api_gateway/default_variables.tf
43 changes: 43 additions & 0 deletions infrastructure/modules/api_gateway/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["apigateway.amazonaws.com"]
}
}
}

resource "aws_iam_role" "api_gateway" {
name = "${var.workspace}-${var.api_gateway_name}-role"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
}

data "aws_iam_policy_document" "api_gateway_logging" {
statement {
sid = "AllowCloudWatchLogging"
effect = "Allow"
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:PutLogEvents",
"logs:GetLogEvents",
"logs:FilterLogEvents"
]
resources = ["*"]
}
}

resource "aws_iam_policy" "api_gateway_logging" {
name = "${var.workspace}-${var.api_gateway_name}-api-gateway-logging-policy"
description = "Policy to allow API Gateway push logs to Cloudwatch"
policy = data.aws_iam_policy_document.api_gateway_logging.json
}

resource "aws_iam_role_policy_attachment" "api_gateway_logging" {
role = aws_iam_role.api_gateway.name
policy_arn = aws_iam_policy.api_gateway_logging.arn
}
48 changes: 48 additions & 0 deletions infrastructure/modules/api_gateway/kms.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
resource "aws_kms_key" "api_gateway" {
description = "${var.workspace} - KMS Key for ${var.api_gateway_name} API Gateway"
deletion_window_in_days = 14
enable_key_rotation = true

tags = {
Stack = var.stack_name
}
}

resource "aws_kms_alias" "api_gateway" {
name = "alias/${var.workspace}-${var.api_gateway_name}-cloudwatch-logs"
target_key_id = aws_kms_key.api_gateway.key_id
}

resource "aws_kms_key_policy" "api_gateway" {
key_id = aws_kms_key.api_gateway.id
policy = data.aws_iam_policy_document.api_gateway.json
}

data "aws_iam_policy_document" "api_gateway" {
statement {
sid = "Enable IAM User Permissions for ${var.api_gateway_name} API Gateway"
effect = "Allow"
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
}
actions = ["kms:*"]
resources = [aws_kms_key.api_gateway.arn]
}
statement {
sid = "APIGatewayCloudwatchKMSAccess"
effect = "Allow"
principals {
type = "Service"
identifiers = ["logs.${var.region}.amazonaws.com"]
}
actions = [
"kms:Encrypt*",
"kms:Decrypt*",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:Describe*"
]
resources = [aws_kms_key.api_gateway.arn]
}
}
27 changes: 27 additions & 0 deletions infrastructure/modules/api_gateway/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
output "rest_api_id" {
value = aws_api_gateway_rest_api.api_gateway.id
}

output "root_resource_id" {
value = aws_api_gateway_rest_api.api_gateway.root_resource_id
}

output "execution_arn" {
value = aws_api_gateway_rest_api.api_gateway.execution_arn
}

output "cloudwatch_destination_arn" {
value = aws_cloudwatch_log_group.api_gateway.arn
}

output "api_gateway_account" {
value = aws_api_gateway_account.api_gateway
}

output "logging_policy_attachment" {
value = aws_iam_role_policy_attachment.api_gateway_logging
}

output "iam_role_name" {
value = aws_iam_role.api_gateway.name
}
10 changes: 10 additions & 0 deletions infrastructure/modules/api_gateway/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.11.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.6, != 5.71.0"
}
}
}
9 changes: 9 additions & 0 deletions infrastructure/modules/api_gateway/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "api_gateway_name" {
type = string
description = "The name of the API Gateway"
}

variable "disable_default_endpoint" {
type = bool
description = "Indicates whether the default endpoint the API Gateway generates should be disabled. If true, the API will need to be called from a Custom Domain Name"
}
8 changes: 8 additions & 0 deletions infrastructure/modules/lambda/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ output "aws_lambda_function_id" {
output "aws_lambda_function_arn" {
value = aws_lambda_function.eligibility_signposting_lambda.arn
}

output "aws_lambda_function_name" {
value = aws_lambda_function.eligibility_signposting_lambda.function_name
}

output "aws_lambda_invoke_arn" {
value = aws_lambda_function.eligibility_signposting_lambda.invoke_arn
}
6 changes: 0 additions & 6 deletions infrastructure/modules/lambda/variables.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
variable "workspace" {
description = "Usually the developer short code or the name of the environment."
type = string
}

variable "eligibility_lambda_role_arn" {
description = "lambda read role arn for dynamodb"
type = string
Expand Down Expand Up @@ -42,4 +37,3 @@ variable "eligibility_status_table_name" {
description = "eligibility datastore table name"
type = string
}

4 changes: 4 additions & 0 deletions infrastructure/modules/s3/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ output "storage_bucket_arn" {
output "storage_bucket_name" {
value = aws_s3_bucket.storage_bucket.bucket
}

output "storage_bucket_id" {
value = aws_s3_bucket.storage_bucket.id
}
Loading
Loading