Skip to content

Commit

Permalink
lab(vagrant): try Vagrant in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
xunleii committed Sep 3, 2023
1 parent 66f7cad commit 9a2df6e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
11 changes: 10 additions & 1 deletion .github/workflows/terraform.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 26 additions & 0 deletions examples/vagrant-k3s/VagrantFile
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions examples/vagrant-k3s/main.tf
Original file line number Diff line number Diff line change
@@ -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)
}
8 changes: 8 additions & 0 deletions examples/vagrant-k3s/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
vagrant = {
source = "bmatcuk/vagrant"
version = "4.1.0"
}
}
}

0 comments on commit 9a2df6e

Please sign in to comment.