init vscode

This commit is contained in:
Bartosz Karwacki 2021-11-30 08:41:36 +01:00
parent b7d560edcd
commit 63efe9bc09
4 changed files with 75 additions and 0 deletions

6
hetzner_3_4/Dockerfile Normal file
View File

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

5
hetzner_3_4/deploy.sh Executable file
View File

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

20
hetzner_3_4/init-server Normal file
View File

@ -0,0 +1,20 @@
#cloud-config
packages:
- curl
write_files:
- path: /root/install.sh
content: |
curl -fsSL https://code-server.dev/install.sh > /root/install.sh
- path: /root/config.yml
content: |
bind-addr: 0.0.0.0
port: 80
password: password
cert: false
runcmd:
- cd /root/
- chmod +x install.sh
- ./install.sh
- code-server --config config.yml

44
hetzner_3_4/main.tf Normal file
View File

@ -0,0 +1,44 @@
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" {
name = "bk-terraform-server"
image = "ubuntu-20.04"
server_type = "cx11"
network {
network_id = hcloud_network.network.id
}
user_data = file("init-server")
}
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"
}
output "link" {
value = "http://${hcloud_server.ubuntu_server.ipv4_address}"
}