Skip to content

Commit

Permalink
optimize terraform file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
git@itrichter.de committed Mar 20, 2022
1 parent 4af781b commit 1d4996d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 46 deletions.
37 changes: 2 additions & 35 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
terraform {
required_providers {
proxmox = {
source = "telmate/proxmox"
version = ">=2.8.0"
}
}
}

provider "proxmox" {
pm_api_url = "https://${var.pm_host}:8006/api2/json"
pm_user = var.pm_user
pm_password = var.pm_password
pm_tls_insecure = var.pm_tls_insecure
pm_parallel = 10
pm_timeout = 600
# pm_debug = true
pm_log_enable = true
pm_log_file = "terraform-plugin-proxmox.log"
pm_log_levels = {
_default = "debug"
_capturelog = ""
}
}

resource "proxmox_vm_qemu" "proxmox_vm_master" {
count = var.num_k3s_masters
name = "k3s-master-${count.index}"
Expand Down Expand Up @@ -65,7 +40,7 @@ resource "proxmox_vm_qemu" "proxmox_vm_workers" {
disk,
network
]
}
}

}

Expand All @@ -83,14 +58,6 @@ resource "local_file" "k8s_file" {
}

resource "local_file" "var_file" {
source = "../inventory/sample/group_vars/all.yml"
source = "../inventory/sample/group_vars/all.yml"
filename = "../inventory/my-cluster/group_vars/all.yml"
}

output "Master-IPS" {
value = ["${proxmox_vm_qemu.proxmox_vm_master.*.default_ipv4_address}"]
}

output "worker-IPS" {
value = ["${proxmox_vm_qemu.proxmox_vm_workers.*.default_ipv4_address}"]
}
8 changes: 8 additions & 0 deletions terraform/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

output "Master-IPS" {
value = ["${proxmox_vm_qemu.proxmox_vm_master.*.default_ipv4_address}"]
}

output "worker-IPS" {
value = ["${proxmox_vm_qemu.proxmox_vm_workers.*.default_ipv4_address}"]
}
24 changes: 24 additions & 0 deletions terraform/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
terraform {
required_providers {
proxmox = {
source = "telmate/proxmox"
version = ">=2.8.0"
}
}
}

provider "proxmox" {
pm_api_url = "https://${var.pm_host}:8006/api2/json"
pm_user = var.pm_user
pm_password = var.pm_password
pm_tls_insecure = var.pm_tls_insecure
pm_parallel = 10
pm_timeout = 600
# pm_debug = true
pm_log_enable = true
pm_log_file = "terraform-plugin-proxmox.log"
pm_log_levels = {
_default = "debug"
_capturelog = ""
}
}
22 changes: 11 additions & 11 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
variable "pm_user" {
description = "The username for the proxmox user"
type = string
sensitive = false
default = "root@pam"
sensitive = false
default = "root@pam"

}
variable "pm_password" {
description = "The password for the proxmox user"
type = string
sensitive = true
sensitive = true
}

variable "pm_tls_insecure" {
description = "Set to true to ignore certificate errors"
type = bool
default = false
type = bool
default = false
}

variable "pm_host" {
Expand All @@ -24,26 +24,26 @@ variable "pm_host" {

variable "pm_node_name" {
description = "name of the proxmox node to create the VMs on"
type = string
default = "pve"
type = string
default = "pve"
}

variable "pvt_key" {}

variable "num_k3s_masters" {
default = 1
default = 1
}

variable "num_k3s_masters_mem" {
default = "4096"
default = "4096"
}

variable "num_k3s_nodes" {
default = 2
default = 2
}

variable "num_k3s_nodes_mem" {
default = "4096"
default = "4096"
}

variable "tamplate_vm_name" {}
Expand Down

0 comments on commit 1d4996d

Please sign in to comment.