> ## Content Index
> Fetch the complete content index at: https://horrell.ca/llms.txt
> Use this file to discover other available public pages before exploring further.

# Validating packer templates with GitHub Actions
- URL: https://horrell.ca/2024/03/22/setting-packer_github_api_token-when-running-packer-in-a-github-action/
- Published: 2024-03-22T13:30:21.000Z
- Updated: 2026-10-02T14:15:08.000Z
- Author: Christopher Horrell
- Tags: GitHub, packer

I setup a GitHub Action for my [packer-aws-windows-openssh](https://github.com/chorrell/packer-aws-windows-openssh?ref=horrell.ca) project last month and it was working pretty well until a recent job failed with this:

```test
Run packer init ./aws-windows-ssh.pkr.hcl
Failed getting the "github.com/hashicorp/amazon" plugin:
1 error occurred:
	* Plugin host rate limited the plugin getter. Try again in 43m44.793174231s.
HINT: Set the PACKER_GITHUB_API_TOKEN env var with a token to get more requests.
GET https://api.github.com/repos/hashicorp/packer-plugin-amazon/git/matching-refs/tags: 403 API rate limit exceeded for 172.183.131.31. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) [rate reset in 43m45s]
```

This happened during the `packer init` part of my [GitHub action](https://github.com/chorrell/packer-aws-windows-openssh/blob/main/.github/workflows/packer.yml?ref=horrell.ca). The `packer init` command queries GitHub's public API, which rate limits requests per IP address. With GitHub actions, it's quite easy to hit this limit. The packer doc mentions setting [PACKER\_GITHUB\_API\_TOKEN](https://developer.hashicorp.com/packer/docs/configure?ref=horrell.ca#packer%5Fgithub%5Fapi%5Ftoken) but it doesn't get into specifics. Outside of GitHub actions, like running this from your local laptop, you'd probably not hit this issue at all

Fortunately, setting this up in an GitHub Action is fairly easy and you don't need to manually create token, you just set `PACKER_GITHUB_API_TOKEN` to `${{ secrets.GITHUB_TOKEN }}` :

```yaml
env:
  PACKER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

GitHub automatically creates a token for you, called [GITHUB\_TOKEN](https://docs.github.com/en/actions/security-guides/automatic-token-authentication?ref=horrell.ca#about-the-github%5Ftoken-secret), which you can use in your workflow. You would put the above two lines at the top of your action, right before `jobs:`. Here's a full example of my GitHub action so you can see it in context:

```yaml
name: Validate packer templates

on:
  pull_request:

env:
  PACKER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
  packer-validate:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup `packer`
        uses: hashicorp/setup-packer@v3
        id: setup

      - name: Run `packer init`
        id: init
        run: "packer init ./aws-windows-ssh.pkr.hcl"

      - name: Run `packer validate`
        id: validate
        run: "packer validate ./aws-windows-ssh.pkr.hcl"
```

Once `PACKER_GITHUB_API_TOKEN` is set in your action, you shouldn't see the rate limit error anymore.