Files
Webseite_Stines/terraform/main.tf
T

63 lines
1.2 KiB
Terraform

terraform {
required_providers {
proxmox = {
source = "telmate/proxmox"
version = "~> 2.9"
}
}
}
provider "proxmox" {
pm_api_url = var.proxmox_host
pm_api_token_id = var.proxmox_token_id
pm_api_token_secret = var.proxmox_token_secret
pm_tls_insecure = true
}
resource "proxmox_lxc" "staging" {
target_node = var.proxmox_node
hostname = "hugo-staging"
ostemplate = var.lxc_ostemplate
unprivileged = true
start = true
onboot = false
cores = 1
memory = 512
swap = 512
rootfs {
storage = var.lxc_storage
size = "8G"
}
network {
name = "eth0"
bridge = "vmbr2"
ip = var.staging_ip
gw = var.staging_gw != "" ? var.staging_gw : null
}
ssh_public_keys = var.ssh_public_key
provisioner "remote-exec" {
inline = [
"apt-get update -qq",
"apt-get install -y nginx",
"systemctl enable --now nginx",
"mkdir -p /var/www/html",
"chown -R www-data:www-data /var/www/html"
]
connection {
type = "ssh"
user = "root"
private_key = file("~/.ssh/deploy_key")
host = self.network[0].ip
}
}
}
output "staging_ip" {
value = proxmox_lxc.staging.network[0].ip
}