Error Handling
This page discusses common error scenarios, HTTP status codes, and troubleshooting tips you may encounter when using the Terraform Editor API. Understanding how errors are reported will help you debug issues quickly and keep your workflow running smoothly.
Error Response Structure
When something goes wrong, the API returns a JSON body with:
{
"success": false,
"error": {
"code": "string",
"message": "string",
"location": "terraform-edit"
},
"message": "string"
}
success: Alwaysfalsefor error responses.error.code: Short code describing the issue (e.g.,"INVALID_REQUEST","AMBIGUOUS_MATCH", etc.).error.message: More human-readable description of the problem.error.location: Typically"terraform-edit", indicating which part of the system generated the error.message: Mirrors theerror.messageor provides additional context.
Common Error Codes
Below are some frequent error codes you might see, along with suggestions on how to resolve them.
1. MISSING_CODE
- When It Happens: The request body doesn't include the required
codefield. - Fix: Provide
"code"with your Terraform configuration string.
2. INVALID_REQUEST
- When It Happens:
- The JSON request is malformed or missing required fields.
- The
editsfield doesn't contain at least one operation key (add,update,set, ordelete). - An internal parsing issue occurred due to incorrect JSON structure.
- Fix: Verify you have a valid JSON structure and that
codeandeditsare present.
3. AMBIGUOUS_MATCH
- When It Happens: An
update,delete, orsetoperation matches more than one block without selectors. - Fix: Use
index,where, orlabelsto narrow down the target block. If you need to modify multiple blocks, include multiple array items or use separate operations.
4. BLOCK_NOT_FOUND or NO_MATCH
- When It Happens: An
update,delete, orsetoperation can't find any block matching the provided type/name/selector. - Fix: Confirm the block actually exists in your
code. If you're trying to create it, useaddorset. If you're sure it should exist, double-check your labels,whereattributes, or names.
5. DUPLICATE_BLOCK
- When It Happens: An
addoperation tries to create a block that already exists (same type/name). - Fix: If you intend to update the existing block, use
updateorset. If you truly want a second block, adjust the label or name.
6. METHOD_NOT_ALLOWED
- When It Happens: You used an HTTP method other than
POST. - Fix: Send your request with
POST.
7. JSON_PARSE_ERROR
- When It Happens: The server can't parse your request body due to malformed JSON.
- Fix: Validate your JSON, remove trailing commas or extra quotes, ensure it's syntactically correct.
HTTP Status Codes Recap
200 OK: The request was successful;success: true.400 Bad Request: Client-side error—check your JSON structure, required fields, or ambiguous operations.405 Method Not Allowed: You used a non-POST request method.500 Internal Server Error: Unexpected server error—check logs or contact support if it persists.
Troubleshooting Checklist
- Validate Your JSON
- Make sure
codeis a string. - Confirm
editsis either a well-formed object or a valid JSON string.
- Make sure
- Include at Least One Operation
- At least one of
add,update,set, ordeletemust be present.
- At least one of
- Avoid Ambiguity
- If multiple blocks share the same type/name, use selectors (
where,index,labels) to target the correct block.
- If multiple blocks share the same type/name, use selectors (
- Check for Typos
- A single spelling mistake (like
"aws_intance"instead of"aws_instance") can prevent the API from finding your block.
- A single spelling mistake (like
- Verify Terraform Compatibility
- After you get
edited_code, runterraform validateto ensure it's valid Terraform syntax.
- After you get
Example Error Response
Below is an example of an ambiguous match error. Suppose you have two aws_instance blocks named "main" and run an update operation without selectors:
{
"success": false,
"error": {
"code": "AMBIGUOUS_MATCH",
"message": "Multiple blocks match aws_instance.main; use selectors to disambiguate",
"location": "terraform-edit"
},
"message": "Multiple blocks match aws_instance.main; use selectors to disambiguate"
}
Resolution: Add a where, index, or labels field to specify which instance you want to update.
When to Contact Support
If you've gone through the checklist and still encounter unexplained errors:
- Check our FAQ for additional tips on common edge cases.
- Reach out to our support team via email or community forums, providing:
- The request JSON you're sending (minus any sensitive info).
- The full error response from the API.
- Any logs or Terraform output that could help diagnose the problem.
Next Steps
- Review the API Reference for request/response structures.
- Explore FAQ if you still have unanswered questions.
- For deeper dives into usage patterns, check out our Guides and the Examples.