Skip to content

Commit

Permalink
Set GitLab user and Personal Access Token (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
alv-lop authored Dec 16, 2021
1 parent 14ea674 commit 93f4ba8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# github-action-kitchen-terraform

GitHub Action to run Kitchen Terraform. Release versions match the Terraform version in use.

After cloning this repo, please run:
Expand Down Expand Up @@ -32,6 +33,8 @@ jobs:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.ACTIONS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.ACTIONS_SECRET_ACCESS_KEY }}
GITLAB_USER: ${{ secrets.GITLAB_USER }}
GITLAB_PAT: ${{ secrets.GITLAB_PAT }}
- name: Kitchen Test B
uses: dwp/github-action-kitchen-terraform@v0.14.7
with:
Expand All @@ -40,6 +43,8 @@ jobs:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.ACTIONS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.ACTIONS_SECRET_ACCESS_KEY }}
GITLAB_USER: ${{ secrets.GITLAB_USER }}
GITLAB_PAT: ${{ secrets.GITLAB_PAT }}
```
### Docker Repo
Expand All @@ -49,16 +54,26 @@ The image repository can be found [here](https://quay.io/repository/dwp/kitchen-
Use the Docker image to run an equivalent locally using the example commands below:
Standard Kitchen command
```shell
docker run --rm -e AWS_PROFILE=default -v $(pwd):/usr/action -v ~/.aws:/root/.aws quay.io/dwp/kitchen-terraform:0.14.7 "test scenario-a"
```

Kitchen command with GitLab user and GitLab Personal Access Token.
Used when Terraform contains references to external modules that require Git credentials.

```shell
docker run --rm -e AWS_PROFILE=default -e GITLAB_USER=user.name -e GITLAB_PAT=token -v $(pwd):/usr/action -v ~/.aws:/root/.aws quay.io/dwp/kitchen-terraform:0.14.7 "test scenario-a"
```

Kitchen command with redacted output - output is piped to `sed` and the second argument is used to find/replace, this can be a string or regex

```shell
docker run --rm -e AWS_PROFILE=default -v $(pwd):/usr/action -v ~/.aws:/root/.aws quay.io/dwp/kitchen-terraform:0.14.7 "test scenario-a" "0123456789"
```

Kitchen command with custom certificate trusts - mounts a local directory of certificates to trust

```shell
docker run --rm -e AWS_PROFILE=default -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ -v $(pwd):/usr/action -v ~/.aws:/root/.aws quay.io/dwp/kitchen-terraform:0.14.7 "test scenario-a"
```
15 changes: 15 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ update-ca-certificates || true
# This ensures that kitchen errors are maintained when piped through sed
set -o pipefail

if [ -n "$GITLAB_USER" ] && [ -n "$GITLAB_PAT" ]; then
# Set GitLab user
git config credential.https://gitlab.com.username ${GITLAB_USER}

# Configure small script to pass GitLab PAT from $GITLAB_PAT env var
# This avoids PAT being on disk, shell history, and terminal output
# See docs: https://git-scm.com/docs/gitcredentials#_requesting_credentials
GIT_ASKPASS=$(mktemp) && chmod a+rx $GIT_ASKPASS && export GIT_ASKPASS
cat > $GIT_ASKPASS <<'EOF'
#!/bin/sh
exec echo "$GITLAB_PAT"
EOF

fi

if [ -z "$2" ]; then
kitchen $1
else
Expand Down

0 comments on commit 93f4ba8

Please sign in to comment.