Skip to content

Commit

Permalink
temporary build provider from main for demo
Browse files Browse the repository at this point in the history
  • Loading branch information
roope-kar committed Oct 2, 2024
1 parent 00878f0 commit 9b9966a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 58 deletions.
63 changes: 26 additions & 37 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,41 @@ name: 'aiven_terraform_governance_compliance_check'
description: 'GitHub Action to check whether the plan generated by terraform plan complies with governance rules on aiven terraform provider resources.'
author: 'Aiven'

outputs:
result:
description: "the compliance result"
value: ${{ steps.check-governance-compliance.outputs.result }}

inputs:
GITHUB_TOKEN:
description: 'A GitHub access token that has permission to read the target pull request.'
requester:
description: 'The github username that created the pull request'
required: true

approvers:
description: 'The github usernames (csv) that have approved the pull request'
required: true

AIVEN_API_TOKEN:
description: 'A Aiven API access token used for terraform plan'
plan:
description: 'Plan generated by terraform plan -json'
required: true


outputs:
result:
description: "the compliance result"
value: ${{ steps.check.outputs.result }}

runs:
using: "composite"
steps:
- name: "Get approvers"
id: approvers
uses: octokit/[email protected]
with:
route: GET /repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}

- name: "Checkout branch"
id: checkout-branch
uses: actions/checkout@v4

- name: "Setup terraform"
id: setup-terraform
uses: hashicorp/setup-terraform@v3
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: ${{ github.action_path }}/go.mod

- name: "Check compliance"
id: check-compliance
env:
PROVIDER_AIVEN_ENABLE_BETA: 1
run: |
terraform init
terraform plan -out=plan -var="aiven_api_token=${{ inputs.AIVEN_API_TOKEN }}"
terraform show -json plan > ./plan.json
REQUESTER=${{ github.event.pull_request.user.login }}
APPROVERS=$(echo '${{ steps.approvers.outputs.data }}' | jq '[.[] | select(.state == "APPROVED") | .user.login] | unique')
RESULT=$(./build/checker -plan=plan.json -requester=$REQUESTER -approvers=$APPROVERS)
- name: Check Aiven Terraform Governance Compliance
id: check
run:
RESULT=$(
${{ github.action_path }}/build/checker -plan=${{ inputs.plan }} -requester=${{ inputs.requester }} -approvers=${{ inputs.approvers }}
)
echo $RESULT
echo "result=$RESULT" >> "$GITHUB_OUTPUT"
shell: bash
shell: bash

branding:
icon: 'shield'
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func main() {
approverIDs := flag.String("approvers", "", "comma separated list of users identified as the approvers of the change")
flag.Parse()

if *path == "" || *requesterID == "" || *approverIDs == "" {
if *path == "" {
log.Fatal("Missing required arguments")
}

Expand Down
20 changes: 0 additions & 20 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,6 @@ func TestE2E_Args(t *testing.T) {
}

tests := []TestCase{
{
Name: "Requester is required",
Args: Args{
Requester: "",
Approvers: "bob,charlie",
Plan: "testdata/nonexistent_plan.json",
},
ExpectStdout: "",
ExpectStderr: "Missing required arguments\nexit status 1",
},
{
Name: "Approvers is required",
Args: Args{
Requester: "alice",
Approvers: "",
Plan: "testdata/nonexistent_plan.json",
},
ExpectStdout: "",
ExpectStderr: "Missing required arguments\nexit status 1",
},
{
Name: "Plan file needs to exist",
Args: Args{
Expand Down

0 comments on commit 9b9966a

Please sign in to comment.