Skip to content

New Code Action: Resolve unexpected block #1563

Open
@radeksimko

Description

@radeksimko

Background

We currently report the following configuration as invalid:

terraform {
  my_block {

  }
}

validation-rule-unexpected-block

There can be multiple reasons for an unknown block:

  • too old/new schema we use for validation
  • typo
  • some hallucinated code generated by AI

It may be difficult to find the best solution if we don't know or can't guess the reason. Removing a block is a solution relevant in some contexts and not others.

Proposal

  • Consider providing quick fix code action which resolves the above diagnostic by removing the block

Further Thoughts

It may be worth looking at how the LS could guess the reason and provide more helpful quick fixes.

For example:

  • we could compare the block name with valid block names more loosely, just like Terraform Core does in its didyoumean package, so that we can suggest correction from e.g. terrafrom {} to terraform {} etc.
  • attempt to compare block names with other versions of the provider schema

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