# Connect a Repo

In order for Abbey to orchestrate your access requests flows, you'll need to connect a code repository that holds your Terraform files.

{% hint style="info" %}
For this step, you'll be working in

* Abbey App
* GitHub
  {% endhint %}

<details>

<summary>Already set up a starter kit before?</summary>

If you've already set up a connection from Abbey <- -> Github, just make sure the Abbey Github App has permissions for your repo. Either select **All Repositories** or make sure your repo is added to the **Only select repositories** list.

Once that's saved, skip ahead to [create-a-grant-kit](https://docs.abbey.io/build-a-grant-kit/create-a-grant-kit "mention") :tada:

<img src="https://1502779850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FudoTqG501gLo2MLzBG55%2Fuploads%2FxQvzHdT4lGC2oBcGuHoT%2Fimage.png?alt=media&#x26;token=b12658c0-8838-4c4e-b025-862e4e914722" alt="" data-size="original">

</details>

## Step 1: Connect Abbey to your Repo

{% hint style="info" %}
For this step, you'll be working in

* Abbey App
* GitHub
  {% endhint %}

To use Abbey for access requests, you'll need to connect Abbey to your GitHub.

### Create a Connection

1. Go to the Abbey App ([app.abbey.io](https://app.abbey.io))
2. Go to the **Settings > Version Control** page and click :heavy\_plus\_sign:**Create a Connection**

<figure><img src="https://1502779850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FudoTqG501gLo2MLzBG55%2Fuploads%2Fgit-blob-a9289b0714b5874b53f42aa85f03c1922f176b56%2Fversion-control-page.png?alt=media" alt=""><figcaption></figcaption></figure>

3. Choose a name for your connection, then click **Create**. You'll be redirected to GitHub to install Abbey on your GitHub account.
4. In the Github App Permissions screen, choose either **All Repositories** or **Only select repositories** with the repository you created earlier in Step 1 selected

<figure><img src="https://1502779850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FudoTqG501gLo2MLzBG55%2Fuploads%2FsX2CkRd23fueXueTsQZI%2Fimage.png?alt=media&#x26;token=79aafa1f-938c-427c-b20e-d291f7e3cc87" alt=""><figcaption></figcaption></figure>

&#x20;5\. Once you click **Install & Authorize**, you'll be redirected back to the Abbey App, and your connection will be created :tada:

{% hint style="info" %}
:checkered\_flag: Congrats! You've now authorized Abbey to talk with the newly created GitHub repo in your personal account

At this point you should&#x20;

1. Have a connection to GitHub under the Abbey Settings -> Version Control tab
2. Have created a repo into your own GitHub account based off the Abbey Labs Quickstart Repo
3. Have cloned the newly created repo into your own terminal to work with
   {% endhint %}

## Step 2: Configure Permissions for Abbey

{% hint style="info" %}
For this step, you'll be working in

* Abbey App
* Github
  {% endhint %}

### Create an Abbey Token

1. Go to Abbey API Tokens via **Settings -> API Tokens** in the Abbey app
2. Click on the **+ New API Token**
3. Enter a name for your new API token or leave as is
4. Configure the **Expires At** field or leave it blank to have the token never expire
5. Click **Create** to make the new key
6. Copy the key - you'll need this for the next step!

<figure><img src="https://1502779850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FudoTqG501gLo2MLzBG55%2Fuploads%2FBslBo7X2FgyRbKKMJWGn%2Fcreate%20an%20api%20token.gif?alt=media&#x26;token=72b64fc5-1d94-47cb-80dd-c6af6e834420" alt=""><figcaption></figcaption></figure>

### Add your Abbey token to Github

1. Navigate to the repo you created in your own GitHub account
2. Go to the **Settings** tab
3. Select **Secrets and Variables -> Actions** on the left side
4. Create a new **Repository Secret**&#x20;

<figure><img src="https://1502779850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FudoTqG501gLo2MLzBG55%2Fuploads%2FwLVl7DkqdCaKBkk7l7g4%2Fimage.png?alt=media&#x26;token=43d11430-fd16-4b75-90cb-9901013f9063" alt=""><figcaption></figcaption></figure>

5. For the **Name,** enter in `ABBEY_TOKEN`
6. For the **Secret,** enter in the value of the Abbey API token you created in the last step.
   1. :warning: Make sure you don't have any newlines or spaces when copy/pasting this
7. Click **Add Secret** to finish adding the repository secret

<details>

<summary>What should it look like?</summary>

![](https://1502779850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FudoTqG501gLo2MLzBG55%2Fuploads%2FMAwRPBHZlY6PLUItf5nO%2Fimage.png?alt=media\&token=0c068627-614d-4f2d-94ac-200b2eae1852)

</details>

### Update Repo Permissions

Abbey needs a few permissions to operate in your GitHub repo.

1. Go to the **Settings** tab of the same repo you added the API token
2. Select **Actions -> General** on the left side
3. Scroll to the **Workflow Permissions** section
4. Select the **Read and write permissions** button
5. Click on **Save** in the **Workflow Permissions** section

<figure><img src="https://1502779850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FudoTqG501gLo2MLzBG55%2Fuploads%2FBLmMNCmnIUsNoCJYsUmZ%2Fadding%20repo%20secret.gif?alt=media&#x26;token=3df409df-e8f3-4902-8c62-e9dbcaa3f648" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
&#x20;Great! Now you've allowed Abbey to interact with your terraform repository.
{% endhint %}
