JanDeDobbeleer/oh-my-posh · warning
no valid terraform files found
Error message
no valid terraform files found
What it means
The terraform segment in oh-my-posh reports the Terraform version by scanning version sources. setVersionFromTfFiles looks for `versions.tf` or `main.tf` in the working directory and extracts the required_version constraint. It throws 'no valid terraform files found' when neither file exists or neither contains a parseable required_version block, i.e. it was the last remaining way to determine the version and it failed.
Source
Thrown at src/segments/terraform.go:164
}
func (tf *Terraform) setVersionFromTfFiles() error {
files := []string{"versions.tf", "main.tf"}
for _, file := range files {
if !tf.env.HasFiles(file) {
continue
}
content := tf.env.FileContent(file)
version, ok := extractRequiredVersion(content)
if !ok {
continue
}
tf.Version = &version
return nil
}
return errors.New("no valid terraform files found")
}
func (tf *Terraform) setVersionFromTfStateFile() {
file := "terraform.tfstate"
if !tf.env.HasFiles(file) {
return
}
content := tf.env.FileContent(file)
_ = json.Unmarshal([]byte(content), &tf.TerraformBlock)
}
View on GitHub (pinned to 0976794618)
Solutions
- Create a versions.tf or main.tf containing a terraform { required_version = "x.y.z" } block
- Set the TENV version source (TERRAFORM_VERSION / .terraform-version file) which takes precedence
- Remove or conditionally disable the terraform segment in the prompt config when not in a Terraform project
- Verify extractRequiredVersion matches your required_version syntax and simplify the constraint
Example fix
// before: versions.tf without version pin
provider "aws" { region = "eu-west-1" }
// after
terraform {
required_version = "~> 1.9.0"
} Defensive patterns
Strategy: fallback
Validate before calling
// shell: before relying on the segment, ensure a version source exists [ -f versions.tf ] || [ -f main.tf ] || [ -n "$TERRAFORM_VERSION" ] || [ -f .terraform-version ]
Try / catch
// segment consumers treat the error as "hide segment"; if embedding, wrap:
if err := tf.setVersionFromTfFiles(); err != nil {
// fall back to tfstate/tenv sources or disable the segment
} Prevention
- Always keep a required_version pin in versions.tf or main.tf
- Configure TENV-style sources so the env var path resolves first
- Disable the terraform segment outside Terraform projects
When it happens
Trigger: The terraform segment is enabled (Enabled calls setVersionFromTfFiles after TENV env var/file checks fail) and: (1) neither versions.tf nor main.tf is present in the directory, (2) the files exist but contain no required_version terraform block, or (3) the required_version string is malformed and extractRequiredVersion fails.
Common situations: Running in a subdirectory without a main.tf; a fresh module that pins versions only in .terraform.lock.hcl or required_providers; using `required_version` written with unusual syntax the extractor doesn't recognize; treating this as a fatal error when the segment simply should hide.
Related errors
- empty m_EditorVersion
- ProjectSettings/ProjectVersion.txt is missing m_EditorVersio
- unable to get data for team %s
- %d is not a valid game status
- no pulumi spec file found
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/c7be9a015298fdc3.
Report an issue: GitHub.