hashicorp/terraform · error
Error parsing %s: %s
Error message
Error parsing %s: %s
What it means
Emitted by `loadConfigFile` (cliconfig.go:167) when `hcl.Parse` fails on the contents of a CLI config file. This is an HCL syntax error in the file itself — the bytes were read successfully but do not form a valid HCL top-level structure. The `%s` values are the path and the HCL parser error.
Source
Thrown at internal/command/cliconfig/cliconfig.go:167
// loadConfigFile loads the CLI configuration from ".terraformrc" files.
func loadConfigFile(path string) (*Config, tfdiags.Diagnostics) {
var diags tfdiags.Diagnostics
result := &Config{}
log.Printf("Loading CLI configuration from %s", path)
// Read the HCL file and prepare for parsing
d, err := ioutil.ReadFile(path)
if err != nil {
diags = diags.Append(fmt.Errorf("Error reading %s: %s", path, err))
return result, diags
}
// Parse it
obj, err := hcl.Parse(string(d))
if err != nil {
diags = diags.Append(fmt.Errorf("Error parsing %s: %s", path, err))
return result, diags
}
// Build up the result
if err := hcl.DecodeObject(&result, obj); err != nil {
diags = diags.Append(fmt.Errorf("Error parsing %s: %s", path, err))
return result, diags
}
// Deal with the provider_installation block, which is not handled using
// DecodeObject because its structure is not compatible with the
// limitations of that function.
providerInstBlocks, moreDiags := decodeProviderInstallationFromConfig(obj)
diags = diags.Append(moreDiags)
result.ProviderInstallation = providerInstBlocks
// Replace all env vars
for k, v := range result.Providers {View on GitHub (pinned to c9def3e214)
Solutions
- Open the file named in the error and fix the HCL syntax at the line/column the parser reports.
- Validate with an HCL linter or by running `terraform init` again to surface the precise location.
- Compare against a known-good `.terraformrc` block structure (e.g. `credentials "app.terraform.io" { token = "..." }`).
- If unsure, comment out suspect blocks with `#` and re-run.
Example fix
# before (~/.terraformrc)
credentials "app.terraform.io" {
token = "atlasv1..."
# missing closing brace
# after
credentials "app.terraform.io" {
token = "atlasv1..."
} Defensive patterns
Strategy: try-catch
Validate before calling
// Validate HCL syntax with the same parser the loader uses (best-effort).
import "github.com/hashicorp/hcl"
func configParses(path string) error {
b, err := os.ReadFile(path)
if err != nil {
return err
}
_, err = hcl.Parse(string(b))
return err
} Try / catch
// cfg, diags := cliconfig.LoadConfig()
for _, d := range diags {
if strings.HasPrefix(d.Description().Summary, "Error parsing") {
// Point user to the line/col reported by HCL.
}
} Prevention
- Lint `.terraformrc` edits before committing.
- Keep block/brace structure balanced; close every `{`.
- Avoid pasting JSON into an HCL file.
When it happens
Trigger: A `.terraformrc` (or `*.tfrc`) file containing malformed HCL: unclosed blocks, bad attribute syntax, stray characters, mismatched quotes/braces.
Common situations: Hand-editing the CLI config and leaving a typo; pasting JSON into an HCL file; truncation from a crashed editor; mixing tabs/spaces incorrectly in block headers.
Related errors
- Error reading %s: %s
- Cannot set both 'source' and 'content'
- Must provide one of 'source' or 'content'
- invalid null string in 'scripts'
- invalid empty string in 'scripts'
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/93ec7cfb164bed72.
Report an issue: GitHub.