From 9a2df6eab7f7715216006c19541bb56bebf24ed1 Mon Sep 17 00:00:00 2001 From: Alexandre Nicolaie Date: Sun, 3 Sep 2023 16:11:48 +0200 Subject: [PATCH] lab(vagrant): try Vagrant in CI --- .github/workflows/terraform.test.yaml | 11 ++++++++++- examples/vagrant-k3s/VagrantFile | 26 ++++++++++++++++++++++++++ examples/vagrant-k3s/main.tf | 11 +++++++++++ examples/vagrant-k3s/versions.tf | 8 ++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 examples/vagrant-k3s/VagrantFile create mode 100644 examples/vagrant-k3s/main.tf create mode 100644 examples/vagrant-k3s/versions.tf diff --git a/.github/workflows/terraform.test.yaml b/.github/workflows/terraform.test.yaml index 4281355..643147f 100644 --- a/.github/workflows/terraform.test.yaml +++ b/.github/workflows/terraform.test.yaml @@ -2,10 +2,19 @@ name: vagrant-up on: [push] +defaults: + run: + working-directory: ./examples/vagrant-k3s + jobs: vagrant-up: - runs-on: ubuntu-latest + runs-on: macos-12 steps: - name: Show Vagrant version run: vagrant --version + - uses: hashicorp/setup-terraform@v2 + - run: terraform init + - run: terraform apply -auto-approve + - run: terraform output -json + - run: terraform destroy -auto-approve diff --git a/examples/vagrant-k3s/VagrantFile b/examples/vagrant-k3s/VagrantFile new file mode 100644 index 0000000..28891a5 --- /dev/null +++ b/examples/vagrant-k3s/VagrantFile @@ -0,0 +1,26 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : +# + +Vagrant.configure("2") do |config| + config.vm.box = 'generic/alpine313' + config.vm.boot_timeout = ENV['TEST_VM_BOOT_TIMEOUT'] || 600 # seconds + config.vm.synced_folder '.', '/vagrant', disabled: true + + ['k3s:server:01', 'k3s:server:02', 'k3s:server:03', 'k3s:agent:01', 'k3s:agent:02'].each do |name| + config.vm.define name do |vm| + vm.vm.hostname = name + end + end + + %w[libvirt virtualbox vmware_desktop].each do |p| + config.vm.provider p do |v| + v.cpus = ENV['TEST_VM_CPUS'] || 1 + v.memory = ENV['TEST_VM_MEMORY'] || 512 + end + end + config.vm.provider :virtualbox do |v,o| + v.gui = false + v.check_guest_additions = false + end +end \ No newline at end of file diff --git a/examples/vagrant-k3s/main.tf b/examples/vagrant-k3s/main.tf new file mode 100644 index 0000000..7291c6e --- /dev/null +++ b/examples/vagrant-k3s/main.tf @@ -0,0 +1,11 @@ +resource "vagrant_vm" "k3s_nodes" { + get_ports = true +} + +output "debug_sshconfig" { + value = nonsensitive(vagrant_vm.k3s_nodes.ssh_config) +} + +output "debug_ports" { + value = nonsensitive(vagrant_vm.k3s_nodes.ports) +} diff --git a/examples/vagrant-k3s/versions.tf b/examples/vagrant-k3s/versions.tf new file mode 100644 index 0000000..4fc4e5b --- /dev/null +++ b/examples/vagrant-k3s/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + vagrant = { + source = "bmatcuk/vagrant" + version = "4.1.0" + } + } +}