# 错误：后端配置冲突：为 's3' 后端指定了部分后端配置

- **ID:** `terraform/conflicting-backend-configuration`
- **领域:** terraform
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

Terraform 后端配置同时在 terraform 块和命令行 -backend-config 选项中部分指定，导致无法解决的冲突。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Terraform v1.5 | active | — | — |
| Terraform v1.6 | active | — | — |
| Terraform v1.7 | active | — | — |

## 解决方案

1. ```
   Use a fully specified backend block in the terraform configuration: `terraform { backend "s3" { bucket = "my-bucket" key = "path/to/state" region = "us-east-1" } }` and remove all -backend-config flags from the init command.
   ```
2. ```
   Use only command-line -backend-config options with an empty backend block: `terraform { backend "s3" {} }` then run `terraform init -backend-config="bucket=my-bucket" -backend-config="key=path/to/state"`.
   ```
3. ```
   Run `terraform init -reconfigure` to force reinitialization and ignore existing state configuration, then provide complete config via -backend-config flags.
   ```

## 无效尝试

- **Removing all -backend-config flags and relying solely on the terraform block** — If the terraform block itself is incomplete (e.g., missing required attributes like bucket or key), init will fail with missing configuration errors. (65% 失败率)
- **Setting all backend config directly in the terraform block without any -backend-config flags, then rerunning init** — If the backend block contains partial config that conflicts with inherited state, Terraform may still detect a mismatch and refuse to initialize. (50% 失败率)
- **Deleting the .terraform directory and rerunning init without -backend-config** — Deleting .terraform doesn't resolve the config conflict; Terraform will still parse the backend block and report the same error if partial config remains. (80% 失败率)
