This commit is contained in:
Bartosz Karwacki 2022-01-05 00:43:50 +01:00
parent fde4a2c7d2
commit 886a763d21
5 changed files with 104 additions and 0 deletions

View File

@ -2,14 +2,25 @@
## Potrzeba
- Docker
### AWS
- Credentials aws w ~/.aws
### Hetzner
- API KEY
#### Zad 4.1
##### AWS
```
cd zad_4_1
./deploy.sh
```
#### Hetzner
```
cd zad_4_1_hetz
./deploy.sh [API KEY]
```
#### Zad 4.2
```

6
zad_4_1_hetz/Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM hashicorp/terraform:latest
COPY user_data user_data
COPY main.tf main.tf
ENTRYPOINT terraform init && terraform apply -var="token=${token}" -auto-approve && sleep 300 && terraform destroy -var="token=${token}" -auto-approve

5
zad_4_1_hetz/deploy.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
token=$1
docker build -t lb-hetzner .
docker run -e token=${1} lb-hetzner

75
zad_4_1_hetz/main.tf Normal file
View File

@ -0,0 +1,75 @@
terraform {
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
version = "1.32.1"
}
}
}
variable "token" {
type = string
}
provider "hcloud" {
token = var.token
}
resource "hcloud_server" "ubuntu_server" {
count = 2
name = "bk-terraform-server-${count.index}"
image = "ubuntu-20.04"
server_type = "cx11"
network {
network_id = hcloud_network.network.id
}
user_data = file("user_data")
}
resource "hcloud_network" "network" {
name = "bk-terraform-network"
ip_range = "10.0.1.0/24"
}
resource "hcloud_network_subnet" "subnet" {
network_id = hcloud_network.network.id
type = "cloud"
network_zone = "eu-central"
ip_range = "10.0.1.0/24"
}
resource "hcloud_load_balancer" "load_balancer" {
name = "bk-terraform-balancer"
load_balancer_type = "lb11"
location = "hel1"
}
resource "hcloud_load_balancer_service" "load_balancer_service" {
load_balancer_id = hcloud_load_balancer.load_balancer.id
protocol = "tcp"
listen_port = 8080
destination_port = 8080
}
resource "hcloud_load_balancer_network" "srvnetwork" {
load_balancer_id = hcloud_load_balancer.load_balancer.id
network_id = hcloud_network.network.id
ip = "10.0.1.25"
}
resource "hcloud_load_balancer_target" "load_balancer_target" {
count = 2
type = "server"
load_balancer_id = hcloud_load_balancer.load_balancer.id
server_id = hcloud_server.ubuntu_server[count.index].id
}
output "link" {
value = "http://${hcloud_load_balancer.load_balancer.ipv4}:8080/"
}

7
zad_4_1_hetz/user_data Normal file
View File

@ -0,0 +1,7 @@
#cloud-config
packages:
- git
runcmd:
- git clone https://git.wmi.amu.edu.pl/s470611/DPZC-aws
- ./DPZC-aws/webservice