Skip to content

Report & remove unused provider blocks #1481

Open
@radeksimko

Description

@radeksimko

Context

Discovered originally as part of hashicorp/vscode-terraform#1597

In Terraform [language], the provider blocks are generally considered a part of the configuration which does not "do" anything - i.e. does not create/update/delete anything, but it typically sets up the authentication and generally configures things, such that each resource or data source can leverage that and focus on the "doing".

This is why Terraform currently also ignores provider blocks without any corresponding resources and data sources and ignores those during plan, apply or validate.

terraform {
  required_providers {
    github = {
      source = "integrations/github"
    }
  }
}

provider "github" {
  foobar {}
  does_not_exist = true
}

^ the above will go unnoticed by terraform validate, terraform plan and terraform apply

This can lead to user confusion and in practice it represents "dead code".

Proposal

  • Introduce new warning diagnostic that highlights redundant provider blocks such as in the example above
  • Provide quickfix code action which removes such redundant provider blocks
  • (re)consider validating such redundant provider blocks further - e.g. for required attributes, blocks, invalid attribute names etc.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions