Commit 9e68d19c authored by pfandzelter's avatar pfandzelter
Browse files

add terraform template for a single node

parent c26ff82f
Dockerfile
\ No newline at end of file
*
!*.go
\ No newline at end of file
......@@ -248,4 +248,4 @@ public/
.fusebox/
# DynamoDB Local files
.dynamodb/
\ No newline at end of file
.dynamodb/
......@@ -22,4 +22,6 @@ COPY --from=golang /go/bin/frednode frednode
EXPOSE 9001
EXPOSE 5555
ENTRYPOINT ["./frednode"]
......@@ -9,6 +9,8 @@
In order to run zmq please install [zmq](https://zeromq.org/download/) and [czmq](http://czmq.zeromq.org/page:get-the-software).
On Arch, this is done by running `yay -S czmq`. Or use the Docker image.
To use Terraform, install [Terraform](https://www.terraform.io/downloads.html).
## Git Workflow
Setup git environment with `sh ./env-setup.sh` (installs git hooks). Be sure to have go installed...
......
data "aws_ami" "amazonlinux2" {
most_recent = true
filter {
name = "name"
values = ["amzn2-ami-hvm-2.0.*-ebs"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["137112412989"] # Canonical
}
\ No newline at end of file
# FReD Node Configuration File
[location]
# latitude of the server
lat = 52.514927933123914
# longitude of the server
lng = 13.32676300345363
[webserver]
# host = "localhost"
port = 9001
[storage]
# adaptor can be either "leveldb" or "memory"
adaptor = "leveldb"
[zmq]
port = 5555
[leveldb]
path = "./db"
[log]
# debug,info,warn,error,fatal,panic
level = "debug"
# dev: print colored output to stdout
# prod: print json to stdout
handler = "dev"
\ No newline at end of file
resource "aws_eip" "test-eip" {
instance = aws_instance.fred_instance.id
}
\ No newline at end of file
resource "aws_key_pair" "my-test-key" {
key_name = "test-key"
public_key = file("terraform.key.pub")
}
\ No newline at end of file
resource "aws_instance" "fred_instance" {
ami = data.aws_ami.amazonlinux2.id
instance_type = var.instance_type
key_name = aws_key_pair.my-test-key.key_name
security_groups = var.security_groups
provisioner "file" {
source = "./fred-node/config.toml"
destination = "/tmp/config.toml"
}
provisioner "file" {
source = "./fred-node/setup_node.sh"
destination = "/tmp/script.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/script.sh",
"/tmp/script.sh ${var.gitlab_repo_username} ${var.gitlab_repo_password}",
]
}
connection {
type = "ssh"
user = "ec2-user"
private_key = file("terraform.key")
host = self.public_ip
}
tags = {
Name = "test-instance"
type = "fred"
}
}
\ No newline at end of file
output "server-ip" {
value = aws_eip.test-eip.public_ip
}
\ No newline at end of file
sudo yum update -y --quiet
sudo yum install docker -y --quiet
echo "$2" > ./gitlabtoken
sudo systemctl start docker
sudo cat ./gitlabtoken | sudo docker login -u="$1" --password-stdin gitlab-registry.tubit.tu-berlin.de
sudo docker pull gitlab-registry.tubit.tu-berlin.de/mcc-fred/fred/fred:latest
sudo docker run -it \
--name=fred \
-d \
--restart=unless-stopped \
-p 80:9001 \
-p 5555:5555 \
-v /tmp/config.toml:/config.toml \
gitlab-registry.tubit.tu-berlin.de/mcc-fred/fred/fred:latest --config config.toml
\ No newline at end of file
variable "instance_type" {
type = string
default = "t2.micro"
}
variable "name" {
type = string
}
variable "key_pair" {
type = string
default = "my_test_key"
}
variable "key_pair_key" {
type = string
}
variable "security_groups" {
type = list(string)
default = []
}
variable "gitlab_repo_username" {
type = string
}
variable "gitlab_repo_password" {
type = string
}
\ No newline at end of file
resource "aws_key_pair" "terraform_key" {
key_name = "terraform_key"
public_key = file("terraform.key.pub")
}
module "fred-node-0" {
source = ".//fred-node"
name = "fred-node-0"
key_pair = aws_key_pair.terraform_key.key_name
key_pair_key = "terraform.key"
security_groups = [
aws_security_group.allow_ssh.name,
aws_security_group.allow_outbound.name,
aws_security_group.allow_fred_web.name,
aws_security_group.allow_fred_zmq.name
]
gitlab_repo_password = var.gitlab_repo_password
gitlab_repo_username = var.gitlab_repo_username
}
\ No newline at end of file
output "server-ip-0" {
value = module.fred-node-0.server-ip
}
\ No newline at end of file
provider "aws" {
region = var.aws_region
access_key = var.aws_access_key
secret_key = var.aws_secret_key
version = "~> 2.0"
}
\ No newline at end of file
resource "aws_security_group" "allow_ssh" {
name = "allow-ssh"
description = "Allow SSH inbound traffic"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "allow_fred_web" {
name = "allow_fred_web"
description = "Allow FReD inbound HTTP traffic"
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "allow_fred_zmq" {
name = "allow_fred_zmq"
description = "Allow FReD inbound ZMQ traffic"
ingress {
from_port = 5555
to_port = 5555
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "allow_outbound" {
name = "allow-all-outbound"
description = "Allow all outbound traffic"
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
\ No newline at end of file
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn
NhAAAAAwEAAQAAAQEAvwm407VkhALYoa0eZkrh8y+uwnq33I8Z+PTCeDRqOcMdjMWVcJLf
KMYyjp3bMDFkr/DxlFv77WSkVnQWicE+GAodd1n0D/MnxJ6dKYWVF9FxoMXTs5Y3eHpOV7
89fMFX9HWTSlnzhrOg0P/aG4dSOOR6akW8ylpU7boUS6DaBxxMJekOWESCHWEQrzn70HBv
5ihNpQSBBGrihwlPeucWrIbfs1cpCeRZmdd+vz3IZR7tcL/yOMlI07ErjSGV67RdwNeNUK
PWMnGW9+vj1d087Y7Ud3G6Yh5wpDwJT0EFY3R17rwnFl3HVlc/6AnJ+PRAZGPQqrjuWfQA
bZxCUjGZQQAAA+BYHEUvWBxFLwAAAAdzc2gtcnNhAAABAQC/CbjTtWSEAtihrR5mSuHzL6
7Cerfcjxn49MJ4NGo5wx2MxZVwkt8oxjKOndswMWSv8PGUW/vtZKRWdBaJwT4YCh13WfQP
8yfEnp0phZUX0XGgxdOz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xSpSL2y09FE453PrElR/4lsV+ThqV88HOOGn3P2CA+unr1C+JZqbn58dkWfYiy7
OabSXAh3hqEkQisAAAAodG9iaWFzQHBmYW5kemVsdGVyLW1hYy5lY2RmLnR1LWJlcmxpbi
5kZQECAw==
-----END OPENSSH PRIVATE KEY-----
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/CbjTtWSEAtihrR5mSuHzL67Cerfcjxn49MJ4NGo5wx2MxZVwkt8oxjKOndswMWSv8PGUW/vtZKRWdBaJwT4YCh13WfQP8yfEnp0phZUX0XGgxdOzljd4ek5Xvz18wVf0dZNKWfOGs6DQ/9obh1I45HpqRbzKWlTtuhRLoNoHHEwl6Q5YRIIdYRCvOfvQcG/mKE2lBIEEauKHCU965xasht+zVykJ5FmZ136/PchlHu1wv/I4yUjTsSuNIZXrtF3A141Qo9YycZb36+PV3TztjtR3cbpiHnCkPAlPQQVjdHXuvCcWXcdWVz/oCcn49EBkY9CquO5Z9ABtnEJSMZlB tobias@pfandzelter-mac.ecdf.tu-berlin.de
variable "aws_access_key" {
description = "The AWS access key."
default = "XYXYXACCESSKEYXYXYX"
}
variable "aws_secret_key" {
description = "The AWS secret key."
default = "XYXYSUPERSECRETKEYXYXYX"
}
variable "gitlab_repo_username" {
description = "The username for the GitLab registry."
default = "XYXYSUPERSECRETKEYXYXYX"
}
variable "gitlab_repo_password" {
description = "The password for the GitLab registry."
default = "XYXYSUPERSECRETKEYXYXYX"
}
variable "aws_region" {
type = string
default = "eu-central-1"
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment