Skip to content

Commit 6d62980

Browse files
Remove IP stuff for now
1 parent a23acbd commit 6d62980

4 files changed

Lines changed: 88 additions & 99 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,35 @@ jobs:
221221
- name: Get API endpoint
222222
run: |
223223
echo "=== API Endpoint ==="
224-
cd terraform
225-
ALB_URL=$(terraform output -raw load_balancer_url)
226-
echo "API is available at: $ALB_URL"
227-
echo "Health check: $ALB_URL/health"
228-
echo "Documentation: $ALB_URL/docs"
224+
TASK_ARN=$(aws ecs list-tasks \
225+
--cluster ${{ vars.ECS_CLUSTER_NAME }} \
226+
--service-name ${{ vars.ECS_API_SERVICE_NAME }} \
227+
--region ${{ vars.AWS_REGION }} \
228+
--desired-status RUNNING \
229+
--query 'taskArns[0]' \
230+
--output text)
231+
232+
if [ -n "$TASK_ARN" ] && [ "$TASK_ARN" != "None" ]; then
233+
NETWORK_INTERFACE_ID=$(aws ecs describe-tasks \
234+
--cluster ${{ vars.ECS_CLUSTER_NAME }} \
235+
--tasks $TASK_ARN \
236+
--region ${{ vars.AWS_REGION }} \
237+
--query 'tasks[0].attachments[0].details[?name==`networkInterfaceId`].value' \
238+
--output text)
239+
240+
PUBLIC_IP=$(aws ec2 describe-network-interfaces \
241+
--network-interface-ids $NETWORK_INTERFACE_ID \
242+
--region ${{ vars.AWS_REGION }} \
243+
--query 'NetworkInterfaces[0].Association.PublicIp' \
244+
--output text)
245+
246+
if [ -n "$PUBLIC_IP" ] && [ "$PUBLIC_IP" != "None" ]; then
247+
echo "API is available at: http://$PUBLIC_IP"
248+
echo "Health check: http://$PUBLIC_IP/health"
249+
echo "Documentation: http://$PUBLIC_IP/docs"
250+
else
251+
echo "Could not retrieve public IP"
252+
fi
253+
else
254+
echo "No running API tasks found"
255+
fi

scripts/get-api-ip.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
# Get the current public IP of the API ECS task
3+
4+
set -e
5+
6+
CLUSTER_NAME=${1:-policyengine-api-v2-alpha}
7+
SERVICE_NAME=${2:-policyengine-api-v2-alpha-api}
8+
AWS_REGION=${3:-us-east-1}
9+
10+
echo "Getting API endpoint for cluster: $CLUSTER_NAME, service: $SERVICE_NAME"
11+
12+
TASK_ARN=$(aws ecs list-tasks \
13+
--cluster "$CLUSTER_NAME" \
14+
--service-name "$SERVICE_NAME" \
15+
--region "$AWS_REGION" \
16+
--desired-status RUNNING \
17+
--query 'taskArns[0]' \
18+
--output text)
19+
20+
if [ -z "$TASK_ARN" ] || [ "$TASK_ARN" == "None" ]; then
21+
echo "Error: No running tasks found"
22+
exit 1
23+
fi
24+
25+
NETWORK_INTERFACE_ID=$(aws ecs describe-tasks \
26+
--cluster "$CLUSTER_NAME" \
27+
--tasks "$TASK_ARN" \
28+
--region "$AWS_REGION" \
29+
--query 'tasks[0].attachments[0].details[?name==`networkInterfaceId`].value' \
30+
--output text)
31+
32+
PUBLIC_IP=$(aws ec2 describe-network-interfaces \
33+
--network-interface-ids "$NETWORK_INTERFACE_ID" \
34+
--region "$AWS_REGION" \
35+
--query 'NetworkInterfaces[0].Association.PublicIp' \
36+
--output text)
37+
38+
if [ -z "$PUBLIC_IP" ] || [ "$PUBLIC_IP" == "None" ]; then
39+
echo "Error: Could not retrieve public IP"
40+
exit 1
41+
fi
42+
43+
echo ""
44+
echo "API endpoint: http://$PUBLIC_IP"
45+
echo "Health check: http://$PUBLIC_IP/health"
46+
echo "Documentation: http://$PUBLIC_IP/docs"
47+
echo ""
48+
echo "IP address: $PUBLIC_IP"

terraform/main.tf

Lines changed: 5 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -146,97 +146,18 @@ resource "aws_ecs_cluster" "main" {
146146
}
147147
}
148148

149-
# Application Load Balancer
150-
resource "aws_security_group" "alb" {
151-
name = "${var.project_name}-alb-sg"
152-
description = "Security group for Application Load Balancer"
153-
vpc_id = aws_vpc.main.id
154-
155-
ingress {
156-
from_port = 80
157-
to_port = 80
158-
protocol = "tcp"
159-
cidr_blocks = ["0.0.0.0/0"]
160-
}
161-
162-
ingress {
163-
from_port = 443
164-
to_port = 443
165-
protocol = "tcp"
166-
cidr_blocks = ["0.0.0.0/0"]
167-
}
168-
169-
egress {
170-
from_port = 0
171-
to_port = 0
172-
protocol = "-1"
173-
cidr_blocks = ["0.0.0.0/0"]
174-
}
175-
176-
tags = {
177-
Name = "${var.project_name}-alb-sg"
178-
}
179-
}
180-
181-
resource "aws_lb" "main" {
182-
name = "${var.project_name}-alb"
183-
internal = false
184-
load_balancer_type = "application"
185-
security_groups = [aws_security_group.alb.id]
186-
subnets = aws_subnet.public[*].id
187-
188-
tags = {
189-
Name = "${var.project_name}-alb"
190-
}
191-
}
192-
193-
resource "aws_lb_target_group" "api" {
194-
name = "${var.project_name}-api-tg"
195-
port = 80
196-
protocol = "HTTP"
197-
vpc_id = aws_vpc.main.id
198-
target_type = "ip"
199-
200-
health_check {
201-
enabled = true
202-
healthy_threshold = 2
203-
interval = 30
204-
matcher = "200"
205-
path = "/health"
206-
port = "traffic-port"
207-
protocol = "HTTP"
208-
timeout = 5
209-
unhealthy_threshold = 2
210-
}
211-
212-
tags = {
213-
Name = "${var.project_name}-api-tg"
214-
}
215-
}
216-
217-
resource "aws_lb_listener" "api" {
218-
load_balancer_arn = aws_lb.main.arn
219-
port = "80"
220-
protocol = "HTTP"
221-
222-
default_action {
223-
type = "forward"
224-
target_group_arn = aws_lb_target_group.api.arn
225-
}
226-
}
227-
228149
# Security group for ECS tasks
229150
resource "aws_security_group" "ecs" {
230151
name = "${var.project_name}-ecs-sg"
231152
description = "Security group for ECS tasks"
232153
vpc_id = aws_vpc.main.id
233154

234155
ingress {
235-
from_port = 80
236-
to_port = 80
237-
protocol = "tcp"
238-
security_groups = [aws_security_group.alb.id]
239-
description = "Allow traffic from ALB"
156+
from_port = 80
157+
to_port = 80
158+
protocol = "tcp"
159+
cidr_blocks = ["0.0.0.0/0"]
160+
description = "Allow HTTP traffic from internet"
240161
}
241162

242163
egress {
@@ -480,13 +401,6 @@ resource "aws_ecs_service" "api" {
480401
assign_public_ip = true
481402
}
482403

483-
load_balancer {
484-
target_group_arn = aws_lb_target_group.api.arn
485-
container_name = "api"
486-
container_port = 80
487-
}
488-
489-
depends_on = [aws_lb_listener.api]
490404

491405
tags = {
492406
Name = "${var.project_name}-api-service"

terraform/outputs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ output "redis_endpoint" {
88
value = aws_elasticache_cluster.redis.cache_nodes[0].address
99
}
1010

11-
output "load_balancer_url" {
12-
description = "Load balancer URL for API"
13-
value = "http://${aws_lb.main.dns_name}"
11+
output "api_endpoint" {
12+
description = "API endpoint (use script to get current IP)"
13+
value = "Run: aws ecs describe-tasks --cluster ${aws_ecs_cluster.main.name} --tasks $(aws ecs list-tasks --cluster ${aws_ecs_cluster.main.name} --service-name ${aws_ecs_service.api.name} --query 'taskArns[0]' --output text) --query 'tasks[0].attachments[0].details[?name==`networkInterfaceId`].value' --output text | xargs -I {} aws ec2 describe-network-interfaces --network-interface-ids {} --query 'NetworkInterfaces[0].Association.PublicIp' --output text"
1414
}
1515

1616
output "ecs_cluster_name" {

0 commit comments

Comments
 (0)