Skip to content
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

Issue #87: Adds reusable workflow for terraform linting #88

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 37 additions & 0 deletions .github/workflows/workflow-terraform-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Reusable Workflow for Terraform Conformance to AI Lab Standards

## Overview

This workflow ensures that Terraform configurations align with the AI Lab's
standards for infrastructure as code. It is designed to automate the enforcement
of code quality and organizational best practices for Terraform files across
various projects.

## Usage

- **Purpose:** Automatically validate and enforce coding standards for Terraform
configurations within the organization. It triggers on **workflow calls** to
repositories and **pushes** to this repository, performing checks to ensure
Terraform files comply with predefined standards.
- **Steps:**
- **Terraform Format Check:** Verifies that Terraform files are formatted
according to Terraform's conventions using `terraform fmt`.
- **TFLint Check:** Runs TFLint to lint Terraform files, identifying potential
issues and deviations from best practices.
- **Input:** Optionally specify a custom configuration file path for TFLint to
use a specific set of rules.

## Terraform Linting Guidelines for Developers

- Developers are encouraged to use the [Terraform
linters/TFLint](https://github.com/terraform-linters/tflint) tool for locally
linting their Terraform files.

## Custom Configuration

If your project requires specific linting rules beyond the AI Lab's standard
set, you can create a `.tflint.hcl` file in your project's root directory.
Specify the path to this file when triggering the workflow to apply your custom
rules. The format and options for this configuration file are documented in the
[TFLint Configuration File Format]
(https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/config.md).
45 changes: 45 additions & 0 deletions .github/workflows/workflow-terraform-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: Check Terraform conformance to AI Lab standards

on:

Check warning on line 4 in .github/workflows/workflow-terraform-check.yml

View workflow job for this annotation

GitHub Actions / yaml-lint-check

4:1 [truthy] truthy value should be one of [false, true]
workflow_call:
inputs:
config-file-path:
required: false
type: string

jobs:
terraform-format-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: latest

- name: Terraform Initialization
run: terraform init

- name: Terraform Format Check
run: terraform fmt -check -recursive -diff

- uses: terraform-linters/setup-tflint@v3
name: Setup TFLint
with:
tflint_version: v0.44.1

- name: Init TFLint
run: tflint --init

- name: Run TFLint
run: |
if [ -n "${{ github.event.inputs.config-file-path }}" ]; then
tflint --recursive --config \
"${{ github.workspace }}/
${{ github.event.inputs.config-file-path }}"
else
tflint --recursive
fi
Loading