-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/module test action #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 27 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
86430af
New feature terraform test for modules:
Artlvns 645e2c5
fix: wrong action version
Artlvns 353db7e
feat: add icon to report depending on status.
Artlvns ad02af9
fix: remove wrong if condition
Artlvns 742c5bc
chore: add debug
Artlvns 4a6cc8b
chore: debug
Artlvns 125023a
feat: add azure login
Artlvns aeb02b9
chore: azure login variables
Artlvns 7d52d1f
fix: az login
Artlvns 4426820
chore: testing with env
Artlvns 6cecea9
fix: add helpers to create-test-report action
Artlvns 0e2af1b
fix: inputs
Artlvns 221654c
fix: remove result correction as not needed
Artlvns 5b767fc
chore: cleanup. chore: add input tf version
Artlvns 7e9636d
fix: outcome don't fail
Artlvns 05840c3
feat: add tflint to pipeline.
Artlvns 85578be
chore: add outcome of lint to report.
Artlvns ac50918
chore: change of flow
Artlvns d1f2e3a
chore: add repo as env
Artlvns ad75e23
feat: plugin cache
Artlvns ada23e5
chore: adjustments
Artlvns b8556fe
feat: cache
Artlvns 818f512
chore: bump test raport, remove unused fields
Artlvns 994548b
chore: update test report text
Artlvns 78129be
fix: typo in comment
Artlvns fb1dea5
docs: update README.md
Artlvns 6748755
chore: remove sourcinf helpers_additional as it is handled in helpers…
Artlvns a0e71c9
Update .github/workflows/terraform-module-ci.yaml
Artlvns 2bff8db
Update create-validation-summary/action.yml
Artlvns d8f07a1
Update .github/workflows/terraform-module-ci.yaml
Artlvns 1967453
Update README.md
Artlvns d811e6a
Update terraform-test/helpers_additional.sh
Artlvns 2d6ab38
Update terraform-test/action.yml
Artlvns bd0d7e6
Update .github/workflows/terraform-module-ci.yaml
Artlvns ef19445
Update create-tftest-matrix/action.yaml
Artlvns df4d3ec
Update .github/workflows/terraform-module-ci.yaml
Artlvns 0a025a5
Update .github/workflows/terraform-module-ci.yaml
Artlvns fd3ac81
Update .github/workflows/terraform-module-ci.yaml
Artlvns 6424a63
Update .github/workflows/terraform-module-ci.yaml
Artlvns e5ee90d
Update .github/workflows/terraform-module-ci.yaml
Artlvns c3f7e92
Update .github/workflows/terraform-module-ci.yaml
Artlvns 7e2e240
Update terraform-test/action.yml
Artlvns 3a16ab3
Review requested changes:
Artlvns f31b3fe
Update .github/workflows/terraform-module-ci.yaml
Artlvns bf7c702
chore: requested changes
Artlvns bd99501
Update .github/workflows/terraform-module-ci.yaml
Artlvns cb37fa8
Update .github/workflows/terraform-module-ci.yaml
Artlvns 4791edd
Update .github/workflows/terraform-module-ci.yaml
Artlvns 5caa7aa
fix: wrong variable refs in workflow
Artlvns d1a4a6d
chore: revert dev tag back to v0
Artlvns File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,271 @@ | ||
name: "DSB Terraform Module CI" | ||
# | ||
# A requirement for this workflow to run is that the following 'permissions' are granted by the calling workflow: | ||
# permissions: | ||
# id-token: write # required for Azure password-less auth | ||
# contents: read # required for actions/checkout | ||
# pull-requests: write # required for commenting on PRs | ||
# | ||
# Additionally for the workflow to have access to secrets (required when using the input 'extra-envs-from-secrets-yml'), | ||
# all secrets available to the calling workflow must be passe down to this one by: | ||
# secrets: inherit | ||
# | ||
on: | ||
workflow_call: | ||
inputs: | ||
terraform-version: | ||
description: "Terraform version to use for the tests." | ||
required: true | ||
type : string | ||
tflint-version: | ||
description: "TFLint version to use for the tests." | ||
required: true | ||
type : string | ||
|
||
env: | ||
ARM_TENANT_ID: ${{ secrets.REPO_AZURE_DSB_TENANT_ID }} | ||
ARM_SUBSCRIPTION_ID: ${{ secrets.REPO_AZURE_SUBSCRIPTION_ID }} | ||
ARM_CLIENT_ID: ${{ secrets.REPO_AZURE_TERRAFORM_USER_SERVICE_PRINCIPAL }} | ||
ARM_USE_OIDC: true | ||
ARM_USE_AZUREAD: true | ||
TF_IN_AUTOMATION: true | ||
|
||
jobs: | ||
create-matrix: | ||
name: Create job matrix | ||
runs-on: [self-hosted, dsb-terraformer, linux, x64] | ||
defaults: | ||
run: | ||
shell: bash | ||
outputs: | ||
all_tests: ${{ steps.create-matrix.outputs.all_tests }} | ||
plugin_cache_directory: ${{ steps.setup-terraform-cache.outputs.plugin-cache-directory }} | ||
Artlvns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
steps: | ||
- name: "🧹 Clean workspace" | ||
uses: dsb-norge/directory-recreate@v1 | ||
|
||
- name: "⬇ Checkout working branch" | ||
uses: actions/checkout@v4 | ||
|
||
- name: "🎰 Create env matrix" | ||
id: create-matrix | ||
# TODO revert to @v0 | ||
uses: dsb-norge/github-actions-terraform/create-tftest-matrix@tf-test | ||
|
||
- name: "📥 Setup Terraform" | ||
uses: hashicorp/setup-terraform@v3 | ||
with: | ||
terraform_version: ${{ inputs.terraform-version }} | ||
terraform_wrapper: false | ||
Artlvns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: "🗄️ Setup Terraform provider plugin cache" | ||
id: setup-terraform-cache | ||
# TODO revert to @v0 | ||
uses: dsb-norge/github-actions-terraform/setup-terraform-plugin-cache@tf-test | ||
|
||
- name: "📥 Setup TFLint" | ||
id: setup-tflint | ||
# TODO revert to @v0 | ||
uses: dsb-norge/github-actions-terraform/setup-tflint@tf-test | ||
with: | ||
tflint-version: ${{ inputs.tflint-version }} | ||
working-directory: ${{ github.workspace }} | ||
|
||
- name: "🚀 Cache Terraform provider plugins" | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.setup-terraform-cache.outputs.plugin-cache-directory }} | ||
key: "terraform-provider-plugin-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('./.terraform.lock.hcl') }}" | ||
Artlvns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: ⚙️ Terraform Init | ||
id: init | ||
# TODO revert to @v0 | ||
uses: dsb-norge/github-actions-terraform/terraform-init@tf-test | ||
with: | ||
working-directory: ${{ github.workspace }} | ||
additional-dirs-json: null | ||
Artlvns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue-on-error: true # allow job to continue, step outcome is evaluated later | ||
|
||
- name: 🖌 Terraform Format | ||
id: fmt | ||
# TODO revert to @v0 | ||
uses: dsb-norge/github-actions-terraform/terraform-fmt@tf-test | ||
with: | ||
working-directory: ${{ github.workspace }} | ||
format-check-in-root-dir: true | ||
continue-on-error: true # allow job to continue, step outcome is evaluated later | ||
|
||
- name: ✔ Terraform Validate | ||
id: validate | ||
# TODO revert to @v0 | ||
uses: dsb-norge/github-actions-terraform/terraform-validate@tf-test | ||
with: | ||
working-directory: ${{ github.workspace }} | ||
continue-on-error: true # allow job to continue, step outcome is evaluated later | ||
|
||
- name: 🧹 Lint with TFLint | ||
id: lint | ||
# TODO revert to @v0 | ||
uses: dsb-norge/github-actions-terraform/lint-with-tflint@tf-test | ||
with: | ||
working-directory: ${{ github.workspace }} | ||
continue-on-error: true # allow job to continue, step outcome is evaluated later | ||
|
||
- name: 📝 Create validation summary | ||
id: create-validation-summary | ||
if: github.event_name == 'pull_request' | ||
# TODO revert to @v0 | ||
uses: dsb-norge/github-actions-terraform/create-validation-summary@tf-test | ||
with: | ||
environment-name: "module" | ||
plan-txt-output-file: ${{ steps.plan.outputs.txt-output-file }} | ||
Artlvns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
status-init: ${{ steps.init.outcome }} | ||
status-fmt: ${{ steps.fmt.outcome }} | ||
status-validate: ${{ steps.validate.outcome }} | ||
status-lint: ${{ steps.lint.outcome }} | ||
status-plan: ${{ steps.plan.outcome }} | ||
Artlvns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue-on-error: true # allow job to continue, step outcome is ignored | ||
|
||
- name: 🏷️ Add validation summary as pull request comment | ||
id: validation-summary-on-pr | ||
if: steps.create-validation-summary.outcome == 'success' | ||
uses: dsb-norge/github-actions/ci-cd/comment-on-pr@v2 | ||
with: | ||
pr-comment-text: ${{ steps.create-validation-summary.outputs.summary }} | ||
delete-comments-starting-with: ${{ steps.create-validation-summary.outputs.prefix }} | ||
continue-on-error: true # allow job to continue, step outcome is ignored | ||
|
||
- name: "🧐 Validation outcome: ⚙️ Init" | ||
run: | | ||
if [ ! "${{ steps.init.outcome }}" == 'success' ]; then | ||
echo "::error title=Init failed::Outcome of terraform init step was '${{ steps.init.outcome }}'!" | ||
exit 1 | ||
fi | ||
continue-on-error: false | ||
- name: "🧐 Validation outcome: 🖌 Format" | ||
run: | | ||
if [ ! "${{ steps.fmt.outcome }}" == 'success' ]; then | ||
echo "::error title=Format check failed::Outcome of terraform fmt step was '${{ steps.fmt.outcome }}'!" | ||
exit 1 | ||
fi | ||
continue-on-error: false | ||
- name: "🧐 Validation outcome: ✔ Validate" | ||
run: | | ||
if [ ! "${{ steps.validate.outcome }}" == 'success' ]; then | ||
echo "::error title=Validate failed::Outcome of terraform validate step was '${{ steps.validate.outcome }}' !" | ||
exit 1 | ||
fi | ||
continue-on-error: false | ||
- name: "🧐 Validation outcome: 🧹 TFLint" | ||
run: | | ||
if [ ! "${{ steps.lint.outcome }}" == 'success' ]; then | ||
echo "::error title=Lint failed::Outcome of TFLint step was '${{ steps.lint.outcome }}'!" | ||
exit 1 | ||
fi | ||
continue-on-error: false | ||
|
||
|
||
terraform-module-ci: | ||
name: "Terraform" | ||
Artlvns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
needs: create-matrix | ||
runs-on: [self-hosted, dsb-terraformer, linux, x64] | ||
strategy: | ||
fail-fast: false # Allow jobs to continue even though one more env(s) fail | ||
matrix: | ||
files: ${{ fromJSON(needs.create-matrix.outputs.all_tests).files }} | ||
Artlvns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- name: "⬇ Checkout" | ||
uses: actions/checkout@v4 | ||
|
||
- name: "📥 Setup Terraform" | ||
uses: hashicorp/setup-terraform@v3 | ||
with: | ||
terraform_version: ${{ inputs.terraform-version }} | ||
terraform_wrapper: false | ||
Artlvns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: "🚀 Cache Terraform provider plugins" | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ needs.create-matrix.outputs.plugin_cache_directory }} | ||
key: "terraform-provider-plugin-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('./.terraform.lock.hcl') }}" | ||
Artlvns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: ⚙️ Terraform Init | ||
id: init | ||
# TODO revert to @v0 | ||
uses: dsb-norge/github-actions-terraform/terraform-init@tf-test | ||
with: | ||
working-directory: ${{ github.workspace }} | ||
additional-dirs-json: null | ||
Artlvns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue-on-error: true # allow job to continue, step outcome is evaluated later | ||
|
||
- name: 🧪 Terraform Test | ||
id: test | ||
# TODO revert to @v0 | ||
uses: dsb-norge/github-actions-terraform/terraform-test@tf-test | ||
with: | ||
test-file: ${{ matrix.files }} | ||
Artlvns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue-on-error: true # allow job to continue, step outcome is evaluated later | ||
|
||
- name: 📝 Create test report | ||
id: create-test-report | ||
if: github.event_name == 'pull_request' | ||
# TODO revert to @v0 | ||
uses: dsb-norge/github-actions-terraform/create-test-report@tf-test | ||
with: | ||
test-out-file: ${{ steps.test.outputs.json }} | ||
status-init: ${{ steps.init.outcome }} | ||
status-test: ${{ steps.test.outcome }} | ||
test-summary: ${{ steps.test.outputs.summary }} | ||
test-report: ${{ steps.test.outputs.report }} | ||
continue-on-error: true # allow job to continue, step outcome is evaluated later | ||
|
||
- name: 🏷️ Add validation summary as pull request comment | ||
id: validation-summary-on-pr | ||
if: steps.create-test-report.outcome == 'success' | ||
uses: dsb-norge/github-actions/ci-cd/comment-on-pr@v2 | ||
with: | ||
pr-comment-text: ${{ steps.create-test-report.outputs.summary }} | ||
delete-comments-starting-with: ${{ steps.create-test-report.outputs.prefix }} | ||
continue-on-error: true # allow job to continue, step outcome is ignored | ||
|
||
# Terminate the job with 'failure' if any validation check did not succeed. | ||
# If 'allow-failing-terraform-operations' is 'true' for the environment the job will not terminate. | ||
|
||
- name: "🧐 Validation outcome: ⚙️ Init" | ||
run: | | ||
if [ ! "${{ steps.init.outcome }}" == 'success' ]; then | ||
echo "::error title=Init failed::Outcome of terraform init step was '${{ steps.init.outcome }}'!" | ||
exit 1 | ||
fi | ||
continue-on-error: false | ||
|
||
- name: "🧐 Validation outcome: 🧪 Test" | ||
run: | | ||
if [ ! "${{ steps.test.outcome }}" == 'success' ]; then | ||
echo "::error title=Test failed::Outcome of terraform test step was '${{ steps.test.outcome }}' for file '${{ matrix.files }}'!" | ||
exit 1 | ||
fi | ||
continue-on-error: false | ||
|
||
# create a global result indicating if workflow steps succeeded or not, | ||
# handy for branch protection rules | ||
conclusion: | ||
if: always() | ||
name: "Terraform conclusion" | ||
needs: [create-matrix, terraform-module-ci] | ||
runs-on: [self-hosted, dsb-terraformer, linux, x64] | ||
Artlvns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- run: exit 1 | ||
# for explanation of '>-' below see https://stackoverflow.com/a/67532120/4907315 | ||
# job 'result': possible values are 'success', 'failure', 'cancelled', or 'skipped' | ||
if: >- | ||
${{ | ||
contains(needs.*.result, 'failure') | ||
|| contains(needs.*.result, 'cancelled') | ||
}} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.