bitwarden deployment

This commit is contained in:
Julian Tölle 2019-01-30 19:49:47 +01:00
commit 42ec743a00
24 changed files with 498 additions and 0 deletions

20
modules/docker_node/main.tf Executable file
View file

@ -0,0 +1,20 @@
resource "hcloud_server" "node" {
name = "${var.name}"
image = "${var.image}"
server_type = "${var.server_type}"
location = "${var.location}"
ssh_keys = ["${var.ssh_key_id}"]
connection {
private_key = "${file("./keys/id_terraform")}"
}
provisioner "remote-exec" {
scripts = [
"modules/docker_node/scripts/wait-cloud-init.sh",
"modules/docker_node/scripts/install-docker.sh",
"modules/docker_node/scripts/install-docker-compose.sh",
]
}
}

7
modules/docker_node/outputs.tf Executable file
View file

@ -0,0 +1,7 @@
output ip {
value = "${hcloud_server.node.ipv4_address}"
}
output id {
value = "${hcloud_server.node.id}"
}

View file

@ -0,0 +1,3 @@
curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

View file

@ -0,0 +1,28 @@
#!/bin/bash
set -e
# Source: https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-using-the-repository
echo "# apt-get update"
apt-get update
echo "# apt-get upgrade -y"
DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' upgrade
# Add Repository
echo "# apt-get install"
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
echo "# apt-get update"
apt-get update
# Install Docker
echo "# apt-get install docker-ce"
apt-get install -y docker-ce

View file

@ -0,0 +1,13 @@
# cloud-init is running at boot time and blocking access to apt.
# Before doing anything we should wait for it to finish.
# cloud-init creates a file after finishing boot.
echo "Waiting for cloud-init to finish provisioning the instance."
while [ ! -f /var/lib/cloud/instance/boot-finished ]
do
echo "#"
sleep 2
done
# Wait some more to be sure
sleep 10

22
modules/docker_node/vars.tf Executable file
View file

@ -0,0 +1,22 @@
variable name {
type = "string"
}
variable image {
type = "string"
default = "ubuntu-18.04"
}
variable server_type {
type = "string"
default = "cx11"
}
variable location {
type = "string"
default = "nbg1"
}
variable ssh_key_id {
type = "string"
}

View file

@ -0,0 +1,4 @@
auto eth0:1
iface eth0:1 inet static
address ${FLOATING_IP}
netmask 255.255.255.255

48
modules/floating_ip/main.tf Executable file
View file

@ -0,0 +1,48 @@
#################
### IP ADDRESS ##
#################
resource hcloud_floating_ip main {
type = "${var.type}"
description = "${var.host}"
home_location = "${var.location}"
}
resource "hcloud_rdns" "main" {
floating_ip_id = "${hcloud_floating_ip.main.id}"
ip_address = "${hcloud_floating_ip.main.ip_address}"
dns_ptr = "${var.host}"
}
###################################
### ASSIGNMENT AND PROVISIONING ###
###################################
data "template_file" "network_config" {
template = "${file("modules/floating_ip/files/99-floating.cfg")}"
vars {
FLOATING_IP = "${hcloud_floating_ip.main.ip_address}"
}
}
resource hcloud_floating_ip_assignment main {
floating_ip_id = "${hcloud_floating_ip.main.id}"
server_id = "${var.server_id}"
connection = {
host = "${var.server_ip}"
private_key = "${file("keys/id_terraform")}"
}
provisioner file {
content = "${data.template_file.network_config.rendered}"
destination = "/etc/network/interfaces.d/99-floating.cfg"
}
provisioner remote-exec {
inline = [
"ifdown eth0:1 ; ifup eth0:1",
]
}
}

3
modules/floating_ip/outputs.tf Executable file
View file

@ -0,0 +1,3 @@
output ip {
value = "${hcloud_floating_ip.main.ip_address}"
}

21
modules/floating_ip/vars.tf Executable file
View file

@ -0,0 +1,21 @@
variable host {
type = "string"
}
variable type {
type = "string"
default = "ipv4"
}
variable server_id {
type = "string"
}
variable server_ip {
type = "string"
}
variable location {
type = "string"
default = "nbg1"
}