# Phase 1 - Github Action

In the workflow we have divided the workflow in two phases i.e Apply and Destroy.

For trigger we have used workflow\_dispatch. This is used in order to give the users option to destroy infrastructure after it's been deployed.

```
on:
  workflow_dispatch:
    inputs:
      prompt:
        description: 'Do you want to destroy the infrastructure? (yes/no)'
        required: true
        default: 'no'
        
```

This block of code defines the "apply" job, which runs on an Ubuntu environment. It has several steps:

1. Checkout code: This step checks out the code from the repository.
2. Set up Terraform: This step sets up Terraform with the specified version and provides the AWS access and secret keys from the repository secrets.
3. Terraform Init: This step initializes the Terraform configuration.
4. Terraform Plan: This step generates an execution plan for the Terraform configuration.
5. Terraform Apply: This step applies the Terraform configuration to create the AWS infrastructure.
6. Save Terraform State: This step saves the Terraform state to an artifact named "terraform-state". This artifact can be used later to destroy the infrastructure.

```
jobs:
  apply:
    runs-on: ubuntu-latest

    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: Terraform Init
        run: terraform init

      - name: Terraform Plan
        run: terraform plan -var aws_access_key=${{ secrets.AWS_ACCESS_KEY_ID }} -var aws_secret_key=${{ secrets.AWS_SECRET_ACCESS_KEY }}
        
      - name: Terraform Apply
        run: terraform apply -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
```

&#x20;


---

# 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/setup-ci-cd/phase-1-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.
