# Error: Invalid resource instance key: resource instance key must be a positive integer or a string

- **ID:** `terraform/resource-config-key-too-deep`
- **Domain:** terraform
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

Using a complex expression (like a list or map) as the key in a resource instance when Terraform expects a simple integer or string.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.5.0 | active | — | — |
| 1.6.0 | active | — | — |

## Workarounds

1. **Simplify the key expression to a single variable or literal. For example, use 'var.environment' instead of 'var.environment[0]' if the key is meant to be a string.** (90% success)
   ```
   Simplify the key expression to a single variable or literal. For example, use 'var.environment' instead of 'var.environment[0]' if the key is meant to be a string.
   ```
2. **Restructure the configuration to use a for_each with a map that has simple keys, or use count with a list.** (85% success)
   ```
   Restructure the configuration to use a for_each with a map that has simple keys, or use count with a list.
   ```

## Dead Ends

- **** — Wrapping the expression in tostring() or tolist() does not change the fundamental type mismatch. (90% fail)
- **** — Using count.index or for_each.key in a nested resource block still fails because the key must be a literal. (85% fail)
