diff --git a/.github/workflows/ec2-integration-test.yml b/.github/workflows/ec2-integration-test.yml index 5ddbf26071..c094939c32 100644 --- a/.github/workflows/ec2-integration-test.yml +++ b/.github/workflows/ec2-integration-test.yml @@ -88,7 +88,7 @@ jobs: fi terraform init - terraform apply --auto-approve \ + if terraform apply --auto-approve \ -var="ssh_key_value=${{env.PRIVATE_KEY}}" -var="github_test_repo=${{ inputs.test_repo_url }}" \ -var="test_name=${{ matrix.arrays.os }}" \ -var="cwa_github_sha=${{inputs.github_sha}}" -var="install_agent=${{ matrix.arrays.installAgentCommand }}" \ @@ -105,4 +105,16 @@ jobs: -var="excluded_tests='${{ matrix.arrays.excludedTests }}'" \ -var="ssh_key_name=${{env.KEY_NAME}}" \ -var="test_dir=${{ matrix.arrays.test_dir }}" \ - -var="agent_start=${{ matrix.arrays.agentStartCommand }}" \ No newline at end of file + -var="agent_start=${{ matrix.arrays.agentStartCommand }}"; then terraform destroy -auto-approve + else + terraform destroy -auto-approve && exit 1 + fi + #This is here just in case workflow cancel + - name: Terraform destroy + if: ${{ cancelled() || failure() }} + uses: nick-fields/retry@v2 + with: + max_attempts: 3 + timeout_minutes: 8 + retry_wait_seconds: 5 + command: cd ${{ inputs.test_dir }} && terraform destroy --auto-approve \ No newline at end of file