Skip to content

Experimental: TFLint plugin SDK for building custom rules

License

Notifications You must be signed in to change notification settings

terraform-linters/tflint-plugin-sdk

Repository files navigation

TFLint plugin SDK

Build Status GitHub release go.dev reference License: MPL 2.0

TFLint plugin SDK for building custom rules.

NOTE: This plugin system is experimental. This means that API compatibility is frequently broken.

Requirements

  • TFLint v0.42+
  • Go v1.22

Usage

Please refer to tflint-ruleset-template for an example plugin implementation using this SDK.

For more details on the API, see https://pkg.go.dev/github.com/terraform-linters/tflint-plugin-sdk.

Developing

The proto compiler is required when updating .proto files. The protoc and protoc-gen-go can be installed using aqua.

$ make prepare
curl -sSfL https://raw.githubusercontent.com/aquaproj/aqua-installer/v2.1.1/aqua-installer | bash
===> Installing aqua v2.2.3 for bootstraping...

...

aqua version 2.3.7 (c07105b10ab825e7f309d2eb83278a0422a2b24f)

Add ${AQUA_ROOT_DIR}/bin to the environment variable PATH.
export PATH="${AQUA_ROOT_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/aquaproj-aqua}/bin:$PATH"
$ export PATH="${AQUA_ROOT_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/aquaproj-aqua}/bin:$PATH"
$ aqua install
$ make proto

Architecture

This plugin system uses go-plugin. TFLint launch plugins as sub-processes and communicates with plugins over gRPC. A plugin acts as a server, while TFLint acts as a client that sends inspection requests to the plugin.

On the other hand, the plugin sends various requests to a server (TFLint) to get detailed runtime contexts (e.g. variables and expressions). This means that TFLint and plugins can act as both a server and a client.

This SDK provides client, server and Protocol Buffers for these bi-directional communications. See Architecture for more details.