# 错误：无效的目标：给定的目标无效：资源地址必须是有效的资源实例

- **ID:** `terraform/targeted-apply-without-plan`
- **领域:** terraform
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

使用了格式不正确的资源地址的 -target 选项，例如缺少资源类型或名称。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.5.0 | active | — | — |
| 1.6.0 | active | — | — |
| 1.7.0 | active | — | — |
| 1.8.0 | active | — | — |

## 解决方案

1. ```
   使用正确的资源地址格式：terraform apply -target="aws_instance.web"。对于模块：-target="module.vpc.aws_subnet.public"。使用 terraform state list 验证地址。
   ```
2. ```
   如果针对具有 count 或 for_each 的资源，请包含索引：-target="aws_instance.web[0]" 或 -target='aws_instance.web["key1"]'。
   ```
3. ```
   在应用之前使用 terraform plan -target 进行预览：terraform plan -target="aws_instance.web" -out=tfplan && terraform apply tfplan。
   ```

## 无效尝试

- **Use the resource name only without the type, e.g., -target=my_resource.** — Terraform requires the full address format: resource_type.resource_name. A bare name is not recognized. (100% 失败率)
- **Use -target with a module path that doesn't exist.** — The target must reference an existing resource in the configuration; non-existent paths cause the same error. (90% 失败率)
- **Run terraform apply without any target, ignoring the need for targeted operations.** — This applies all changes, which may not be desired and could cause unintended side effects. (60% 失败率)
