{"record":{"id":"e444e882bc329dc8","repo":"hashicorp/terraform","slug":"configuration-file-did-not-contain-profile-s","errorCode":null,"errorMessage":"configuration file did not contain profile: %s","messagePattern":"configuration file did not contain profile: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/oci/util.go","lineNumber":68,"sourceCode":"\t\treturn \"\"\n\t}\n\treturn home\n}\nfunc checkProfile(profile string, path string) (err error) {\n\tvar profileRegex = regexp.MustCompile(`^\\[(.*)\\]`)\n\tdata, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn err\n\t}\n\tcontent := string(data)\n\tsplitContent := strings.Split(content, \"\\n\")\n\tfor _, line := range splitContent {\n\t\tif match := profileRegex.FindStringSubmatch(line); match != nil && len(match) > 1 && match[1] == profile {\n\t\t\treturn nil\n\t\t}\n\t}\n\n\treturn fmt.Errorf(\"configuration file did not contain profile: %s\", profile)\n}\n\n// cleans and expands the path if it contains a tilde , returns the expanded path or the input path as is if not expansion\n// was performed\nfunc expandPath(filepath string) string {\n\tif strings.HasPrefix(filepath, fmt.Sprintf(\"~%c\", os.PathSeparator)) {\n\t\tfilepath = path.Join(getHomeFolder(), filepath[2:])\n\t}\n\treturn path.Clean(filepath)\n}\n\nfunc getBackendAttrWithDefault(obj cty.Value, attrName, def string) (cty.Value, bool) {\n\tvalue := backendbase.GetAttrDefault(obj, attrName, cty.StringVal(getEnvSettingWithDefault(attrName, def)))\n\treturn value, value.IsKnown() && !value.IsNull()\n}\n\nfunc getBackendAttr(obj cty.Value, attrName string) (cty.Value, bool) {\n\treturn getBackendAttrWithDefault(obj, attrName, \"\")","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/oci/util.go#L50-L86","documentation":"Returned by checkProfile in the oci backend after it reads the OCI config file and scans every line for an INI section header [PROFILE] matching the requested profile name, finding none. It is a configuration-validation error raised before any cloud API call is attempted.","triggerScenarios":"The oci backend is configured with an auth profile name that does not exist as a [section] in the OCI config file (~/.oci/config by default, or the file pointed to by OCI_CONFIG_FILE / the backend config). Also triggered when the profile name has a typo, trailing whitespace, or the config file is the wrong one (e.g. HOME override).","commonSituations":"User sets profile = \"prod\" but the config file only contains [DEFAULT] and [dev]; CI runs with a different HOME so ~/.oci/config is empty; profile name copied with a leading space; switching between OCI_CONFIG_FILE locations without updating the backend block.","solutions":["Open the OCI config file and confirm a section header exactly matches the requested profile name, including brackets, e.g. [myprofile].","Check OCI_CONFIG_FILE / OCI_HOME_OVERRIDE env vars point at the file you expect; echo $HOME to confirm which ~/.oci/config is read.","Correct the profile attribute in the terraform backend 'oci' block to match an existing section.","Regenerate the config with `oci setup config` if the section was lost."],"exampleFix":"// before: terraform backend block\nprofile = \"prod\"\n# but ~/.oci/config only has [DEFAULT] and [nonprod]\n\n# after: align names\nprofile = \"nonprod\"\n# or add to ~/.oci/config:\n# [prod]\n# user=ocid1.user...\n# tenancy=ocid1.tenancy...\n# key_file=~/.oci/prod.pem\n# region=us-phoenix-1","handlingStrategy":"validation","validationCode":"// Replicate checkProfile's scan before configuring the backend.\nfunc profileExists(configPath, profile string) error {\n    re := regexp.MustCompile(`^\\[(.*)\\]`)\n    data, err := os.ReadFile(configPath)\n    if err != nil { return err }\n    for _, line := range strings.Split(string(data), \"\\n\") {\n        if m := re.FindStringSubmatch(line); m != nil && len(m) > 1 && strings.TrimSpace(m[1]) == profile {\n            return nil\n        }\n    }\n    return fmt.Errorf(\"profile %q not found in %s\", profile, configPath)\n}","typeGuard":null,"tryCatchPattern":"if err := checkProfile(profile, ociConfigPath); err != nil {\n    log.Fatalf(\"OCI backend misconfigured: %v. Run `oci setup config`.\", err)\n}","preventionTips":["Pin OCI_CONFIG_FILE explicitly in CI.","List profiles before running: grep '^\\[' ~/.oci/config.","Avoid trailing spaces in profile names."],"tags":["oci","config","profile","auth","backend","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}