terraform config_error ai_generated true

Error: Invalid required_providers block: duplicate required_providers block

ID: terraform/invalid-required-providers-block

Also available as: JSON · Markdown · 中文
95%Fix Rate
84%Confidence
1Evidence
2023-09-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.5.0 active
1.6.0 active
1.7.0 active

Root Cause

Multiple required_providers blocks exist in the same module, which Terraform does not allow.

generic

中文

同一模块中存在多个 required_providers 块,这是 Terraform 不允许的。

Official Documentation

https://developer.hashicorp.com/terraform/language/providers/requirements

Workarounds

  1. 95% success Consolidate all provider requirements into a single required_providers block in the root module. Remove any duplicate blocks.
    Consolidate all provider requirements into a single required_providers block in the root module. Remove any duplicate blocks.
  2. 90% success If using Terraform 1.5+, use the 'required_providers' attribute in a single block, combining all entries.
    If using Terraform 1.5+, use the 'required_providers' attribute in a single block, combining all entries.

中文步骤

  1. 将所有提供者需求合并到根模块中的单个 required_providers 块中。删除任何重复的块。
  2. 如果使用 Terraform 1.5+,在单个块中使用 'required_providers' 属性,合并所有条目。

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Merging the blocks with incorrect syntax still results in a duplicate block error.

  2. 80% fail

    Adding a required_providers block inside a submodule does not fix the root module; the error is per module.