From 97cc3536c5a8ddf16f9b1b2ab4b416f50488f869 Mon Sep 17 00:00:00 2001 From: anacalva <132065767+anacalva@users.noreply.github.com> Date: Tue, 12 Mar 2024 10:47:27 +0100 Subject: [PATCH] Revert "Test" --- .github/workflows/pythonaction.yml | 46 ---------- .github/workflows/release-terraform.yaml | 36 ++++++++ .github/workflows/validate-terraform.yaml | 23 +++++ README.md | 1 - tests/pipeline.py | 103 ---------------------- 5 files changed, 59 insertions(+), 150 deletions(-) delete mode 100644 .github/workflows/pythonaction.yml create mode 100644 .github/workflows/release-terraform.yaml create mode 100644 .github/workflows/validate-terraform.yaml delete mode 100644 tests/pipeline.py diff --git a/.github/workflows/pythonaction.yml b/.github/workflows/pythonaction.yml deleted file mode 100644 index d430046..0000000 --- a/.github/workflows/pythonaction.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: run tests/main.py - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - - name: checkout repo content - uses: actions/checkout@v2 # checkout the repository content to github runner - - - name: setup python - uses: actions/setup-python@v4 - with: - python-version: '3.9' # install the python version needed - - - name: install python packages - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - - name: execute py script # run main.py - env: - ENV_VAR_PY: "VENUS" - run: python tests/main.py - - - name: execute py script # run main.py - run: python tests/main.py - - - name: commit files - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add -A - git diff-index --quiet HEAD || (git commit -a -m "updated logs" --allow-empty) - - - name: push changes - uses: ad-m/github-push-action@v0.6.0 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: main diff --git a/.github/workflows/release-terraform.yaml b/.github/workflows/release-terraform.yaml new file mode 100644 index 0000000..bfcd80d --- /dev/null +++ b/.github/workflows/release-terraform.yaml @@ -0,0 +1,36 @@ +--- +name: Validate and Release Terraform Module +on: + workflow_dispatch: + inputs: + release-tag: + required: true + type: string + release-message: + required: true + type: string + +jobs: + Validate-Terraform: + if: github.event.ref == 'refs/heads/main' + name: Valdiate + uses: stuttgart-things/stuttgart-things/.github/workflows/validate-terraform.yaml@main + with: + environment-name: k8s + runs-on: arc-runner-scale-set-proxmox-vm + terraform-version: 1.6 + tflint-version: "v0.50.0" + continue-error: false + + Release-Terraform: + if: github.event.ref == 'refs/heads/main' + name: Release + needs: Validate-Terraform + uses: stuttgart-things/stuttgart-things/.github/workflows/release-terraform.yaml@main + with: + module-name: proxmox-vm + tag-name: "${{ github.event.inputs.release-tag }}" + release-message: "${{ github.event.inputs.release-message }}" + environment-name: k8s + runs-on: arc-runner-scale-set-proxmox-vm + continue-error: false \ No newline at end of file diff --git a/.github/workflows/validate-terraform.yaml b/.github/workflows/validate-terraform.yaml new file mode 100644 index 0000000..bda59cc --- /dev/null +++ b/.github/workflows/validate-terraform.yaml @@ -0,0 +1,23 @@ +--- +name: Terraform +on: + push: + branches: + - main + - feature/* + - review/* + - fix/* + pull_request: + types: [opened, reopened] + +jobs: + validate-terraform: + if: github.event.ref == 'refs/heads/main' + name: Valdiate + uses: stuttgart-things/stuttgart-things/.github/workflows/validate-terraform.yaml@main + with: + environment-name: k8s + runs-on: arc-runner-scale-set-proxmox-vm + terraform-version: 1.6 + tflint-version: "v0.50.0" + continue-error: false diff --git a/README.md b/README.md index dad535d..7ebae6f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ # stuttgart-things/proxmox-vm -"HOLA" terraform module for creating proxmox vms diff --git a/tests/pipeline.py b/tests/pipeline.py deleted file mode 100644 index 4289c4d..0000000 --- a/tests/pipeline.py +++ /dev/null @@ -1,103 +0,0 @@ -import python_terraform -import yaml -import random -import string -import pprint -import os -import json - -### Control Booleans -cb_runApply = False -cb_runDestroy = False -cb_destroyOldMachines = False -cb_printTfvars = False -cb_omitTfLiveOutput = False -cb_printOutput = False -output_file_name = "vm_info.txt" - -def main(): - # Initialize the Terraform working directory - global tf - tf = python_terraform.Terraform(working_dir='.') - tf.init() - - - dict_tfvars = get_test_tfvars() - if os.path.isfile(output_file_name) & cb_destroyOldMachines: - if os.path.getsize(output_file_name) > 0: - terraform_destroy(output_file_name) - os.remove(output_file_name) - str_tfOutput = run_terraform(tfvars=dict_tfvars) - - if (cb_printTfvars): - print ("### TFVARS ###") - pprint.pprint(dict_tfvars) - print ("###############\n") - - if (cb_printOutput): - print(f""" - ### TF OUTPUT ### - {str_tfOutput} - #################\n - """) - save_env_vars() - -def random_string_generation(length): - # choose from all lowercase letter - letters = string.ascii_lowercase - result_str = ''.join(random.choice(letters) for i in range(length)) - return result_str - -def get_test_tfvars(): - ### Generate Random String for VM name - str_tfvarName = "pipeline-" + random_string_generation(length = 5) - - ### Import Yaml file with all possible test values - with open('test_values.yaml', 'r') as file: - testVars = yaml.safe_load(file) - - ### Get random value for test tfvars - int_tfvarVmCount, str_tfvarVmNumCpus, str_tfvarPveDatastore = random.choice(testVars['vm_count']), str(random.choice(testVars['vm_num_cpus'])), random.choice(testVars['pve_datastore']) - - ### Generate dictionary with test tfvars - dict_tfvars = {'name': str_tfvarName, 'vm_count':int_tfvarVmCount, 'vm_num_cpus':str_tfvarVmNumCpus, 'pve_datastore':str_tfvarPveDatastore} - return dict_tfvars - -def run_terraform(tfvars): - # Plan the infrastructure changes - tf.plan(capture_output=cb_omitTfLiveOutput, var=tfvars) - - if (cb_runApply): - # Apply the changes - tf.apply(skip_plan=True, capture_output=cb_omitTfLiveOutput, var=tfvars) - - # Get the output of the applied resources - output = tf.output() - - # Save random tf_vars - f = open(output_file_name, "w") - f.write(str(tfvars)) - f.close() - else: - output = "Apply was deactivated" - - if (cb_runDestroy): - terraform_destroy(output_file_name) - os.remove(output_file_name) - return output - -def terraform_destroy(vm_info): - f = open(vm_info, "r") - destroy_vars = eval(f.read()) - f.close() - - tf.destroy(var=destroy_vars, force=None, auto_approve=True, capture_output=cb_omitTfLiveOutput) - -def save_env_vars(): - #os.environ["ENV_VAR_PY"] = "Mundo" - - print("HOLA " +str(os.getenv('ENV_VAR_PY'))) - os.environ["ENV_VAR_PY"] = "Mundo" - -if __name__ == '__main__': - main()