# Phase 2 - Github Action

The code block defines a job named "destroy" which runs on an Ubuntu machine. The job depends on the successful completion of the "apply" job because of the "needs" key. It has a condition defined by the "if" key that checks the value of the "prompt" input that was passed during the workflow dispatch event. If the value of "prompt" is equal to "yes", then the job will be executed, otherwise it will be skipped.

The job consists of several steps, which are executed sequentially:

1. Checkout code: This step checks out the code from the repository using the actions/checkout action.
2. Set up Terraform: This step sets up Terraform on the machine and configures the AWS access key ID and secret access key using the hashicorp/setup-terraform action.
3. Download Terraform state: This step downloads the Terraform state file that was saved during the "apply" job using the actions/download-artifact action.
4. Terraform Init: This step initializes Terraform on the machine.
5. Terraform Destroy: This step destroys the infrastructure that was created by the "apply" job using the terraform destroy command. The -auto-approve flag is used to skip the confirmation prompt.
6. Save Terraform State: This step saves the Terraform state file after the destruction of infrastructure using the actions/upload-artifact action.

The&#x20;

```
  destroy:
    name: Terraform Destroy
    runs-on: ubuntu-latest
    needs: apply
    if: github.event.inputs.prompt == 'yes'
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Set up Terraform
        uses: hashicorp/setup-terraform@v1
        with:
          terraform_version: 1.1.5
          aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

      - name: Download Terraform state
        uses: actions/download-artifact@v2
        with:
          name: terraform-state

      - name: Terraform Init
        run: terraform init

      - name: Terraform Destroy
        run: terraform destroy -auto-approve -var aws_access_key=${{ secrets.AWS_ACCESS_KEY_ID }} -var aws_secret_key=${{ secrets.AWS_SECRET_ACCESS_KEY }}

      - name: Save Terraform State
        uses: actions/upload-artifact@v2
        with:
          name: terraform-state
          path: terraform.tfstate
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rishaws-projects.gitbook.io/devops-project/phase-2-github-action.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
