Repository: terraform-linters/tflint (Go)

Issue:
`terraform_required_providers`: allow missing `version` for built-in providers
`terraform test` does not support a `version` parameter [yet](https://github.com/hashicorp/terraform/issues/30164). currently tflint is warning, failing CI (see below). I believe the `tflint-ignore` is not taking effect because there is actually no line to ignore. It would be nice if there was a workaround for situations like this. If im missing something please lmk!

```hcl
terraform {
  required_version = ">= 1.1.0"

  required_providers {
    test = {
      # tflint-ignore: terraform_required_providers
      source = "terraform.io/builtin/test"
    }
}
```

```
Warning: Missing version constraint for provider "test" in "required_providers" (terraform_required_providers)

  on tests.tf line 16:
  16: resource "test_assertions" "ipam_vpc_explicit_netmask" {

Reference: https://github.com/terraform-linters/tflint/blob/v0.33.1/docs/rules/terraform_required_providers.md
```

## Version

```console
$ tflint -v
TFLint version 0.33.1
WARNING: The plugin `aws` is not explicitly enabled. The bundled plugin will be enabled instead, but it is deprecated and will be removed in a future version. Please see https://github.com/terraform-linters/tflint/pull/1160 for details.
+ ruleset.aws (0.8.0-bundled)

$ tf -v  
Terraform v1.1.0
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v3.69.0
```



Discussion:
Annotation works for the reported line. In this case, you should add the `tflint-ignore` comment on `test.tf` line 15 or 16.
https://github.com/terraform-linters/tflint/blob/v0.33.1/docs/user-guide/annotations.md
Built in providers may not have a version distinct from the Terraform CLI version. Ignoring the builtin namespace is reasonable.  
@wata727 is correct that ignoring the resource (rather than the provider block) does properly prevent the error. thank you!

@bendrucker is this a potential FR or should we close this issue? Im happy to reword the issue if you see a FR coming out of this 
Leave it open, it's an easy PR for anyone and I'll get to it otherwise. 



Patch:
diff --git a/rules/terraformrules/terraform_required_providers.go b/rules/terraformrules/terraform_required_providers.go
index 70896334f..9f98acce3 100644
--- a/rules/terraformrules/terraform_required_providers.go
+++ b/rules/terraformrules/terraform_required_providers.go
@@ -5,6 +5,7 @@ import (
 	"log"
 
 	"github.com/hashicorp/hcl/v2"
+	"github.com/terraform-linters/tflint/terraform/configs"
 	"github.com/terraform-linters/tflint/tflint"
 )
 
@@ -62,28 +63,32 @@ func (r *TerraformRequiredProvidersRule) Check(runner *tflint.Runner) error {
 		}
 	}
 
-	for _, resource := range module.ManagedResources {
-		if _, ok := providers[resource.Provider.Type]; !ok {
-			providers[resource.Provider.Type] = resource.DeclRange
-		}
-	}
+	providers = providerResourceRanges(providers, module.ManagedResources)
+	providers = providerResourceRanges(providers, module.DataResources)
 
-	for _, data := range module.DataResources {
-		if _, ok := providers[data.Provider.Type]; !ok {
-			providers[data.Provider.Type] = data.DeclRange
+	for name, decl := range providers {
+		if provider, ok := module.ProviderRequirements.RequiredProviders[name]; !ok || provider.Requirement.Required == nil {
+			runner.EmitIssue(r, fmt.Sprintf(`Missing version constraint for provider "%s" in "required_providers"`, name), decl)
 		}
 	}
 
-	for name, decl := range providers {
-		// builtin
-		if name == "terraform" {
+	return nil
+}
+
+func providerResourceRanges(providers map[string]hcl.Range, resources map[string]*configs.Resource) map[string]hcl.Range {
+	for _, resource := range resources {
+		provider := resource.Provider
+
+		if provider.IsBuiltIn() {
 			continue
 		}
 
-		if provider, ok := module.ProviderRequirements.RequiredProviders[name]; !ok || provider.Requirement.Required == nil {
-			runner.EmitIssue(r, fmt.Sprintf(`Missing version constraint for provider "%s" in "required_providers"`, name), decl)
+		if _, ok := providers[provider.Type]; ok {
+			continue
 		}
+
+		providers[resource.Provider.Type] = resource.DeclRange
 	}
 
-	return nil
+	return providers
 }


Test patch:
diff --git a/rules/terraformrules/terraform_required_providers_test.go b/rules/terraformrules/terraform_required_providers_test.go
index 06ec05e39..45906260d 100644
--- a/rules/terraformrules/terraform_required_providers_test.go
+++ b/rules/terraformrules/terraform_required_providers_test.go
@@ -244,6 +244,21 @@ provider "template" {
 			Name: "terraform provider",
 			Content: `
 data "terraform_remote_state" "foo" {}
+`,
+			Expected: tflint.Issues{},
+		},
+		{
+			Name: "builtin provider",
+			Content: `
+terraform {
+	required_providers {
+		test = {
+			source = "terraform.io/builtin/test"
+		}
+	}
+}
+
+resource "test_assertions" "foo" {}
 `,
 			Expected: tflint.Issues{},
 		},