Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add E2E tests directly into Github Actions #134

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/terraform.lint.pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Terraform HCL validation (PRs only)

on:
pull_request:
paths: ["**.tf"]

jobs:
terraform-module-k3s:
name: Validate main Terraform module
uses: ./.github/worflows/terraform.lint.yaml

examples_hcloud-k3s:
name: Hetzner Cloud
needs: [terraform-module-k3s]
uses: ./.github/worflows/terraform.lint.yaml
with:
terraform_workdir: examples/hcloud-k3s

examples_civo-k3s:
name: CIVO
needs: [terraform-module-k3s]
uses: ./.github/worflows/terraform.lint.yaml
with:
terraform_workdir: examples/civo-k3s
63 changes: 43 additions & 20 deletions .github/workflows/terraform.lint.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
name: Terraform HCL validation (PRs only)
---
name: Terraform HCL validation

on:
pull_request:
paths: ["**.tf"]
workflow_call:
inputs:
terraform_workdir:
description: Working directory where Terraform files are
required: false
default: "."
type: string

permissions:
pull-requests: write
env:
TF_IN_AUTOMATION: "yes"

jobs:
terraform-module-k3s:
name: Terraform module
uses: xunleii/github-actions-grimoire/.github/workflows/terraform.pull_requests.lint.yaml@0ab2cd93e86642397ecdfb2da1e5b97594ab9905
# Checks if your TF files are in a canonical format and without HCL issues
terraform_validate:
name: Terraform files validation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3.1.0
- uses: hashicorp/setup-terraform@bbe167fbdaa1a3bd046bdd70eba9dd3dddcca99c # tag=v2.0.2
with:
terraform_version: ${{ inputs.terraform_version }}
- uses: terraform-linters/setup-tflint@ba6bb2989f94daf58a4cc6eac2c1ca7398a678bf # tag=v3.0.0

examples_hcloud-k3s:
name: Hetzner Cloud
needs: [terraform-module-k3s]
uses: xunleii/github-actions-grimoire/.github/workflows/terraform.pull_requests.lint.yaml@0ab2cd93e86642397ecdfb2da1e5b97594ab9905
with:
terraform_workdir: examples/hcloud-k3s
# --- `terraform fmt`
- name: Check if all Terraform configuration files are in a canonical format ${{ steps.pre.outputs.workdir }}
id: fmt
run: terraform fmt -check -recursive -diff -no-color
working-directory: ${{ inputs.terraform_workdir }}

examples_civo-k3s:
name: CIVO
needs: [terraform-module-k3s]
uses: xunleii/github-actions-grimoire/.github/workflows/terraform.pull_requests.lint.yaml@0ab2cd93e86642397ecdfb2da1e5b97594ab9905
with:
terraform_workdir: examples/civo-k3s
# --- `terraform init`
- name: Initialize Terraform working directory ${{ steps.pre.outputs.workdir }}
id: init
run: terraform init -no-color -backend=false
working-directory: ${{ inputs.terraform_workdir }}

# --- `terraform validate`
- name: Validate the configuration files ${{ steps.pre.outputs.workdir }}
id: validate
run: terraform validate -no-color
working-directory: ${{ inputs.terraform_workdir }}

# --- `terraform lint`
- name: Lint the configuration files ${{ steps.pre.outputs.workdir }}
id: lint
run: tflint --format compact
working-directory: ${{ inputs.terraform_workdir }}
25 changes: 25 additions & 0 deletions .github/workflows/terraform.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: vagrant-up

on: [push]

defaults:
run:
working-directory: examples/vagrant-k3s

jobs:
vagrant-up:
runs-on: macos-12

steps:
- name: "Checkout"
uses: actions/checkout@v3
- name: Show Vagrant version
run: vagrant --version
- uses: hashicorp/setup-terraform@v2
- run: vagrant up
# - run: terraform init
# - run: terraform apply -auto-approve
# env:
# TF_LOG: TRACE
# - 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/ubuntu2204'
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 = vagrant_vm.k3s_nodes.ssh_config
}

output "debug_ports" {
value = 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"
}
}
}
Loading