> For the complete documentation index, see [llms.txt](https://docs.digit.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.digit.org/platform/introducing-digit/releases/digit-2.9-lts/automated-digit-deployment.md).

# Automated DIGIT Deployment

Installation Guide for DIGIT via GitHub Actions in AWS

## Overview

This guide provides step-by-step instructions for installing DIGIT using GitHub Actions within an AWS environment.

## Pre-requisites

* AWS account
* Github account

## Steps

#### Prepare AWS IAM User

1. Create an IAM User in your AWS account.
2. Generate `ACCESS_KEY` and `SECRET_KEY` for the IAM user.
3. Assign Administrator Access to the IAM user for necessary permissions.

#### Configure GitHub Repository

1. Fork the Repository into your organization account on GitHub.
2. Navigate to the repository settings, then to Secrets and Variables, and add the following repository secrets:
   * `AWS_ACCESS_KEY_ID: <GENERATED_ACCESS_KEY>`
   * `AWS_SECRET_ACCESS_KEY: <GENERATED_SECRET_KEY>`
   * `AWS_DEFAULT_REGION: ap-south-1`
   * `AWS_REGION: ap-south-1`

**Enable GitHub Actions**

1. Open the GitHub Actions workflow file.
2. Specify the branch name you wish to enable GitHub Actions for.

#### Configure Infrastructure-as-Code

1. Navigate to `infra-as-code/terraform/sample-aws`.
2. Open `input.yaml` and enter details such as `domain_name`, `cluster_name`, `bucket_name`, and `db_name`.

#### Configure Application Secrets

1. Navigate to `config-as-code/environments`.
2. Open `egov-demo-secrets.yaml`.
3. Enter `db_password` and `ssh_private_key`. Add the `public_key` to your GitHub account.

#### Generate SSH Key Pair

Choose one of the following methods to generate an SSH key pair:

* **Method a:** Use an online website (Note: This is not recommended for production setups, only for demo purposes): `https://8gwifi.org/sshfunctions.jsp`
* **Method b:** Use OpenSSL commands:

  ```
  openssl genpkey -algorithm RSA -out private_key.pem
  openssl rsa -pubout -in private_key.pem -out public_key.pem
  ```

#### Finalize Installation

After entering all the details, push these changes to the remote GitHub repository. Open the `Actions` tab in your GitHub account to view the workflow. You should see that the workflow has started, and the pipelines are completed successfully.

<figure><img src="https://content.gitbook.com/content/051YseixNq69PlJkCdKt/blobs/OGE28cg6MJEeEyC2Il8H/image1.png" alt=""><figcaption><p>Github actions workflow that gets created after committing the inputs</p></figcaption></figure>

This indicates that your setup is correctly configured, and your application is ready to be deployed. Monitor the output of the workflow for any errors or success messages to ensure everything is functioning as expected.

### DIGIT Infrastructure - Cleanup & Uninstallation

As you wrap up your work with DIGIT, ensuring a smooth and error-free cleanup of the resources is crucial. Regular monitoring of the GitHub Actions workflow's output is essential during the destruction process. Watch out for any error messages or signs of issues. A successful job completion will be confirmed by a success message in the GitHub Actions window, indicating that the infrastructure has been effectively destroyed.

When you're ready to remove DIGIT and clean up the resources it created, proceed with executing the `terraform_infra_destruction` job. This action is designed to dismantle all setup resources, clearing the environment neatly.

We hope your experience with DIGIT was positive and that this guide makes the uninstallation process straightforward.

#### Run the Terraform Infrastructure Destruction Job - Steps

To initiate the destruction of a Terraform-managed infrastructure, follow the steps below:

1. Navigate to **Actions**
2. Click **DIGIT-Install workflow**
3. Select **Run workflow**
4. When prompted, type **"destroy"**. This action starts the `terraform_infra_destruction` job.

You can observe the progress of the destruction job in the actions window.

**Note:** For DIGIT configurations created using the master branch

<div align="left"><figure><img src="https://content.gitbook.com/content/051YseixNq69PlJkCdKt/blobs/NoSq7h58VxSgFnSgKWDQ/image2.png" alt=""><figcaption><p>Destroying the created DIGIT Infrastructure via Terraform</p></figcaption></figure></div>

If DIGIT is installed from a branch other than the main one, ensure that the branch name is correctly specified in the workflow file. For instance, if the installation is done from the **digit-install** branch, the following snippet should be updated to reflect that.

```github-actions-workflow
name: DIGIT-Install workflow
# Workflow branch creating cluster against the input.yaml file  
on:
  push:
    branches:
      - master
      - digit-install
  workflow_dispatch:
    inputs:
      destroyCommand:
        description: 'Type "destroy" to run the terraform_infra_destruction job.'
        required: true
        default: ''  
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.digit.org/platform/introducing-digit/releases/digit-2.9-lts/automated-digit-deployment.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
