Skip to content

Commit

Permalink
Merge pull request #14 from stuttgart-things/feature/issue-1/vmTest-p…
Browse files Browse the repository at this point in the history
…ipeline

Checkout in dir
  • Loading branch information
anacalva authored Mar 27, 2024
2 parents ef85a94 + 466dc48 commit 1f2ae31
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 229 deletions.
80 changes: 38 additions & 42 deletions .github/workflows/vm-creation-terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
def write_file(testVars, output_file_name):
environment = Environment(loader=FileSystemLoader("tests/templates/"))
template = environment.get_template("module.tpl")
filename = "terraform.tfvars"
filename = "main.tf"
content = template.render(
name = output_file_name,
vm_count = random.choice(testVars['vm_count']),
Expand Down Expand Up @@ -74,11 +74,11 @@ jobs:
main()
- name: Upload main.tf file for job 2
- name: Upload main file for job 2
uses: actions/upload-artifact@v4
with:
name: terraform_vars
path: terraform.tfvars
name: terraform_main
path: main.tf

test-terraform-apply:
needs: build-terraform-file
Expand All @@ -89,13 +89,16 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
path: "./tests"

- name: Download main
uses: actions/download-artifact@v4
with:
name: terraform_vars
name: terraform_main

- run: |
- name: Run teraform init, plan and apply
run: |
terraform init
terraform plan -var="pve_api_url=${{ secrets.PVE_API_URL }}" -var="pve_api_user=${{ secrets.PVE_API_USER }}" -var="pve_api_password=${{ secrets.PVE_API_PASSWORD }}" -var="vm_ssh_user=${{ secrets.VM_SSH_USER }}" -var="vm_ssh_password=${{ secrets.VM_SSH_PASSWORD }}" -var="pve_api_tls_verify=${{ vars.PVE_API_TLS_VERIFY }}"
terraform apply --auto-approve -var="pve_api_url=${{ secrets.PVE_API_URL }}" -var="pve_api_user=${{ secrets.PVE_API_USER }}" -var="pve_api_password=${{ secrets.PVE_API_PASSWORD }}" -var="vm_ssh_user=${{ secrets.VM_SSH_USER }}" -var="vm_ssh_password=${{ secrets.VM_SSH_PASSWORD }}" -var="pve_api_tls_verify=${{ vars.PVE_API_TLS_VERIFY }}"
Expand All @@ -107,42 +110,35 @@ jobs:
name: terraform_state
path: terraform.tfstate

- name: Run in Python Terraform Destroy
- name: Run Terraform Destroy
run: |
terraform destroy --auto-approve -var="pve_api_url=${{ secrets.PVE_API_URL }}" -var="pve_api_user=${{ secrets.PVE_API_USER }}" -var="pve_api_password=${{ secrets.PVE_API_PASSWORD }}" -var="vm_ssh_user=${{ secrets.VM_SSH_USER }}" -var="vm_ssh_password=${{ secrets.VM_SSH_PASSWORD }}" -var="pve_api_tls_verify=${{ vars.PVE_API_TLS_VERIFY }}"
cleanup:
if: ${{ always() }}
needs: test-terraform-apply
runs-on: ghr-proxmox-vm-sthings-cicd
environment: k8s
container:
image: hashicorp/terraform:1.6
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
path: "./tests"

- name: Download tfstate
uses: actions/download-artifact@v4
with:
name: terraform_state

- name: Download main
uses: actions/download-artifact@v4
with:
name: terraform_main

- name: Run Terraform Destroy
run: |
terraform init
terraform destroy --auto-approve -var="pve_api_url=${{ secrets.PVE_API_URL }}" -var="pve_api_user=${{ secrets.PVE_API_USER }}" -var="pve_api_password=${{ secrets.PVE_API_PASSWORD }}" -var="vm_ssh_user=${{ secrets.VM_SSH_USER }}" -var="vm_ssh_password=${{ secrets.VM_SSH_PASSWORD }}" -var="pve_api_tls_verify=${{ vars.PVE_API_TLS_VERIFY }}"
# cleanup:
# if: ${{ always() }}
# needs: test-terraform-apply
# runs-on: self-hosted
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# with:
# node-version: 20
#
# - name: Setup Python
# uses: actions/setup-python@v5
# with:
# python-version: '3.10'
#
# - uses: hashicorp/setup-terraform@v3
#
# - name: Install dependencies
# run: |
# python -m pip install github-action-utils python-terraform
#
# - name: Download tfstate
# uses: actions/download-artifact@v4
# with:
# name: terraform_state
#
# - name: Download main
# uses: actions/download-artifact@v4
# with:
# name: terraform_main
#
# - name: Run Python Terraform Destroy
# run: |
# python3 tests/terraform_destroy.py
41 changes: 0 additions & 41 deletions tests/build_tf_file.py

This file was deleted.

59 changes: 0 additions & 59 deletions tests/templates/module copy.tpl

This file was deleted.

69 changes: 58 additions & 11 deletions tests/templates/module.tpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,58 @@
pve_cluster_node = "sthings-pve1"
pve_datastore = "{{ pve_datastore }}"
pve_folder_path = "stuttgart-things"
pve_network = "vmbr103"
vm_count = {{ vm_count }}
vm_name = "{{ name }}"
vm_notes = "vm-info"
vm_template = "ubuntu22"
vm_num_cpus = "{{ vm_num_cpus }}"
vm_memory = "4096"
vm_disk_size = "32G"
module "proxmox-vm" {
source = "git::https://github.com/stuttgart-things/proxmox-vm.git"
pve_api_url = var.pve_api_url
pve_api_user = var.pve_api_user
pve_api_password = var.pve_api_password
pve_api_tls_verify = var.pve_api_tls_verify
pve_cluster_node = "sthings-pve1"
pve_datastore = "{{ pve_datastore }}"
pve_folder_path = "stuttgart-things"
pve_network = "vmbr103"
vm_count = {{ vm_count }}
vm_name = "{{ name }}"
vm_notes = "vm-info"
vm_template = "ubuntu22"
vm_num_cpus = "{{ vm_num_cpus }}"
vm_memory = "4096"
vm_disk_size = "32G"
vm_ssh_user = var.vm_ssh_user
vm_ssh_password = var.vm_ssh_password
}

output "ip" {
value = module.proxmox-vm.ip
}

output "mac" {
value = module.proxmox-vm.mac
}

output "id" {
value = module.proxmox-vm.id
}


variable "pve_api_url" {
description = "url of proxmox api"
}

variable "pve_api_user" {
description = "username of proxmox api user"
}

variable "pve_api_password" {
description = "password of proxmox api user"
}

variable "vm_ssh_user" {
description = "username of proxmox api user"
}

variable "vm_ssh_password" {
description = "password of proxmox api user"
}

variable "pve_api_tls_verify" {
description = "proxmox API disable check if cert is valid"
}
53 changes: 0 additions & 53 deletions tests/terraform_apply.py

This file was deleted.

23 changes: 0 additions & 23 deletions tests/terraform_destroy.py

This file was deleted.

0 comments on commit 1f2ae31

Please sign in to comment.