@@ -19,73 +19,15 @@ data "aws_ssm_parameter" "private_subnet_id" {
19
19
name = " /unity/shared-services/network/privatesubnet2"
20
20
}
21
21
22
- # Create ALB security group
23
- # TODO: REMOVE this ALB securty group.
24
- # Use ucs-httpd-alb-sec-group
25
- resource "aws_security_group" "alb_sg" {
26
- # TODO: change this to the actual name
27
- name = " ucs-httpd-alb-sec-group2"
28
- description = " Security group for shared services ALB"
29
- vpc_id = data. aws_ssm_parameter . vpc_id . value
30
-
31
- # Incoming rules for ALB
32
- ingress {
33
- from_port = 80
34
- to_port = 80
35
- protocol = " tcp"
36
- cidr_blocks = [" 0.0.0.0/0" ]
37
- description = " Allow HTTP from anywhere"
38
- }
39
-
40
- ingress {
41
- from_port = 443
42
- to_port = 443
43
- protocol = " tcp"
44
- cidr_blocks = [" 0.0.0.0/0" ]
45
- description = " Allow HTTPS from anywhere"
46
- }
47
-
48
- # Outgoing rule - allow all traffic
49
- egress {
50
- from_port = 0
51
- to_port = 0
52
- protocol = " -1"
53
- cidr_blocks = [" 0.0.0.0/0" ]
54
- }
55
-
56
- tags = {
57
- # TODO: change this to the actual name
58
- Name = " ucs-httpd-alb-sec-group2"
59
- }
22
+ # Get existing security group
23
+ data "aws_security_group" "httpd_sg" {
24
+ name = " shared-services-httpd-sg"
25
+ vpc_id = data. aws_ssm_parameter . vpc_id . value
60
26
}
61
27
62
- # Create security group for HTTPD instance
63
- resource "aws_security_group" "httpd_sg" {
64
- # TODO: change this to the actual name
65
- name = " shared-services-httpd-sg2"
66
- description = " Security group for shared services HTTPD"
67
- vpc_id = data. aws_ssm_parameter . vpc_id . value
68
-
69
- # Incoming rule for HTTPS
70
- ingress {
71
- from_port = 443
72
- to_port = 443
73
- protocol = " tcp"
74
- security_groups = [aws_security_group . alb_sg . id ]
75
- }
76
-
77
- # Outgoing rule - allow all traffic
78
- egress {
79
- from_port = 0
80
- to_port = 0
81
- protocol = " -1"
82
- cidr_blocks = [" 0.0.0.0/0" ]
83
- }
84
-
85
- tags = {
86
- # TODO: change this to the actual name
87
- Name = " shared-services-httpd-sg2"
88
- }
28
+ # Get venue from SSM Parameter Store
29
+ data "aws_ssm_parameter" "venue" {
30
+ name = " /unity/account/venue"
89
31
}
90
32
91
33
# Create EC2 instance
@@ -94,8 +36,8 @@ resource "aws_instance" "httpd_instance" {
94
36
instance_type = " t3.large"
95
37
96
38
subnet_id = data. aws_ssm_parameter . private_subnet_id . value
97
- vpc_security_group_ids = [aws_security_group . httpd_sg . id ]
98
- iam_instance_profile = " MCP-SSM-CloudWatch "
39
+ vpc_security_group_ids = [data . aws_security_group . httpd_sg . id ]
40
+ iam_instance_profile = " U-CS_Service_Role "
99
41
associate_public_ip_address = false
100
42
101
43
user_data = <<- EOF
@@ -104,14 +46,18 @@ resource "aws_instance" "httpd_instance" {
104
46
sudo su - ubuntu << 'USERDATA'
105
47
echo "Starting Apache installation and configuration..."
106
48
49
+ # Clone unity-cs-infra repository
50
+ echo "Cloning unity-cs-infra repository..."
51
+ cd /home/ubuntu
52
+ git clone https://github.com/unity-sds/unity-cs-infra.git
53
+
107
54
# Update package lists
108
55
echo "Updating package lists..."
109
56
sudo apt update
110
57
111
- # Install Apache2 and OpenIDC module
112
- echo "Installing Apache2 and OpenIDC module..."
113
- sudo DEBIAN_FRONTEND=noninteractive apt install -y apache2
114
- sudo DEBIAN_FRONTEND=noninteractive apt-get install -y libapache2-mod-auth-openidc
58
+ # Install Apache2, OpenIDC module, and AWS CLI
59
+ echo "Installing Apache2, OpenIDC module, and AWS CLI..."
60
+ sudo DEBIAN_FRONTEND=noninteractive apt install -y apache2 libapache2-mod-auth-openidc awscli
115
61
116
62
# Enable Apache modules
117
63
echo "Enabling Apache modules..."
@@ -136,6 +82,27 @@ resource "aws_instance" "httpd_instance" {
136
82
echo "Restarting Apache..."
137
83
sudo systemctl restart apache2
138
84
85
+ # Create and set permissions for sync log file
86
+ echo "Setting up sync log file..."
87
+ sudo touch /var/log/sync_apache_config.log
88
+ sudo chown ubuntu:ubuntu /var/log/sync_apache_config.log
89
+ sudo chmod 644 /var/log/sync_apache_config.log
90
+
91
+ # Set up cron job with PATH
92
+ echo "Setting up cron job..."
93
+ SYSTEM_PATH=$(echo $PATH)
94
+ (crontab -l 2>/dev/null; echo "PATH=$SYSTEM_PATH") | crontab -
95
+ (crontab -l 2>/dev/null; echo "* * * * * ~/unity-cs-infra/terraform-ss-proxy/sync_apache_config.sh >> /var/log/sync_apache_config.log 2>&1") | crontab -
96
+
97
+ # Get venue from SSM and download Apache config
98
+ echo "Downloading Apache configuration..."
99
+ VENUE=$(aws ssm get-parameter --name "/unity/account/venue" --query "Parameter.Value" --output text)
100
+ sudo aws s3 cp "s3://ucs-shared-services-apache-config-$VENUE/unity-cs.conf" /etc/apache2/sites-enabled/
101
+
102
+ # Set proper permissions
103
+ sudo chown root:root /etc/apache2/sites-enabled/unity-cs.conf
104
+ sudo chmod 644 /etc/apache2/sites-enabled/unity-cs.conf
105
+
139
106
echo "Installation and configuration complete!"
140
107
USERDATA
141
108
EOF
0 commit comments