{"record":{"id":"c7be9a015298fdc3","repo":"JanDeDobbeleer/oh-my-posh","slug":"no-valid-terraform-files-found","errorCode":null,"errorMessage":"no valid terraform files found","messagePattern":"no valid terraform files found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/segments/terraform.go","lineNumber":164,"sourceCode":"}\n\nfunc (tf *Terraform) setVersionFromTfFiles() error {\n\tfiles := []string{\"versions.tf\", \"main.tf\"}\n\tfor _, file := range files {\n\t\tif !tf.env.HasFiles(file) {\n\t\t\tcontinue\n\t\t}\n\n\t\tcontent := tf.env.FileContent(file)\n\t\tversion, ok := extractRequiredVersion(content)\n\t\tif !ok {\n\t\t\tcontinue\n\t\t}\n\n\t\ttf.Version = &version\n\t\treturn nil\n\t}\n\treturn errors.New(\"no valid terraform files found\")\n}\n\nfunc (tf *Terraform) setVersionFromTfStateFile() {\n\tfile := \"terraform.tfstate\"\n\tif !tf.env.HasFiles(file) {\n\t\treturn\n\t}\n\n\tcontent := tf.env.FileContent(file)\n\t_ = json.Unmarshal([]byte(content), &tf.TerraformBlock)\n}\n","sourceCodeStart":146,"sourceCodeEnd":176,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/segments/terraform.go#L146-L176","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: versions.tf without version pin\nprovider \"aws\" { region = \"eu-west-1\" }\n// after\nterraform {\n  required_version = \"~> 1.9.0\"\n}","handlingStrategy":"fallback","validationCode":"// shell: before relying on the segment, ensure a version source exists\n[ -f versions.tf ] || [ -f main.tf ] || [ -n \"$TERRAFORM_VERSION\" ] || [ -f .terraform-version ]","typeGuard":null,"tryCatchPattern":"// segment consumers treat the error as \"hide segment\"; if embedding, wrap:\nif err := tf.setVersionFromTfFiles(); err != nil {\n    // fall back to tfstate/tenv sources or disable the segment\n}","preventionTips":["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"],"tags":["terraform","segment","version-detection","go"],"backgroundTag":"version-source-not-found","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}