Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

feat!: introduce basic Terratest based tests, unified Makefile and ChatOPS like workflows #304

Merged
merged 33 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
171def1
init - 1st working test + skeleton
FoSix Jun 27, 2023
fc1689c
run online tests
FoSix Jun 30, 2023
58dc833
main into 263-terratest-for-azure
FoSix Jun 30, 2023
e8171e7
update documentation
FoSix Jun 30, 2023
1827f28
debuging
FoSix Jun 30, 2023
88563a8
use new CI workflows -> 43-introduce-terratest
FoSix Jun 30, 2023
5acc20b
remove makefile.sh dependency
FoSix Jun 30, 2023
65ea158
Merge branch 'main' into 263-terratest-for-azure
FoSix Jul 7, 2023
9ebda03
update
FoSix Jul 18, 2023
b279cf5
Merge remote-tracking branch 'origin/main' into 263-terratest-for-azure
FoSix Jul 18, 2023
5cd73a1
update readmes
FoSix Jul 18, 2023
ba031d4
full test
FoSix Jul 18, 2023
35ac322
fixing failing CI tests, TF wrapper and HA PIPs in GH actions
FoSix Jul 20, 2023
2c9f436
ready for review
FoSix Jul 20, 2023
0903207
Merge branch 'main' into 263-terratest-for-azure
FoSix Aug 2, 2023
839174f
Merge branch 'main' into 263-terratest-for-azure
FoSix Aug 22, 2023
c9c400d
update go mod to use testskeleton package
FoSix Aug 23, 2023
ff70402
add terratest to common_vmseries_and_autoscale
FoSix Aug 23, 2023
6ea41d6
test new makefiles
FoSix Aug 24, 2023
61bc871
test releases
FoSix Aug 24, 2023
19d49e1
differernt paralelizm parameters for tests and validation
FoSix Aug 24, 2023
66bcf84
cleanup old Makefiles
FoSix Aug 24, 2023
852d46b
test different paralelizm params for PRs
FoSix Aug 24, 2023
b913e4f
new test go for all examples
FoSix Aug 24, 2023
7db309e
add reusable workflows for chatops + concurency configuration
FoSix Aug 28, 2023
92e10de
adding suggestions from comments
FoSix Aug 29, 2023
d1c0812
adding possibility to use PR number as a part of the name_prefix
FoSix Sep 1, 2023
0831cea
Merge branch 'main' into 263-terratest-for-azure
FoSix Sep 6, 2023
fb776a2
update reusable workflows dependencies to the latest release
FoSix Sep 6, 2023
bc47922
Merge branch 'main' into 263-terratest-for-azure
FoSix Sep 7, 2023
724e308
adding GWLB module and example with terratest
FoSix Sep 7, 2023
5d3c728
Merge branch 'main' into 263-terratest-for-azure
FoSix Sep 7, 2023
0cbcb8f
fix sample init-cfg file name for gwlb
FoSix Sep 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 0 additions & 101 deletions .github/actions/plan_apply/action.yml

This file was deleted.

12 changes: 11 additions & 1 deletion .github/actions/sub_cleanup/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: 'Subscription cleanup'
description: 'Cleans up subscription in case the job was cancelled.'
inputs:
pr-id:
description: A PR number. Optional value, you might want to use it to prefix resources created for a particular PR to identify them easly.
type: string
default: ""
required: false
runs:
using: "composite"
steps:
Expand All @@ -13,11 +19,15 @@ runs:

- name: delete resource groups
shell: bash
env:
PRID: ${{ inputs.pr-id }}
run: |
echo "::group::CLEANUP"

set +e
for RG in $(az group list --query "[?properties.provisioningState=='Succeeded']" | jq -r '.[] | select(.name | contains("ghci")) | .name'); do
PRPREFIX=$(if [ "$PRID" ]; then echo "-pr$PRID-"; fi)

for RG in $(az group list --query "[?properties.provisioningState=='Succeeded']" | jq -r ".[] | select(.name | contains(\"ghci$PRPREFIX\")) | .name"); do
echo " deleting: $RG"
az group delete -g ${RG} -y --no-wait

Expand Down
50 changes: 50 additions & 0 deletions .github/actions/terratest/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: 'Terratest'
description: 'Runs Terratest for a specified path.'
inputs:
tf_version:
description: 'TF version used.'
required: true
path:
description: 'Path to Terraform module.'
required: true
terratest_action:
description: The action (name of a test in Terratest) that will be passed to the Makefile's ACTION parameter
type: string
required: true
pr-id:
description: A PR number. Optional value, you might want to use it to prefix resources created for a particular PR to identify them easly.
type: string
default: ""
required: false

runs:
using: "composite"
steps:

- name: setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ inputs.tf_version }}
terraform_wrapper: false

- name: setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: login to Azure
uses: azure/login@v1
with:
client-id: ${{ env.ARM_CLIENT_ID }}
tenant-id: ${{ env.ARM_TENANT_ID }}
subscription-id: ${{ env.ARM_SUBSCRIPTION_ID }}

- name: ${{ inputs.terratest_action }} infrastructure
env:
TPATH: ${{ inputs.path }}
ARM_USE_OIDC: true
ARM_SKIP_PROVIDER_REGISTRATION: true
ACTION: ${{ inputs.terratest_action }}
PRID: ${{ inputs.pr-id }}
shell: bash
run: make $TPATH ACTION=$ACTION
51 changes: 51 additions & 0 deletions .github/workflows/apply-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: ChatOPS Apply
run-name: "On demand Apply test for PR - (#${{ github.event.inputs.pr-id }}) ${{ github.event.inputs.pr-title }}"

permissions:
contents: read

concurrency: chatops-apply

on:
workflow_dispatch:
inputs:
paths:
description: Space delimited list of module paths to test
type: string
required: true
tf_version:
description: Terraform versions to use for tests, comma-separated list
type: string
pr-id:
description: ID of the PR that triggered this workflow
type: string
required: true
pr-title:
description: Title of the PR that triggered this workflow
type: string
required: true
comment-id:
description: 'The comment-id of the slash command'
type: string
required: true
branch:
description: Branch on which the tests should run
type: string
default: main

jobs:
test:
name: Run apply test
permissions:
contents: read
pull-requests: write
id-token: write
uses: PaloAltoNetworks/terraform-modules-vmseries-ci-workflows/.github/workflows/[email protected]
secrets: inherit
with:
paths: ${{ inputs.paths }}
tf_version: ${{ inputs.tf_version }}
pr-id: ${{ inputs.pr-id }}
comment-id: ${{ inputs.comment-id }}
branch: ${{ inputs.branch }}
terratest_action: Apply
77 changes: 77 additions & 0 deletions .github/workflows/chatops.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: ChatOPS dispatcher
run-name: "ChatOPS bot for PR - (#${{ github.event.issue.number }}) ${{ github.event.issue.title }}"

permissions:
contents: read

on:
issue_comment:
types: [created]

concurrency:
group: chat-${{ github.event.issue.number }}
cancel-in-progress: true

jobs:
dispatch:
name: Dispatch a test job
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: get PR head branch
uses: actions/github-script@v6
id: pr
with:
result-encoding: string
script: |
let pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
})
console.log(pr.data.head.ref)
return pr.data.head.ref

- name: "dispatch test command on branch: ${{ steps.pr.outputs.result }}"
id: scd
uses: peter-evans/slash-command-dispatch@v3
with:
token: ${{ secrets.CHATOPS }}
issue-type: pull-request
dispatch-type: workflow
permission: maintain
commands: |
validate
sebastianczech marked this conversation as resolved.
Show resolved Hide resolved
plan
apply
idempotence
sca
help
static-args: |
comment-id=${{ github.event.comment.id }}
pr-id=${{ github.event.issue.number }}
pr-title=${{ github.event.issue.title }}
branch=${{ steps.pr.outputs.result }}

- name: Edit comment with error message
if: steps.scd.outputs.error-message
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ github.event.comment.id }}
body: |
> ${{ steps.scd.outputs.error-message }}
reactions: '-1'
reactions-edit-mode: replace

- name: Concurency ratio fallback
if: cancelled()
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ github.event.comment.id }}
body: |
> ChatOPS run cancelled.
> See [job run log](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
reactions: 'confused'
reactions-edit-mode: replace
67 changes: 67 additions & 0 deletions .github/workflows/help-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: ChatOPS Help
run-name: "Display ChatOPS help (#${{ github.event.inputs.pr-id }}) ${{ github.event.inputs.pr-title }}"

on:
workflow_dispatch:
inputs:
pr-id:
description: ID of the PR that triggered this workflow
type: string
required: true
pr-title:
description: Title of the PR that triggered this workflow
type: string
required: true
comment-id:
description: 'The comment-id of the slash command'
type: string
required: true
branch:
description: Branch on which the tests should run
type: string
default: main

jobs:
help:
name: Add help comment to originating PR
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: add help comment
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ inputs.comment-id }}
issue-number: ${{ inputs.pr-id }}
body: |

## ChatOPS built in help:

Currently supported commands include:

* `/sca` - run all SCA tests via `pre-commit`
* `/validate` - run `terraform validate`
* `/plan` - plan the infrastructure (only examples)
* `/apply` - deploy the infrastructure and destroy afterwards (only examples)
* `/idempotence` - test idempotence: deploy, plan and destroy afterwards (only examples).

The 1<sup>st</sup> command does not take arguments, the remaining take two:

* `paths` - a space delimitied list of module paths
* `tf_version` - (optional, defaults to the latest available) a space delimited list of Terraform versions to test the infrastrucure against.

Examples:

```bash
# run idempotence tests on listed modules with Terraform versions: 1.2 (latest patch available), 1.4 (latest patch available), 1.5.4.
/idempotence paths="examples/common_vmseries examples/panorama_standalone" tf_version="1.2 1.4 1.5.4"
```

```bash
# run validation tests with the latest available Terraform version on listed modules.
/validate paths="modules/vmseries modules/vnet examples/dedicated_vmseries"
```

reactions: '+1'
reactions-edit-mode: replace
Loading