From 37db557ec1f4dde3325db0f45ea007d030ba2d1e Mon Sep 17 00:00:00 2001 From: Alexandre NICOLAIE Date: Sun, 6 Aug 2023 16:52:57 +0200 Subject: [PATCH 1/3] fix(github-actions): remove all comments mechanisms Commenting all PR seems to be a good idea at the beginning, but any fork running these workflows fail because they didn't have right to create PR comments on this repository. So, just running workflows should be enough to check if the changes are valid. --- .../terraform.lint.pull_request.yaml | 24 +++++++ .github/workflows/terraform.lint.yaml | 63 +++++++++++++------ ....yaml => terraform.plan.pull_request.yaml} | 0 3 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/terraform.lint.pull_request.yaml rename .github/workflows/{terraform.plan.yaml => terraform.plan.pull_request.yaml} (100%) diff --git a/.github/workflows/terraform.lint.pull_request.yaml b/.github/workflows/terraform.lint.pull_request.yaml new file mode 100644 index 0000000..5da9791 --- /dev/null +++ b/.github/workflows/terraform.lint.pull_request.yaml @@ -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 diff --git a/.github/workflows/terraform.lint.yaml b/.github/workflows/terraform.lint.yaml index 53b0963..41ddfc9 100644 --- a/.github/workflows/terraform.lint.yaml +++ b/.github/workflows/terraform.lint.yaml @@ -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 }} diff --git a/.github/workflows/terraform.plan.yaml b/.github/workflows/terraform.plan.pull_request.yaml similarity index 100% rename from .github/workflows/terraform.plan.yaml rename to .github/workflows/terraform.plan.pull_request.yaml From 66f7cade5d74c9a2c617b9ae41c5f1bdcaf701d9 Mon Sep 17 00:00:00 2001 From: Alexandre NICOLAIE Date: Sun, 6 Aug 2023 17:00:04 +0200 Subject: [PATCH 2/3] test --- .github/workflows/terraform.test.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/workflows/terraform.test.yaml diff --git a/.github/workflows/terraform.test.yaml b/.github/workflows/terraform.test.yaml new file mode 100644 index 0000000..4281355 --- /dev/null +++ b/.github/workflows/terraform.test.yaml @@ -0,0 +1,11 @@ +name: vagrant-up + +on: [push] + +jobs: + vagrant-up: + runs-on: ubuntu-latest + + steps: + - name: Show Vagrant version + run: vagrant --version From 49bd7c7b1341eb729c70ee477cc283c64d22aece Mon Sep 17 00:00:00 2001 From: Alexandre Nicolaie Date: Sun, 3 Sep 2023 16:11:48 +0200 Subject: [PATCH 3/3] lab(vagrant): try Vagrant in CI --- .github/workflows/terraform.test.yaml | 16 +++++++++++++++- examples/vagrant-k3s/VagrantFile | 26 ++++++++++++++++++++++++++ examples/vagrant-k3s/main.tf | 11 +++++++++++ examples/vagrant-k3s/versions.tf | 8 ++++++++ 4 files changed, 60 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..e91f608 100644 --- a/.github/workflows/terraform.test.yaml +++ b/.github/workflows/terraform.test.yaml @@ -2,10 +2,24 @@ 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: "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 diff --git a/examples/vagrant-k3s/VagrantFile b/examples/vagrant-k3s/VagrantFile new file mode 100644 index 0000000..2acf254 --- /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/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 \ 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..4c3a8d1 --- /dev/null +++ b/examples/vagrant-k3s/main.tf @@ -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 +} 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" + } + } +}