diff --git a/.github/workflows/deploy_terraform.yml b/.github/workflows/deploy_terraform.yml index c6937f7a..728292ed 100644 --- a/.github/workflows/deploy_terraform.yml +++ b/.github/workflows/deploy_terraform.yml @@ -80,10 +80,10 @@ jobs: run: terraform plan -var-file=${STAGE}.tfvars -out=tfplan - name: Terraform Apply - if: env.STAGE == 'prod' + if: env.TERRAFORM_APPLY == 'true' working-directory: infrastructure/terraform/shared run: terraform apply -auto-approve tfplan - + # ============================================================ # 2️⃣ Build Address 2 UPRN image and Push # ============================================================ diff --git a/infrastructure/terraform/lambda/_template/README.md b/infrastructure/terraform/lambda/_template/README.md index a7282fc9..5bb10627 100644 --- a/infrastructure/terraform/lambda/_template/README.md +++ b/infrastructure/terraform/lambda/_template/README.md @@ -3,7 +3,7 @@ ### 1. Create the Lambda scaffold - Copy the template: - cp -r lambda/_template lambda/ + `cp -r lambda/_template lambda/` --- @@ -12,8 +12,7 @@ infrastructure/terraform/shared/main.tf -- Apply the shared stack - - This requires commenting 'if env.stage == "prod"' in .github/workflows/deploy_terraform.yml +- Create a PR to deploy this to main then dev in order to deploy the shared stack - Verify the ECR repository exists in AWS diff --git a/infrastructure/terraform/lambda/categorisation/main.tf b/infrastructure/terraform/lambda/categorisation/main.tf new file mode 100644 index 00000000..a402a386 --- /dev/null +++ b/infrastructure/terraform/lambda/categorisation/main.tf @@ -0,0 +1,27 @@ +data "terraform_remote_state" "shared" { + backend = "s3" + config = { + bucket = "assessment-model-terraform-state" + key = "env:/${var.stage}/terraform.tfstate" + region = "eu-west-2" + } +} + +module "lambda" { + source = "../modules/lambda_with_sqs" + + name = "categorisation" + stage = var.stage + + image_uri = local.image_uri + + + environment = merge( + { + STAGE = var.stage + LOG_LEVEL = "info" + DB_USERNAME = local.db_credentials.db_assessment_model_username + DB_PASSWORD = local.db_credentials.db_assessment_model_password + } + ) +} \ No newline at end of file diff --git a/infrastructure/terraform/lambda/categorisation/provider.tf b/infrastructure/terraform/lambda/categorisation/provider.tf new file mode 100644 index 00000000..f983533d --- /dev/null +++ b/infrastructure/terraform/lambda/categorisation/provider.tf @@ -0,0 +1,16 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 4.16" + } + } + + backend "s3" { + bucket = "categorisation" + key = "terraform.tfstate" + region = "eu-west-2" + } + + required_version = ">= 1.2.0" +} \ No newline at end of file diff --git a/infrastructure/terraform/lambda/categorisation/variables.tf b/infrastructure/terraform/lambda/categorisation/variables.tf new file mode 100644 index 00000000..e4bab243 --- /dev/null +++ b/infrastructure/terraform/lambda/categorisation/variables.tf @@ -0,0 +1,27 @@ +variable "lambda_name" { + type = string + description = "Logical name of the lambda (e.g. address2uprn)" +} + +variable "stage" { + description = "Deployment stage (e.g. dev, prod)" + type = string +} +variable "ecr_repo_url" { + type = string + description = "ECR repository URL (no tag, no digest)" +} + +variable "image_digest" { + type = string + description = "Image digest (sha256:...)" +} + + +locals { + image_uri = "${var.ecr_repo_url}@${var.image_digest}" +} + +output "resolved_image_uri" { + value = local.image_uri +} diff --git a/infrastructure/terraform/shared/main.tf b/infrastructure/terraform/shared/main.tf index acf8c281..74906c32 100644 --- a/infrastructure/terraform/shared/main.tf +++ b/infrastructure/terraform/shared/main.tf @@ -392,4 +392,19 @@ module "postcode_splitter_s3_read" { output "postcode_splitter_s3_read_arn" { value = module.postcode_splitter_s3_read.policy_arn +} + +################################################ +# Categorisation – Lambda ECR +################################################ +module "categorisation_state_bucket" { + source = "../modules/tf_state_bucket" + bucket_name = "categorisation-terraform-state" + +} + +module "categorisation_registry" { + source = "../modules/container_registry" + name = "categorisation" + stage = var.stage } \ No newline at end of file