@@ -2,134 +2,71 @@ terraform {
22 required_version = " >= 1.0"
33
44 required_providers {
5- aws = {
6- source = " hashicorp/aws"
7- version = " ~> 5.0"
8- }
95 local = {
106 source = " hashicorp/local"
117 version = " ~> 2.4"
128 }
139 }
1410}
1511
16- provider "aws" {
17- region = var. aws_region
18-
19- default_tags {
20- tags = {
21- Project = " HBN Migration"
22- Environment = var.environment
23- ManagedBy = " Terraform"
24- }
25- }
12+ locals {
13+ workspace = terraform. workspace
2614}
2715
28- # EC2 Instance
29- resource "aws_instance" "hbn_migration" {
30- ami = var. ami_id
31- instance_type = var. instance_type
32- key_name = var. key_name
33- ebs_optimized = true
34- monitoring = true
35-
36- vpc_security_group_ids = [aws_security_group . hbn_migration . id ]
37- subnet_id = var. subnet_id
38-
39- metadata_options {
40- http_endpoint = " enabled"
41- http_tokens = " required"
42- }
43-
44- root_block_device {
45- encrypted = true
46- }
47-
48- user_data = templatefile (" ${ path . module } /user_data.sh" , {
49- github_repo = var.github_repo
50- github_branch = var.github_branch
51- working_directory = var.working_directory
52- python_venv = var.python_venv
16+ # Webhook services (long-running uvicorn servers)
17+ resource "local_file" "redcap_to_redcap_service" {
18+ content = templatefile (" ${ path . module } /services/redcap-to-redcap.service.tpl" , {
5319 service_user = var.service_user
5420 service_group = var.service_group
21+ working_directory = var.working_directory
22+ python_venv = var.python_venv
5523 })
56-
57- tags = {
58- Name = " hbn-migration-${ var . environment } "
59- }
60-
61- lifecycle {
62- create_before_destroy = true
63- }
24+ filename = " ${ path . module } /generated/redcap-to-redcap.service"
6425}
6526
66- # Security Group
67- resource "aws_security_group" "hbn_migration" {
68- name = " hbn-migration-${ var . environment } "
69- description = " Security group for HBN migration webhook services"
70- vpc_id = var. vpc_id
71-
72- # SSH access (conditional - only if CIDRs specified)
73- dynamic "ingress" {
74- for_each = length (var. ssh_allowed_cidrs ) > 0 ? [1 ] : []
75- content {
76- from_port = 22
77- to_port = 22
78- protocol = " tcp"
79- cidr_blocks = var. ssh_allowed_cidrs
80- description = " SSH access"
81- }
82- }
83-
84- # REDCap to REDCap webhook
85- ingress {
86- from_port = 8001
87- to_port = 8001
88- protocol = " tcp"
89- cidr_blocks = var. webhook_allowed_cidrs
90- description = " REDCap to Intake webhook"
91- }
92-
93- # REDCap to Curious webhook
94- ingress {
95- from_port = 8002
96- to_port = 8002
97- protocol = " tcp"
98- cidr_blocks = var. webhook_allowed_cidrs
99- description = " REDCap to Curious webhook"
100- }
101-
102- # Outbound traffic (required for apt, pip, API calls to REDCap/Curious)
103- egress {
104- from_port = 0
105- to_port = 0
106- protocol = " -1"
107- cidr_blocks = [" 0.0.0.0/0" ]
108- description = " All outbound traffic (required for updates and API calls)"
109- }
110-
111- tags = {
112- Name = " hbn-migration-${ var . environment } "
113- }
27+ resource "local_file" "redcap_to_curious_service" {
28+ content = templatefile (" ${ path . module } /services/redcap-to-curious.service.tpl" , {
29+ service_user = var.service_user
30+ service_group = var.service_group
31+ working_directory = var.working_directory
32+ python_venv = var.python_venv
33+ })
34+ filename = " ${ path . module } /generated/redcap-to-curious.service"
11435}
11536
116- # Generate systemd service files
117- resource "local_file" "redcap_to_redcap_service " {
118- content = templatefile (" ${ path . module } /services/redcap-to-redcap.service.tpl" , {
37+ # Batch services (oneshot, triggered by timer)
38+ resource "local_file" "redcap_to_redcap_batch_service " {
39+ content = templatefile (" ${ path . module } /services/redcap-to-redcap-batch .service.tpl" , {
11940 service_user = var.service_user
12041 service_group = var.service_group
12142 working_directory = var.working_directory
12243 python_venv = var.python_venv
12344 })
124- filename = " ${ path . module } /generated/redcap-to-redcap.service"
45+ filename = " ${ path . module } /generated/redcap-to-redcap-batch .service"
12546}
12647
127- resource "local_file" "redcap_to_curious_service " {
128- content = templatefile (" ${ path . module } /services/redcap-to-curious.service.tpl" , {
48+ resource "local_file" "redcap_to_curious_batch_service " {
49+ content = templatefile (" ${ path . module } /services/redcap-to-curious-batch .service.tpl" , {
12950 service_user = var.service_user
13051 service_group = var.service_group
13152 working_directory = var.working_directory
13253 python_venv = var.python_venv
13354 })
134- filename = " ${ path . module } /generated/redcap-to-curious.service"
55+ filename = " ${ path . module } /generated/redcap-to-curious-batch.service"
56+ }
57+
58+ # Timer and sync target
59+ resource "local_file" "hbn_sync_service" {
60+ content = templatefile (" ${ path . module } /services/hbn-sync.service.tpl" , {
61+ workspace = local.workspace
62+ })
63+ filename = " ${ path . module } /generated/hbn-sync.service"
64+ }
65+
66+ resource "local_file" "hbn_sync_timer" {
67+ content = templatefile (" ${ path . module } /services/hbn-sync.timer.tpl" , {
68+ workspace = local.workspace
69+ sync_interval_minutes = var.sync_interval_minutes
70+ })
71+ filename = " ${ path . module } /generated/hbn-sync.timer"
13572}
0 commit comments