add terragorm provissionning for VPS

This commit is contained in:
vincent 2022-06-19 16:04:32 +02:00
parent d1b0144e68
commit 8ddbc8a3fc
5 changed files with 59 additions and 0 deletions

13
infra/output.tf Normal file
View File

@ -0,0 +1,13 @@
output "homelab_servers_status" {
value = {
for server in hcloud_server.HomeLab :
server.name => server.status
}
}
output "homelab_servers_ips" {
value = {
for server in hcloud_server.HomeLab :
server.name => server.ipv4_address
}
}

12
infra/providers.tf Normal file
View File

@ -0,0 +1,12 @@
terraform {
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
}
}
required_version = ">= 0.13"
}
provider "hcloud" {
token = var.hcloud_token
}

11
infra/server.tf Normal file
View File

@ -0,0 +1,11 @@
resource "hcloud_server" "HomeLab" {
count = var.instances
name = "random"
image = var.os_type
server_type = var.server_type
location = var.location
ssh_keys = [hcloud_ssh_key.default.id]
labels = {
}
}

4
infra/ssh.tf Normal file
View File

@ -0,0 +1,4 @@
resource "hcloud_ssh_key" "default" {
name = "hetzner_key"
public_key = file("~/.ssh/id_rsa.pub")
}

19
infra/variable.tf Normal file
View File

@ -0,0 +1,19 @@
variable "hcloud_token" {
# default = <your-api-token>
}
variable "location" {
default = "hel1"
}
variable "instances" {
default = "1"
}
variable "server_type" {
default = "cpx11"
}
variable "os_type" {
default = "rocky-8"
}