github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/docs/rules/terraform_unused_declarations.md (about)

     1  # terraform_unused_declarations
     2  
     3  Disallow variables, data sources, and locals that are declared but never used.
     4  
     5  ## Example
     6  
     7  ```hcl
     8  variable "not_used" {}
     9  
    10  variable "used" {}
    11  output "out" {
    12    value = var.used
    13  }
    14  ```
    15  
    16  ```
    17  $ tflint
    18  1 issue(s) found:
    19  
    20  Warning: variable "not_used" is declared but not used (terraform_unused_declarations)
    21  
    22    on config.tf line 1:
    23     1: variable "not_used" {
    24  
    25  Reference: https://github.com/terraform-linters/tflint/blob/v0.15.5/docs/rules/terraform_unused_declarations.md
    26   
    27  ```
    28  
    29  ## Why
    30  
    31  Terraform will ignore variables and locals that are not used. It will refresh declared data sources regardless of usage. However, unreferenced variables likely indicate either a bug (and should be referenced) or removed code (and should be removed).
    32  
    33  ## How To Fix
    34  
    35  Remove the declaration. For `variable` and `data`, remove the entire block. For a `local` value, remove the attribute from the `locals` block.
    36  
    37  While data sources should generally not have side effects, take greater care when removing them. For example, removing `data "http"` will cause Terraform to no longer perform an HTTP `GET` request during each plan. If a data source is being used for side effects, add an annotation to ignore it:
    38  
    39  ```tf
    40  # tflint-ignore: terraform_unused_declarations
    41  data "http" "example" {
    42    url = "https://checkpoint-api.hashicorp.com/v1/check/terraform"
    43  }
    44  ```