Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(terraform): vol5223 initial setup of eventbridge scheduling for batch #197

Merged
merged 40 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d2a1252
feat(terraform): vol5223 initial setup of eventbridge module for batch
matbeales Jul 31, 2024
27217a0
feat(terraform): add schedules block in locals
matbeales Jul 31, 2024
97b222d
docs: update Terraform docs
github-actions[bot] Jul 31, 2024
ce48d5e
feat(terraform): create eventbridge module with temp hardcoded example
matbeales Aug 1, 2024
2746b1b
feat(terraform): create eventbridge module with temp hardcoded example
matbeales Aug 1, 2024
15a1316
feat(terraform): create eventbridge module with temp hardcoded example
matbeales Aug 1, 2024
f16332d
feat(terraform): create eventbridge module with temp hardcoded example
matbeales Aug 1, 2024
bce0557
docs: update Terraform docs
github-actions[bot] Aug 1, 2024
1b42039
Merge branch 'main' into VOL-5223-batch-schedules
matbeales Aug 1, 2024
34ae5e8
feat(terraform): create eventbridge module with temp hardcoded example
matbeales Aug 1, 2024
844c330
feat(terraform): create eventbridge module with temp hardcoded example
matbeales Aug 1, 2024
294afc6
feat(terraform): create eventbridge module with temp hardcoded example
matbeales Aug 1, 2024
10a11e1
feat(terraform): create eventbridge module with temp hardcoded example
matbeales Aug 1, 2024
6e60b93
feat(terraform): create eventbridge module with temp hardcoded example
matbeales Aug 1, 2024
ae8af46
feat(terraform): create eventbridge module with temp hardcoded example
matbeales Aug 1, 2024
d0bf86e
feat(terraform): add if statement to scheduled jobs
matbeales Aug 1, 2024
cf7d5a6
feat(terraform): add if statement to scheduled jobs
matbeales Aug 1, 2024
65f36bf
docs: update Terraform docs
github-actions[bot] Aug 1, 2024
5e1653f
feat(terraform): add if statement to scheduled jobs
matbeales Aug 1, 2024
8e95380
docs: update Terraform docs
github-actions[bot] Aug 1, 2024
1b011a3
feat(terraform): add if statement to scheduled jobs
matbeales Aug 1, 2024
471bd38
feat(terraform): add if statement to scheduled jobs
matbeales Aug 1, 2024
e18a0ad
feat(terraform): fix local schedules
matbeales Aug 1, 2024
82f2182
feat(terraform): add if statement to scheduled jobs
matbeales Aug 1, 2024
0594180
feat(terraform): add if statement to scheduled jobs
matbeales Aug 1, 2024
547b5dd
feat(terraform): add if statement to scheduled jobs
matbeales Aug 2, 2024
dd4c29a
feat(terraform): add conditional for scheduled jobs only
matbeales Aug 2, 2024
c6ad419
feat(terraform): add conditional for scheduled jobs only
matbeales Aug 2, 2024
f4cf5bc
feat(terraform): add conditional for scheduled jobs only
matbeales Aug 2, 2024
abda6c2
Merge branch 'main' into VOL-5223-batch-schedules
matbeales Aug 2, 2024
fbb482c
feat(terraform): add variables for region and account number
matbeales Aug 2, 2024
700b040
docs: update Terraform docs
github-actions[bot] Aug 2, 2024
51d3687
feat(terraform): tidy up formatting for eventbridge module
matbeales Aug 5, 2024
5e725ba
feat(terraform): linting fixes
matbeales Aug 5, 2024
fcae7a1
docs: update Terraform docs
github-actions[bot] Aug 5, 2024
24e79d1
feat(terraform): less strict versioning and cleaner if statement on e…
matbeales Aug 6, 2024
20f0de8
feat(terraform): attempt logical reference in eventbridge batch input
matbeales Aug 6, 2024
6850357
feat(terraform): fix merge conflict and remove unsued data calls
matbeales Aug 6, 2024
8a2d185
docs: update Terraform docs
github-actions[bot] Aug 6, 2024
09f8c84
feat(terraform): ammend job name and description
matbeales Aug 6, 2024
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
34 changes: 34 additions & 0 deletions infra/terraform/environments/dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -254,26 +254,31 @@ module "service" {
name = "clean-up-variations",
commands = ["batch:clean-up-variations"],
timeout = 43200,
schedule = "cron(00 02 * * ? *)",
},
{
name = "cns",
commands = ["batch:cns"],
timeout = 43200,
schedule = "cron(30 18 ? * 7 *)",
},
{
name = "create-psv-licence-surrender-task",
commands = ["batch:create-psv-licence-surrender-task"],
timeout = 43200,
schedule = "cron(00 02 * * ? *)",
},
{
name = "psv-operator-list-export",
commands = ["batch:data-gov-uk-export", "-v", "--report-name=psv-operator-list", "--path=/tmp/"],
timeout = 43200,
schedule = "cron(00 02 ? * 7 *)",
},
{
name = "international-goods-export",
commands = ["batch:data-gov-uk-export", "-v", "--report-name=international-goods", "--path=/tmp/"],
timeout = 43200,
schedule = "cron(00 02 ? * 7 *)",
},
{
name = "data-retention-populate",
Expand All @@ -299,26 +304,31 @@ module "service" {
name = "digital-continuation-reminders",
commands = ["batch:digital-continuation-reminders"],
timeout = 43200,
schedule = "cron(00 02 * * ? *)",
},
{
name = "duplicate-vehicle-warning",
commands = ["batch:duplicate-vehicle-warning"],
timeout = 43200,
schedule = "cron(0 18 ? * 1-5 *)",
},
{
name = "enqueue-ch-compare",
commands = ["batch:enqueue-ch-compare"],
timeout = 1800,
schedule = "cron(0 21 ? * 3 *)",
},
{
name = "expire-bus-registration",
commands = ["batch:expire-bus-registration"],
timeout = 43200,
schedule = "cron(0 21 ? * 3 *)",
},
{
name = "flag-urgent-tasks",
commands = ["batch:flag-urgent-tasks"],
timeout = 1800,
schedule = "cron(0 * * * ? *)",
},
{
name = "import-users-from-csv",
Expand All @@ -328,21 +338,25 @@ module "service" {
name = "inspection-request-email",
commands = ["batch:inspection-request-email"],
timeout = 1800,
schedule = "cron(0 00-04 * * ? *)",
},
{
name = "interim-end-date-enforcement",
commands = ["batch:interim-end-date-enforcement"],
timeout = 43200,
schedule = "cron(00 02 * * ? *)",
},
{
name = "last-tm-letter",
commands = ["batch:last-tm-letter"],
timeout = 43200,
schedule = "cron(30 06 * * ? *)",
},
{
name = "licence-status-rules",
commands = ["batch:licence-status-rules"],
timeout = 1800,
schedule = "cron(0 * * * ? *)",
},
{
name = "process-cl",
Expand All @@ -352,21 +366,25 @@ module "service" {
name = "process-inbox",
commands = ["batch:process-inbox"],
timeout = 43200,
schedule = "cron(45 01 * ? *)",
},
{
name = "process-ntu",
commands = ["batch:process-ntu"],
timeout = 43200,
schedule = "cron(45 01 * ? *)",
},
{
name = "remove-read-audit",
commands = ["batch:remove-read-audit"],
timeout = 43200,
schedule = "cron(0 22 ? * 7 *)",
},
{
name = "resolve-payments",
commands = ["batch:resolve-payments"],
timeout = 150,
schedule = "cron(0/5 * * * ? *)",
},
{
name = "system-parameter",
Expand All @@ -380,81 +398,97 @@ module "service" {
name = "close-expired-windows",
commands = ["permits:close-expired-windows"],
timeout = 43200,
schedule = "cron(45 00 * * ? *)",
},
{
name = "mark-expired-permits",
commands = ["permits:mark-expired-permits"],
timeout = 43200,
schedule = "cron(15 06 * * ? *)",
},
{
name = "process-queue-general",
commands = ["queue:process-queue", "--exclude", "que_typ_ch_compare,que_typ_create_gds_vehicle_list,que_typ_create_psv_vehicle_list,que_typ_disc_printing,que_typ_print,que_typ_disc_printing_print,que_typ_create_com_lic,que_typ_remove_deleted_docs,que_typ_permit_generate,que_typ_permit_print,que_typ_run_ecmt_scoring,que_typ_accept_ecmt_scoring,que_typ_irhp_permits_allocate"],
timeout = 90,
schedule = "cron(0/2 * * * ? *)",
},
{
name = "process-queue-community-licences",
commands = ["queue:process-queue", "--type", "que_typ_create_com_lic"],
timeout = 90,
schedule = "cron(0/2 * * * ? *)",
},
{
name = "process-queue-disc-generation",
commands = ["queue:process-queue", "--type", "que_typ_create_gds_vehicle_list,que_typ_create_psv_vehicle_list,que_typ_disc_printing"],
timeout = 90,
schedule = "cron(0/2 * * * ? *)",
},
{
name = "process-queue-disc-print",
commands = ["queue:process-queue", "--type", "que_typ_disc_printing_print", "--queue-duration", "840"],
timeout = 850,
schedule = "cron(0/15 * * * ? *)",
},
{
name = "process-queue-ecmt-accept",
commands = ["queue:process-queue", "--type", "que_typ_accept_ecmt_scoring"],
timeout = 90,
schedule = "cron(0/2 * * * ? *)",
},
{
name = "process-queue-irhp-allocate",
commands = ["queue:process-queue", "--type", "que_typ_run_ecmt_scoring"],
timeout = 90,
schedule = "cron(0/2 * * * ? *)",
},
{
name = "process-queue-permit-generation",
commands = ["queue:process-queue", "--type", "que_typ_permit_generate"],
timeout = 90,
schedule = "cron(0/2 * * * ? *)",
},
{
name = "process-queue-permit-print",
commands = ["queue:process-queue", "--type", "que_typ_permit_print", "--queue-duration", "840"],
timeout = 850,
schedule = "cron(0/15 * * * ? *)",
},
{
name = "process-queue-print",
commands = ["queue:process-queue", "--type", "que_typ_print"],
timeout = 90,
schedule = "cron(0/2 * * * ? *)",
},
{
name = "process-company-profile",
commands = ["queue:process-company-profile"],
timeout = 150,
schedule = "cron(0/5 * * * ? *)",
},
{
name = "company-profile-dlq",
commands = ["queue:company-profile-dlq"],
timeout = 900,
schedule = "cron(0/30 * * * ? *)",
},
{
name = "process-insolvency",
commands = ["queue:process-insolvency"],
timeout = 900,
schedule = "cron(0/30 * * * ? *)",
},
{
name = "process-insolvency-dlq",
commands = ["queue:process-insolvency-dlq"],
timeout = 900,
schedule = "cron(0/30 * * * ? *)",
},
{
name = "transxchange-consumer",
commands = ["queue:transxchange-consumer"],
timeout = 90,
schedule = "cron(0/2 * * * ? *)",
},
]
}
Expand Down
3 changes: 2 additions & 1 deletion infra/terraform/modules/service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
| <a name="module_cloudfront"></a> [cloudfront](#module\_cloudfront) | terraform-aws-modules/cloudfront/aws | ~> 3.4 |
| <a name="module_ecs_cluster"></a> [ecs\_cluster](#module\_ecs\_cluster) | terraform-aws-modules/ecs/aws//modules/cluster | ~> 5.10 |
| <a name="module_ecs_service"></a> [ecs\_service](#module\_ecs\_service) | terraform-aws-modules/ecs/aws//modules/service | ~> 5.10 |
| <a name="module_eventbridge"></a> [eventbridge](#module\_eventbridge) | terraform-aws-modules/eventbridge/aws | ~> 3.7 |
| <a name="module_log_bucket"></a> [log\_bucket](#module\_log\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 4.0 |
| <a name="module_records"></a> [records](#module\_records) | terraform-aws-modules/route53/aws//modules/records | ~> 3.1 |
| <a name="module_route53_records"></a> [route53\_records](#module\_route53\_records) | terraform-aws-modules/acm/aws | ~> 5.0 |
Expand All @@ -46,7 +47,7 @@
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_assets_version"></a> [assets\_version](#input\_assets\_version) | The version of the assets | `string` | n/a | yes |
| <a name="input_batch"></a> [batch](#input\_batch) | Configuration for the batch process | <pre>object({<br> version = string<br> repository = string<br> subnet_ids = list(string)<br> task_iam_role_statements = list(object({<br> effect = string<br> actions = list(string)<br> resources = list(string)<br> }))<br> jobs = list(object({<br> name = string<br> commands = list(string)<br> cpu = optional(number, 1)<br> memory = optional(number, 2048)<br> timeout = optional(number, 300)<br> }))<br> })</pre> | n/a | yes |
| <a name="input_batch"></a> [batch](#input\_batch) | Configuration for the batch process | <pre>object({<br> version = string<br> repository = string<br> subnet_ids = list(string)<br> task_iam_role_statements = list(object({<br> effect = string<br> actions = list(string)<br> resources = list(string)<br> }))<br> jobs = list(object({<br> name = string<br> commands = list(string)<br> cpu = optional(number, 1)<br> memory = optional(number, 2048)<br> timeout = optional(number, 300)<br> schedule = optional(string, "")<br> }))<br> })</pre> | n/a | yes |
| <a name="input_domain_name"></a> [domain\_name](#input\_domain\_name) | The domain name for the environment | `string` | n/a | yes |
| <a name="input_environment"></a> [environment](#input\_environment) | The environment to deploy to | `string` | n/a | yes |
| <a name="input_services"></a> [services](#input\_services) | The services to deploy | <pre>map(object({<br> version = string<br> repository = string<br> cpu = number<br> memory = number<br> task_iam_role_statements = list(object({<br> effect = string<br> actions = list(string)<br> resources = list(string)<br> }))<br> add_cdn_url_to_env = optional(bool, false)<br> lb_listener_arn = string<br> listener_rule_priority = optional(number, 10)<br> listener_rule_host_header = optional(string, "*")<br> security_group_ids = list(string)<br> subnet_ids = list(string)<br> vpc_id = optional(string, null)<br> }))</pre> | `{}` | no |
Expand Down
20 changes: 20 additions & 0 deletions infra/terraform/modules/service/batch.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ locals {
attempt_duration_seconds = job.timeout
retry_strategy = local.default_retry_policy
} }

schedules = {
for job in var.batch.jobs : job.name => {
description = "Schedule for ${module.batch.job_definitions[job.name].name}"
schedule_expression = job.schedule
arn = "arn:aws:scheduler:::aws-sdk:batch:submitJob"
input = jsonencode({ "jobName" : module.batch.job_definitions[job.name].name, "jobQueue" : module.batch.job_queues.default.arn, "jobDefinition" : module.batch.job_definitions[job.name].arn })
}
if job.schedule != ""
}
}

module "batch" {
Expand Down Expand Up @@ -110,6 +120,16 @@ module "batch" {
job_definitions = local.jobs
}

module "eventbridge" {
source = "terraform-aws-modules/eventbridge/aws"
version = "~> 3.7"

create_bus = false
create_role = true

schedules = local.schedules
}

resource "aws_cloudwatch_log_group" "this" {
name = "/aws/batch/vol-app-${var.environment}"
retention_in_days = 1
Expand Down
1 change: 1 addition & 0 deletions infra/terraform/modules/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ variable "batch" {
cpu = optional(number, 1)
memory = optional(number, 2048)
timeout = optional(number, 300)
schedule = optional(string, "")
}))
})
}