generated from CC/VMServiceTemplate
Initial commit
This commit is contained in:
18
terraform/backend.tf
Normal file
18
terraform/backend.tf
Normal file
@@ -0,0 +1,18 @@
|
||||
terraform {
|
||||
backend "s3" {
|
||||
bucket = "terraform"
|
||||
key = "template/terraform.tfstate"
|
||||
access_key = "GK242d456c0692a9d4cc102206"
|
||||
secret_key = "1d7e22b7a8892cb11b569017659aa511b37b53287c4d1699c310d9f8ac76df09"
|
||||
region = "garage"
|
||||
endpoints = {
|
||||
s3 = "http://192.168.10.109:3900"
|
||||
}
|
||||
skip_credentials_validation = true
|
||||
skip_requesting_account_id = true
|
||||
skip_metadata_api_check = true
|
||||
skip_region_validation = true
|
||||
use_path_style = true
|
||||
use_lockfile = true
|
||||
}
|
||||
}
|
||||
25
terraform/main.tf
Normal file
25
terraform/main.tf
Normal file
@@ -0,0 +1,25 @@
|
||||
locals {
|
||||
instance_map = var.instance_mode == "single" ? {
|
||||
main = var.instance
|
||||
} : var.instances
|
||||
}
|
||||
|
||||
module "vm" {
|
||||
for_each = local.instance_map
|
||||
source = "git::https://tea.charcarservices.uk/CC/TerraformModules.git//proxmox_ubuntu_cloudinit_template?ref=main"
|
||||
|
||||
vm_name = each.value.vm_name
|
||||
node_name = each.value.node_name
|
||||
node_datastore = var.vm_defaults.node_datastore
|
||||
bridge = var.vm_defaults.bridge
|
||||
vm_cpu = coalesce(try(each.value.vm_cpu, null), var.vm_defaults.vm_cpu)
|
||||
vm_ram = coalesce(try(each.value.vm_ram, null), var.vm_defaults.vm_ram)
|
||||
vm_size = coalesce(try(each.value.vm_size, null), var.vm_defaults.vm_size)
|
||||
vm_bios = var.vm_defaults.vm_bios
|
||||
vm_machine = var.vm_defaults.vm_machine
|
||||
vm_tags = concat(
|
||||
try(each.value.vm_tags, []),
|
||||
["terraform", "docker", each.value.service_name]
|
||||
)
|
||||
vm_user_sshkey = var.vm_defaults.vm_user_sshkey
|
||||
}
|
||||
21
terraform/multi.tfvars.example
Normal file
21
terraform/multi.tfvars.example
Normal file
@@ -0,0 +1,21 @@
|
||||
instance_mode = "multi"
|
||||
|
||||
instances = {
|
||||
grafana = {
|
||||
service_name = "grafana"
|
||||
vm_name = "grafana-01"
|
||||
node_name = "pop"
|
||||
app_port = 3000
|
||||
app_image = "grafana/grafana:latest"
|
||||
vm_tags = ["monitoring"]
|
||||
}
|
||||
|
||||
caddy = {
|
||||
service_name = "caddy"
|
||||
vm_name = "caddy-01"
|
||||
node_name = "pop"
|
||||
app_port = 80
|
||||
app_image = "caddy:latest"
|
||||
vm_tags = ["proxy"]
|
||||
}
|
||||
}
|
||||
20
terraform/output.tf
Normal file
20
terraform/output.tf
Normal file
@@ -0,0 +1,20 @@
|
||||
output "vm_ipv4_addresses" {
|
||||
value = {
|
||||
for k, m in module.vm : k => m.vm_ipv4_address
|
||||
}
|
||||
}
|
||||
|
||||
output "vm_tags" {
|
||||
value = {
|
||||
for k, m in module.vm : k => concat(
|
||||
try(local.instance_map[k].vm_tags, []),
|
||||
["terraform", "docker", local.instance_map[k].service_name, "ip-${replace(m.vm_ipv4_address, ".", "-")}"]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
output "service_names" {
|
||||
value = {
|
||||
for k, cfg in local.instance_map : k => cfg.service_name
|
||||
}
|
||||
}
|
||||
33
terraform/providers.tf
Normal file
33
terraform/providers.tf
Normal file
@@ -0,0 +1,33 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
proxmox = {
|
||||
source = "bpg/proxmox"
|
||||
version = "0.106.0"
|
||||
#url = https://registry.terraform.io/providers/bpg/proxmox/latest/docs/guides/clone-vm
|
||||
}
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = "6.38.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "proxmox" {
|
||||
endpoint = var.pm_api_url
|
||||
api_token = var.pm_api_token
|
||||
insecure = true
|
||||
|
||||
# === FIX THIS ===
|
||||
ssh {
|
||||
agent = true
|
||||
username = "root"
|
||||
password = "Ishimaru17"
|
||||
}
|
||||
}
|
||||
|
||||
provider "aws" {
|
||||
region = "garage"
|
||||
access_key = "GK242d456c0692a9d4cc102206"
|
||||
secret_key = "1d7e22b7a8892cb11b569017659aa511b37b53287c4d1699c310d9f8ac76df09"
|
||||
# shared_credentials_files = ["$HOME/.aws/credentials"]
|
||||
}
|
||||
21
terraform/single.tfvars.example
Normal file
21
terraform/single.tfvars.example
Normal file
@@ -0,0 +1,21 @@
|
||||
instance_mode = "single"
|
||||
|
||||
instance = {
|
||||
service_name = "grafana"
|
||||
vm_name = "grafana-01"
|
||||
node_name = "pop"
|
||||
app_port = 3000
|
||||
app_image = "grafana/grafana:latest"
|
||||
vm_tags = ["monitoring"]
|
||||
}
|
||||
|
||||
vm_defaults = {
|
||||
node_datastore = "hlst"
|
||||
vm_bios = "ovmf"
|
||||
vm_machine = "q35"
|
||||
vm_user_sshkey = "ssh-ed25519 AAAA..."
|
||||
bridge = "vmbr0"
|
||||
vm_cpu = 2
|
||||
vm_ram = 4096
|
||||
vm_size = "20G"
|
||||
}
|
||||
59
terraform/variables.tf
Normal file
59
terraform/variables.tf
Normal file
@@ -0,0 +1,59 @@
|
||||
variable "instance_mode" {
|
||||
type = string
|
||||
default = "single"
|
||||
}
|
||||
|
||||
variable "instance" {
|
||||
description = "Single instance definition"
|
||||
type = object({
|
||||
service_name = string
|
||||
vm_name = string
|
||||
node_name = string
|
||||
vm_cpu = optional(number)
|
||||
vm_ram = optional(number)
|
||||
vm_size = optional(string)
|
||||
app_port = number
|
||||
app_image = string
|
||||
vm_tags = optional(list(string))
|
||||
})
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "instances" {
|
||||
description = "Multiple instance definitions"
|
||||
type = map(object({
|
||||
service_name = string
|
||||
vm_name = string
|
||||
node_name = string
|
||||
vm_cpu = optional(number)
|
||||
vm_ram = optional(number)
|
||||
vm_size = optional(string)
|
||||
app_port = number
|
||||
app_image = string
|
||||
vm_tags = optional(list(string))
|
||||
}))
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "vm_defaults" {
|
||||
type = object({
|
||||
node_datastore = string
|
||||
vm_bios = string
|
||||
vm_machine = string
|
||||
vm_user_sshkey = string
|
||||
bridge = string
|
||||
vm_cpu = number
|
||||
vm_ram = number
|
||||
vm_size = string
|
||||
})
|
||||
default = {
|
||||
node_datastore = "hlst"
|
||||
vm_bios = "ovmf"
|
||||
vm_machine = "q35"
|
||||
vm_user_sshkey = ""
|
||||
bridge = "vmbr0"
|
||||
vm_cpu = 1
|
||||
vm_ram = 2048
|
||||
vm_size = "20G"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user