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

Redesign config schema #1953

Open
wata727 opened this issue Jan 4, 2024 · 0 comments
Open

Redesign config schema #1953

wata727 opened this issue Jan 4, 2024 · 0 comments
Labels
enhancement needs-design Detailed design is required for implementation

Comments

@wata727
Copy link
Member

wata727 commented Jan 4, 2024

Introduction

The .tflint.hcl configuration schema has remained largely unchanged since its design, but I believe there are better designs out there now. The current (v0.50) schema is shown below:

config {
  call_module_type    = string
  force               = bool
  ignore_module       = map(bool)
  varfile             = list(string)
  variables           = list(string)
  disabled_by_default = bool
  plugin_dir          = string
  format              = string
}

plugin "name" {
  enabled     = bool
  version     = string
  source      = string
  signing_key = string

  [plugin custom fields]
}

rule "name" {
  enabled = bool

  [plugin custom fields]
}

This schema has the following issues:

  • Top-level config block is redundant. As I recall, this was introduced simply for implementation reasons at the time. This limitation no longer exists.
  • ignore_module is set by a module source, not an ID, so you cannot ignore a module exactly. Also, originally, list(string) should be enough instead of map(bool).
  • varfile is poorly named. Given that the CLI flag in Terraform is --var-file, var_file is appropriate. var_files is the best because it accepts multiple files.
  • variables is accepted as simple string, but HCL allows for more flexible expressions. Imagine being able to write *.tfvars inline.
  • There is a mix of different types of attributes within the config block. For example, it may be easier to understand if attributes that affect inspection and attributes that affect output are grouped in separate blocks.
  • Plugin custom fields and reserved fields may conflict. Adding new reserved attributes in the future may impact existing plugins.
  • Since rules are provided by plugins, it might be possible to nest rule blocks inside plugin blocks.

Proposal

Redesign config schema like below:

force               = bool
disabled_by_default = bool
plugin_dir          = string
format              = string

terraform {
  var_files = list(map)
  variables = {
    foo = "bar"
    baz = 1
  }
  ignore_modules   = list(string)
  call_module_type = string
}

plugin "name" {
  enabled     = bool
  version     = string
  source      = string
  signing_key = string

  _ {
    [plugin custom fields]
  }

  rule "name" {
    enabled = bool

    _ {
      [plugin custom fields]
    }
  }
}

However, this is a draft and we do not guarantee that it will be changed to this schema. The final version should be considered for backward compatibility and impact on changes.

References

@wata727 wata727 added enhancement needs-design Detailed design is required for implementation labels Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement needs-design Detailed design is required for implementation
Development

No branches or pull requests

1 participant