# 错误：无效的属性值：给定的值不适用于属性 "tags"：字符串值不能为 null

- **ID:** `terraform/invalid-nullable-attribute`
- **领域:** terraform
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

期望字符串或字符串映射的资源属性接收到了 null 值，通常来自条件表达式或求值为 null 的变量。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Terraform 1.3.0 | active | — | — |
| Terraform 1.4.0 | active | — | — |
| Terraform 1.5.0 | active | — | — |

## 解决方案

1. ```
   使用 coalesce() 函数在变量为 null 时提供默认的非 null 值。
   ```
2. ```
   使用条件逻辑和 try() 结合类型约束确保 null 值被替换。或者，为变量定义默认的非 null 值。
   ```
3. ```
   如果属性是可选的并且可以省略，使用动态块或条件逻辑在值为 null 时完全跳过它。
   ```

## 无效尝试

- **** — Some AWS services reject empty strings for required tags. The provider may still throw an error if the service requires non-empty values. (60% 失败率)
- **** — If the attribute is required, Terraform will error with 'Required attribute is not set'. Removing it doesn't fix the null issue. (85% 失败率)
- **** — try() only catches errors, not null values. If the expression evaluates to null without error, try() returns null. (75% 失败率)
