Skip to content

Commit

Permalink
Adding monitoring and logging (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar4596 authored Feb 28, 2024
1 parent 336f5a0 commit f4018ff
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ jobs:
# On push to "main", build or change infrastructure according to Terraform configuration files
# Note: It is recommended to set up a required "strict" status check in your repository for "Terraform Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks
- name: Terraform Apply
if: github.ref == 'refs/heads/"main"' && github.event_name == 'push'
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: terraform apply -auto-approve -input=false
4 changes: 4 additions & 0 deletions ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ resource "aws_instance" "minecraft_server" {
echo "eula=true" > eula.txt
java -Xms2G -Xmx4G -jar server.jar nogui
EOF

tags = {
Name = "minecraft_server"
}
}
3 changes: 2 additions & 1 deletion locals.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
locals {
# Allowed CIDR for minecraft_server
allowed_ips = ["186.155.12.50/32"]
allowed_ips = ["186.155.12.50/32"]
ssh_source_ip = "186.155.12.50/32"
}
3 changes: 3 additions & 0 deletions monitoring/logging.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

ssh -i '/Users/Oscar_Lopez/Downloads/test.pem' [email protected] tail -f /minecraft_server/logs/latest.log
4 changes: 4 additions & 0 deletions monitoring/top.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

pid=$(ssh -i '/Users/Oscar_Lopez/Downloads/test.pem' [email protected] pidof java)
ssh -i '/Users/Oscar_Lopez/Downloads/test.pem' [email protected] ps -p ${pid} -o %cpu,%mem,cmd
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
output "pub_ip" {
value = aws_instance.minecraft_server.public_ip
description = "Instance Public IP"
depends_on = [aws_instance.minecraft_server]
}
8 changes: 7 additions & 1 deletion sg.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resource "aws_security_group" "minecraft_server" {

resource "aws_vpc_security_group_ingress_rule" "minecraft_server_ssh" {
security_group_id = aws_security_group.minecraft_server.id
cidr_ipv4 = "186.155.12.50/32"
cidr_ipv4 = local.ssh_source_ip
from_port = 22
ip_protocol = "tcp"
to_port = 22
Expand All @@ -23,4 +23,10 @@ resource "aws_vpc_security_group_ingress_rule" "minecraft_server_port" {
from_port = 25565
ip_protocol = "tcp"
to_port = 25565
}

resource "aws_vpc_security_group_egress_rule" "minecraft_server" {
security_group_id = aws_security_group.minecraft_server.id
cidr_ipv4 = "0.0.0.0/0"
ip_protocol = -1
}

0 comments on commit f4018ff

Please sign in to comment.