Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.terraform
.terraform.lock.hcl
*.tfstate
*.tfstate.*
8 changes: 4 additions & 4 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[defaults]
inventory = inventory.ini
remote_user = vagrant
private_key_file = ~/.ssh/id_rsa
host_key_checking = False
remote_tmp = /tmp/.ansible-${USER}/tmp
roles_path= roles
roles_path = roles
remote_user = ubuntu
private_key_file = /home/emora/linux_files/workStuff/emi_openproject/tf_config/keys/openproject

2 changes: 1 addition & 1 deletion host_vars/db1.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ansible_host: 192.168.56.12
ansible_host: 3.123.232.167
2 changes: 1 addition & 1 deletion host_vars/web1.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ansible_host: 192.168.56.11
ansible_host: 3.68.226.174
apache_config_path: /etc/apache2/sites-available/openproject.conf
apache_service_name: apache2
ruby_version: "2.7"
Expand Down
4 changes: 2 additions & 2 deletions inventory.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[dbservers]
db1 ansible_host=192.168.56.12 ansible_user=vagrant ansible_ssh_private_key_file=~/.ssh/vagrant_db_key
db1 ansible_host=3.123.232.167 ansible_user=ubuntu ansible_ssh_private_key_file=/home/emora/linux_files/workStuff/emi_openproject/tf_config/keys/openproject

[webservers]
web1 ansible_host=192.168.56.11 ansible_user=vagrant ansible_ssh_private_key_file=~/.ssh/vagrant_web_key
web1 ansible_host=3.68.226.174 ansible_user=ubuntu ansible_ssh_private_key_file=/home/emora/linux_files/workStuff/emi_openproject/tf_config/keys/openproject

[all:children]
dbservers
Expand Down
5 changes: 5 additions & 0 deletions roles/webserver/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
service:
name: "{{ apache_service_name }}"
state: restarted

- name: restart openproject
systemd:
name: openproject-web
state: restarted
72 changes: 72 additions & 0 deletions tf_config/ec2_config.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
data "aws_ssm_parameter" "ubuntu_2004" {
name = "/aws/service/canonical/ubuntu/server/focal/stable/current/amd64/hvm/ebs-gp2/ami-id"
}
data "aws_vpcs" "default" {
filter {
name = "isDefault"
values = ["true"]
}
}

data "aws_subnets" "default_subnet" {
filter {
name = "vpc-id"
values = [data.aws_vpcs.default.ids[0]]
}
}

resource "aws_security_group" "openproject_sg" {
name = "openproject-sg"
vpc_id = data.aws_vpcs.default.ids[0]

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
self = true
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

resource "aws_key_pair" "openproject" {
key_name = "openproject-key"
public_key = file("${path.module}/keys/openproject.pub")
}

resource "aws_instance" "openproject" {
count = 2
ami = data.aws_ssm_parameter.ubuntu_2004.value
instance_type = "t3.micro"
subnet_id = data.aws_subnets.default_subnet.ids[0]
vpc_security_group_ids = [aws_security_group.openproject_sg.id]
key_name = aws_key_pair.openproject.key_name
associate_public_ip_address = true

tags = {
Name = "openproject-${count.index + 1}"
}
}

output "openproject_public_ips" {
value = aws_instance.openproject[*].public_ip
}
13 changes: 13 additions & 0 deletions tf_config/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.92"
}
}
required_version = ">=1.2"
}

provider "aws" {
region = "eu-central-1"
}