Update coder templates automatically
Find a file
2023-08-11 12:15:18 +03:00
.github/workflows update release workflow to use token 2023-08-11 12:15:18 +03:00
action.yaml fix envs 2023-08-11 12:06:31 +03:00
LICENSE First commit 2022-11-24 09:57:45 +03:00
push_template.sh Update docs for v3 2023-08-11 11:49:33 +03:00
README.md Update docs for v3 2023-08-11 11:49:33 +03:00

Update Coder Template

Update coder templates automatically

Usage

  1. Create a GitHub secret named CODER_SESSION_TOKEN with your coder session token You can generate a long lived session token by running the following command in your browser console while logged into Coder with a Template Admin or Owner role.

      coder token create --lifetime 8760h --name "GitHub Actions"
    
  2. Create a .github/workflows/push-coder-template.yaml file and use one of the examples below.

Inputs

Name Description Default
url Required The url of coder deployment (e.g. https://dev.coder.com). -
coder_session_token Required The session token of coder. -
id Required The id of template. -
dir Required The directory of the template that contains main.tf file -
name New version name for the template. Autogenerated name by Coder
activate Activate the new template version. true
create Creates a new template if it does not exist true
message Update message (similar to commit messages) -

Examples

  1. Update a Coder template with the latest commit hash as the version name, commit message as the update message and mark this as active.

    name: Update Coder Template
    
    on:
      push:
        branches:
          - main
    
    jobs:
        update:
            runs-on: ubuntu-latest
            steps:
            - name: Checkout
              uses: actions/checkout@v3
            - name: Get latest commit hash
              id: latest_commit
              run: echo "hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
            - name: Get commit title
               id: commit_title
               run: echo "title=$(git log -1 --pretty=%B)" >> $GITHUB_OUTPUT
    
    
            - name: Update Coder Template
                uses: matifali/update-coder-template@v3
                with:
                    id: "my-template"
                    dir: "my-template"
                    url: "https://coder.example.com"
                    name: "${{ steps.latest_commit.outputs.hash }}"
                    message: "${{ steps.commit_title.outputs.title }}"
                    coder_session_token: ${{ secrets.CODER_SESSION_TOKEN }}
    
  2. Update a Coder template with a random version name without activating.

    name: Update Coder Template
    
    on:
      push:
        branches:
          - main
    
    jobs:
        update:
            runs-on: ubuntu-latest
            steps:
            - name: Checkout
              uses: actions/checkout@v3
    
            - name: Update Coder Template
                uses: matifali/update-coder-template@v3
                with:
                    id: "my-template"
                    dir: "my-template"
                    url: "https://coder.example.com"
                    activate: "false"
                    coder_session_token: ${{ secrets.CODER_SESSION_TOKEN }}