diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c11bc269..10b56d50 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -77,12 +77,13 @@ create: script: - terraform apply -auto-approve rules: - - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' + - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "aaron-dev"' when: on_success - when: never artifacts: paths: - ${TF_ROOT}/.terraform + - ${TF_ROOT}/hosts.ini # Ansible section here run-playbooks: @@ -95,7 +96,7 @@ run-playbooks: script: - echo $(/bin/true) rules: - - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' + - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "aaron-dev"' when: on_success - when: never @@ -109,7 +110,7 @@ destroy: script: - terraform destroy -auto-approve rules: - - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' + - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "aaron-dev"' when: manual - when: never artifacts: diff --git a/terraform/lxc-dhcp.tf b/terraform/lxc-dhcp.tf index d4381623..54ae63d9 100644 --- a/terraform/lxc-dhcp.tf +++ b/terraform/lxc-dhcp.tf @@ -1,13 +1,9 @@ -module "dhcp1" { - source = "./modules/lxc" - cluster_name = "pve1" - ip_address = "${cidrhost(var.subnet, 253)}/${local.cidr_suffix}" - hostname = "dhcp1.${local.domain}" -} - -module "dhcp2" { - source = "./modules/lxc" - cluster_name = "pve2" - ip_address = "${cidrhost(var.subnet, 254)}/${local.cidr_suffix}" - hostname = "dhcp2.${local.domain}" +module "dhcp" { + source = "./modules/lxc" + count = 2 + # This one weird trick. Everyone will hate it. + cluster_name = "pve${count.index % 2 + 1}" + ip_address = cidrhost(var.subnet, 253 + count.index) + cidr_mask = local.cidr_suffix + hostname = "dhcp${floor(count.index + 1)}.${local.domain}" } diff --git a/terraform/lxc-dns.tf b/terraform/lxc-dns.tf new file mode 100644 index 00000000..7f13e687 --- /dev/null +++ b/terraform/lxc-dns.tf @@ -0,0 +1,9 @@ +module "dns" { + source = "./modules/lxc" + count = 2 + # This one weird trick. Everyone will hate it. + cluster_name = "pve${count.index % 2 + 1}" + ip_address = cidrhost(var.subnet, 110 + (count.index * 10)) + cidr_mask = local.cidr_suffix + hostname = "dns${floor(count.index + 1)}.${local.domain}" +} diff --git a/terraform/lxc-graylog.tf b/terraform/lxc-graylog.tf new file mode 100644 index 00000000..7e6a4675 --- /dev/null +++ b/terraform/lxc-graylog.tf @@ -0,0 +1,8 @@ +module "graylog" { + source = "./modules/lxc" + cluster_name = "pve1" + ip_address = cidrhost(var.subnet, 129) + cidr_mask = local.cidr_suffix + hostname = "graylog.${local.domain}" + memory = 4096 +} diff --git a/terraform/lxc-ntp.tf b/terraform/lxc-ntp.tf new file mode 100644 index 00000000..ae308675 --- /dev/null +++ b/terraform/lxc-ntp.tf @@ -0,0 +1,9 @@ +module "ntp" { + source = "./modules/lxc" + count = 2 + # This one weird trick. Everyone will hate it. + cluster_name = "pve${count.index % 2 + 1}" + ip_address = cidrhost(var.subnet, 6 + count.index) + cidr_mask = local.cidr_suffix + hostname = "ntp${floor(count.index + 1)}.${local.domain}" +} diff --git a/terraform/lxc-stackstorm.tf b/terraform/lxc-stackstorm.tf deleted file mode 100644 index c190d1e6..00000000 --- a/terraform/lxc-stackstorm.tf +++ /dev/null @@ -1,12 +0,0 @@ -module "stackstorm1" { - source = "./modules/lxc" - ip_address = "10.101.23.136/24" - hostname = "stackstorm1.dev.magevent.net" -} - -module "stackstorm2" { - source = "./modules/lxc" - cluster_name = "pve2" - ip_address = "10.101.23.137/24" - hostname = "stackstorm2.dev.magevent.net" -} diff --git a/terraform/lxc-tftp.tf b/terraform/lxc-tftp.tf new file mode 100644 index 00000000..ee799898 --- /dev/null +++ b/terraform/lxc-tftp.tf @@ -0,0 +1,7 @@ +module "tftp" { + source = "./modules/lxc" + cluster_name = "pve2" + ip_address = cidrhost(var.subnet, 9) + cidr_mask = local.cidr_suffix + hostname = "tftp.${local.domain}" +} diff --git a/terraform/lxc-zabbix.tf b/terraform/lxc-zabbix.tf new file mode 100644 index 00000000..b203f7fa --- /dev/null +++ b/terraform/lxc-zabbix.tf @@ -0,0 +1,7 @@ +module "zabbix" { + source = "./modules/lxc" + cluster_name = "pve1" + ip_address = cidrhost(var.subnet, 200) + cidr_mask = local.cidr_suffix + hostname = "zabbix.${local.domain}" +} diff --git a/terraform/main.tf b/terraform/main.tf index 54f02065..ecfdcdfc 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -37,3 +37,23 @@ locals { cidr_suffix = element(split("/", var.subnet), 1) domain = "${var.branch}.magevent.net" } + +resource "local_file" "inventory" { + filename = "./hosts.ini" + content = <<-EOF + [dhcp] + ${module.dhcp[0].ip_address} + ${module.dhcp[1].ip_address} + + [dns] + ${module.dns[0].ip_address} + ${module.dns[1].ip_address} + + [ntp] + ${module.ntp[0].ip_address} + ${module.ntp[1].ip_address} + + [tftp] + ${module.tftp.ip_address} + EOF +} diff --git a/terraform/modules/lxc/main.tf b/terraform/modules/lxc/main.tf index 667a324f..0dd04b21 100644 --- a/terraform/modules/lxc/main.tf +++ b/terraform/modules/lxc/main.tf @@ -13,6 +13,7 @@ resource "proxmox_lxc" "lxc-container" { ostemplate = "wowza:vztmpl/ubuntu-20.04-standard_20.04-1_amd64.tar.gz" unprivileged = true hostname = var.hostname + memory = var.memory cores = "1" swap = "512" start = true @@ -31,8 +32,9 @@ EOT name = "eth0" bridge = "vmbr999" tag = "22" - ip = var.ip_address + ip = "${var.ip_address}/${var.cidr_mask}" } + } variable "hostname" { @@ -52,8 +54,23 @@ variable "ip_address" { type = string } +variable "cidr_mask" { + description = "CIDR for IP subnet" + type = string +} + variable "size" { description = "Size of fs in gigabytes" type = string default = "8G" } + +variable "memory" { + description = "Size of memory in megabytes" + type = string + default = "512" +} + +output "ip_address" { + value = var.ip_address +}