How to fix Error: Unsuitable value type - string required in Terraform
This error occurs when Terraform receives a value of the wrong type for an argument. It commonly happens when passing a list where a string is expected, or wrapping already-typed values in extra brackets.
Quick fix
Fixes Error: Unsuitable value type - string required
Error: Inappropriate value for attribute "name": string required- Review the error message carefully
- Check if you're passing a list where a string is expected
- Remove unnecessary bracket wrapping
- Fix variable type declarations
Error: Inappropriate value for attribute "name": string requiredError: Unsuitable value type - string required
What this error means
Terraform is a strongly-typed language. Every resource argument, variable, and module input has a declared type (string, list, map, object, etc.). When you provide a value that doesn't match the expected type, Terraform raises an "unsuitable value type" error. This error most commonly occurs in three scenarios: 1. **Type Mismatch in Arguments**: You're passing a list value to an argument that expects a string, or vice versa. 2. **Wrapping Already-Typed Values**: You're unnecessarily wrapping a list in brackets (e.g., `["list_output"]` instead of just `list_output`). 3. **Nested Type Mismatches**: Object or map arguments have incompatible nested field types. The error message tells you exactly which argument needs fixing and what type is required.
Typical symptoms
- Terraform plan or apply fails with 'unsuitable value type - string required'
- Error message includes the argument name and expected type
- Configuration worked in an older Terraform version (especially if upgrading from 0.11 to 0.12+)
- Module or resource declarations that pass variables have type validation errors
Common causes
- Passing a list variable or output to an argument that expects a single string
- Wrapping a list output in extra brackets: `[module.vpc.private_route_table_ids]` when the output is already a list
- Removing the index from a list when a single value is needed: using `var.extensions` instead of `var.extensions[0]`
- Setting a variable default value that doesn't match the declared type constraint
- Terraform 0.12+ enforcing stricter type checking compared to 0.11
How to fix "Error: Unsuitable value type - string required"
The error will specify which argument is problematic and what type is required. For example:
Error: Inappropriate value for attribute "name": string requiredThis tells you that the name argument expects a string, not the type you provided.
If you're trying to pass a single item from a list, use indexing:
WRONG:
resource "aws_instance" "example" {
subnet_id = var.subnet_ids # List, but subnet_id expects a string
}RIGHT:
resource "aws_instance" "example" {
subnet_id = var.subnet_ids[0] # Get first item from list
}For dynamic selection, use element() function:
resource "aws_instance" "example" {
subnet_id = element(var.subnet_ids, 0)
}If an output is already a list, don't wrap it in brackets:
WRONG:
resource "aws_route_table_association" "private" {
route_table_id = ["module.vpc.private_route_table_ids"] # Extra brackets!
}RIGHT:
resource "aws_route_table_association" "private" {
route_table_id = module.vpc.private_route_table_id # Direct reference
}When a resource expects multiple values (like a list), pass it directly without extra brackets.
Ensure your variable type matches how you use it:
WRONG:
variable "database_name" {
type = string
default = ["mydb"] # Type says string but default is list!
}RIGHT:
variable "database_name" {
type = string
default = "mydb" # Matches the declared type
}Or if you need multiple values:
variable "database_names" {
type = list(string)
default = ["mydb", "otherdb"]
}If you need to convert a list to a string (rarely necessary), Terraform provides functions:
# Join a list into a single string
resource "example" "test" {
names = join(",", var.list_of_names)
}
# Convert to JSON for object arguments
resource "example" "test" {
tags = jsonencode(var.tag_object)
}Advanced notes
Terraform 0.12+ Migration Note: When upgrading from Terraform 0.11, type checking became much stricter. Configurations that worked before may need adjustment. Use terraform console to test expressions and verify their types before committing changes.
Type Conversion Strategy: While Terraform can automatically convert between numbers and strings in some cases, it cannot convert lists to strings. If you absolutely need string representation of a list, use jsonencode() or join() instead of relying on implicit conversion.
Module Outputs: When consuming module outputs, check the module's documentation for the exact output type. Module outputs can be strings, lists, maps, or objects—don't assume based on the output name.
Frequently asked questions
- What does "Error: Unsuitable value type - string required" mean?
- Terraform is a strongly-typed language. ). When you provide a value that doesn't match the expected type, Terraform raises an "unsuitable value type" error.
- How do I fix "Error: Unsuitable value type - string required"?
- This error occurs when Terraform receives a value of the wrong type for an argument. It commonly happens when passing a list where a string is expected, or wrapping already-typed values in extra brackets.
- What causes "Error: Unsuitable value type - string required"?
- Passing a list variable or output to an argument that expects a single string Wrapping a list output in extra brackets: [module.vpc.private_route_table_ids] when the output is already a list Removing the index from a list when a single value is needed: using var.extensions instead of var.extensions[0]
- Is the "Error: Unsuitable value type - string required" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚Terraform Official Documentation
- 📖Terraform Troubleshooting Workflow Guide(Official Docs)
- 📖Terraform Types and Values Documentation(Official Docs)
- 📖Terraform Type Constraints Reference(Official Docs)
- 🐙