From 1c3bb330d48394dad3bfa6c2dcb3bf27106c78d9 Mon Sep 17 00:00:00 2001 From: Himanshu Rai Date: Sat, 14 Sep 2024 18:11:43 +0530 Subject: [PATCH 1/4] stopping instances if there are error --- .github/workflows/run_e2e_tests.yml | 15 +++++++++++---- terraform/ec2-instances-creator/main.tf | 4 ++++ terraform/ec2-stop-instances/Makefile | 7 +++++++ terraform/ec2-stop-instances/main.tf | 9 +++++++++ ...azonlinux_2.yml => amazonlinux_2.yml.disabled} | 0 ...nux_2023.yml => amazonlinux_2023.yml.disabled} | 0 versions/{centos_7.yml => centos_7.yml.disabled} | 0 versions/{centos_8.yml => centos_8.yml.disabled} | 0 versions/{centos_9.yml => centos_9.yml.disabled} | 0 ...0_buster.yml => debian_10_buster.yml.disabled} | 0 ...llseye.yml => debian_11_bullseye.yml.disabled} | 0 ...okworm.yml => debian_12_bookworm.yml.disabled} | 0 .../{sles_12.1.yml => sles_12.1.yml.disabled} | 0 .../{sles_12.2.yml => sles_12.2.yml.disabled} | 0 .../{sles_12.3.yml => sles_12.3.yml.disabled} | 0 .../{sles_12.4.yml => sles_12.4.yml.disabled} | 0 .../{sles_12.5.yml => sles_12.5.yml.disabled} | 0 .../{sles_15.1.yml => sles_15.1.yml.disabled} | 0 .../{sles_15.2.yml => sles_15.2.yml.disabled} | 0 .../{sles_15.3.yml => sles_15.3.yml.disabled} | 0 .../{sles_15.4.yml => sles_15.4.yml.disabled} | 0 .../{sles_15.5.yml => sles_15.5.yml.disabled} | 0 ...8_bionic.yml => ubuntu_18_bionic.yml.disabled} | 0 ..._20_focal.yml => ubuntu_20_focal.yml.disabled} | 0 ..._24_noble.yml => ubuntu_24_noble.yml.disabled} | 0 ...-2019.yml => windows-server-2019.yml.disabled} | 0 ...-2022.yml => windows-server-2022.yml.disabled} | 0 27 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 terraform/ec2-stop-instances/Makefile create mode 100644 terraform/ec2-stop-instances/main.tf rename versions/{amazonlinux_2.yml => amazonlinux_2.yml.disabled} (100%) rename versions/{amazonlinux_2023.yml => amazonlinux_2023.yml.disabled} (100%) rename versions/{centos_7.yml => centos_7.yml.disabled} (100%) rename versions/{centos_8.yml => centos_8.yml.disabled} (100%) rename versions/{centos_9.yml => centos_9.yml.disabled} (100%) rename versions/{debian_10_buster.yml => debian_10_buster.yml.disabled} (100%) rename versions/{debian_11_bullseye.yml => debian_11_bullseye.yml.disabled} (100%) rename versions/{debian_12_bookworm.yml => debian_12_bookworm.yml.disabled} (100%) rename versions/{sles_12.1.yml => sles_12.1.yml.disabled} (100%) rename versions/{sles_12.2.yml => sles_12.2.yml.disabled} (100%) rename versions/{sles_12.3.yml => sles_12.3.yml.disabled} (100%) rename versions/{sles_12.4.yml => sles_12.4.yml.disabled} (100%) rename versions/{sles_12.5.yml => sles_12.5.yml.disabled} (100%) rename versions/{sles_15.1.yml => sles_15.1.yml.disabled} (100%) rename versions/{sles_15.2.yml => sles_15.2.yml.disabled} (100%) rename versions/{sles_15.3.yml => sles_15.3.yml.disabled} (100%) rename versions/{sles_15.4.yml => sles_15.4.yml.disabled} (100%) rename versions/{sles_15.5.yml => sles_15.5.yml.disabled} (100%) rename versions/{ubuntu_18_bionic.yml => ubuntu_18_bionic.yml.disabled} (100%) rename versions/{ubuntu_20_focal.yml => ubuntu_20_focal.yml.disabled} (100%) rename versions/{ubuntu_24_noble.yml => ubuntu_24_noble.yml.disabled} (100%) rename versions/{windows-server-2019.yml => windows-server-2019.yml.disabled} (100%) rename versions/{windows-server-2022.yml => windows-server-2022.yml.disabled} (100%) diff --git a/.github/workflows/run_e2e_tests.yml b/.github/workflows/run_e2e_tests.yml index ff0bca00..3a5e1a77 100644 --- a/.github/workflows/run_e2e_tests.yml +++ b/.github/workflows/run_e2e_tests.yml @@ -97,10 +97,17 @@ jobs: files: | ${{ inputs.test_report_filename }} - tear_down_test_executor_instances: - name: Tear down test executor instances - needs: report_test_results + stop_executor_instances: + name: Stop executor instances uses: ./.github/workflows/run_task.yml with: - container_make_target: "terraform/ec2-test-executors/clean PRE_RELEASE_NAME=${{ inputs.gh_release_name }}" + container_make_target: "terraform/ec2-stop-instances/stop" secrets: inherit + +# tear_down_test_executor_instances: +# name: Tear down test executor instances +# needs: report_test_results +# uses: ./.github/workflows/run_task.yml +# with: +# container_make_target: "terraform/ec2-test-executors/clean PRE_RELEASE_NAME=${{ inputs.gh_release_name }}" +# secrets: inherit diff --git a/terraform/ec2-instances-creator/main.tf b/terraform/ec2-instances-creator/main.tf index 8311ea53..5b0d4ef7 100644 --- a/terraform/ec2-instances-creator/main.tf +++ b/terraform/ec2-instances-creator/main.tf @@ -71,4 +71,8 @@ module "ec2_instance" { instance_type = var.instance_type fb_package_name = each.value.targetPackageName }) +} + +output "instance_ids" { + value = { for k, v in module.ec2_instance : k => v.id } } \ No newline at end of file diff --git a/terraform/ec2-stop-instances/Makefile b/terraform/ec2-stop-instances/Makefile new file mode 100644 index 00000000..25832c9e --- /dev/null +++ b/terraform/ec2-stop-instances/Makefile @@ -0,0 +1,7 @@ +# Terraform-stop +.PHONY: stop +stop: + terraform init -reconfigure && \ + terraform refresh && \ + terraform apply -target null_resource.stop_instances -auto-approve + @echo "Stopping all the instances" diff --git a/terraform/ec2-stop-instances/main.tf b/terraform/ec2-stop-instances/main.tf new file mode 100644 index 00000000..4465beb3 --- /dev/null +++ b/terraform/ec2-stop-instances/main.tf @@ -0,0 +1,9 @@ +# creates a resource named null_resource +resource "null_resource" "stop_instances" { + provisioner "local-exec" { + on_failure = continue + command = < Date: Sat, 14 Sep 2024 18:39:07 +0530 Subject: [PATCH 2/4] making steps dependent --- .github/workflows/run_e2e_tests.yml | 1 + terraform/ec2-stop-instances/Makefile | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/run_e2e_tests.yml b/.github/workflows/run_e2e_tests.yml index 3a5e1a77..54b6187f 100644 --- a/.github/workflows/run_e2e_tests.yml +++ b/.github/workflows/run_e2e_tests.yml @@ -99,6 +99,7 @@ jobs: stop_executor_instances: name: Stop executor instances + needs: [ provision_and_execute_tests, report_test_results ] uses: ./.github/workflows/run_task.yml with: container_make_target: "terraform/ec2-stop-instances/stop" diff --git a/terraform/ec2-stop-instances/Makefile b/terraform/ec2-stop-instances/Makefile index 25832c9e..5fe91d6d 100644 --- a/terraform/ec2-stop-instances/Makefile +++ b/terraform/ec2-stop-instances/Makefile @@ -3,5 +3,6 @@ stop: terraform init -reconfigure && \ terraform refresh && \ + terraform output -json instance_ids | jq -r '.[]' | paste -sd ' ' - && \ terraform apply -target null_resource.stop_instances -auto-approve @echo "Stopping all the instances" From e4dd32b31c0f2a694513e2afa82ed2c7c4bb8998 Mon Sep 17 00:00:00 2001 From: Himanshu Rai Date: Sat, 14 Sep 2024 19:37:22 +0530 Subject: [PATCH 3/4] making each terrfom step independent --- terraform/ec2-stop-instances/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/terraform/ec2-stop-instances/Makefile b/terraform/ec2-stop-instances/Makefile index 5fe91d6d..337b1fcb 100644 --- a/terraform/ec2-stop-instances/Makefile +++ b/terraform/ec2-stop-instances/Makefile @@ -1,8 +1,8 @@ # Terraform-stop .PHONY: stop stop: - terraform init -reconfigure && \ - terraform refresh && \ - terraform output -json instance_ids | jq -r '.[]' | paste -sd ' ' - && \ + terraform init -reconfigure + terraform refresh + terraform output -json instance_ids | jq -r '.[]' | paste -sd ' ' - terraform apply -target null_resource.stop_instances -auto-approve @echo "Stopping all the instances" From 599381d1575f1629cf83fb04cb20e6829d96c67a Mon Sep 17 00:00:00 2001 From: Himanshu Rai Date: Sat, 14 Sep 2024 23:47:25 +0530 Subject: [PATCH 4/4] changes to call destroy directly --- terraform/ec2-stop-instances/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/terraform/ec2-stop-instances/Makefile b/terraform/ec2-stop-instances/Makefile index 337b1fcb..e04b355c 100644 --- a/terraform/ec2-stop-instances/Makefile +++ b/terraform/ec2-stop-instances/Makefile @@ -3,6 +3,7 @@ stop: terraform init -reconfigure terraform refresh - terraform output -json instance_ids | jq -r '.[]' | paste -sd ' ' - - terraform apply -target null_resource.stop_instances -auto-approve + #terraform output -json instance_ids | jq -r '.[]' | paste -sd ' ' - + terraform destroy -auto-approve + #terraform apply -target null_resource.stop_instances -auto-approve @echo "Stopping all the instances"