{"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":"error_code","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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/backend/remote-state/oci/util.go#L50-L86","documentation":"Thrown by checkProfile() in the OCI backend when the specified profile name is not found in the OCI config file (typically ~/.oci/config). The function reads the file line-by-line and matches INI-style section headers ([profile_name]) via regex '^\\\\[(.*)\\\\]'. If no section header matches the requested profile, this error is returned.","triggerScenarios":"checkProfile(profile, path) is called during OCI backend configuration. It reads the config file at the given path, splits by newline, and searches for a line matching '[profile]'. Fails when: the profile name has a typo, the config file uses a different format, or the profile section simply doesn't exist.","commonSituations":"Typo in the 'profile' attribute of the backend configuration block. Using 'DEFAULT' vs 'default' (case-sensitive match). Config file path points to wrong file. New machine without 'oci setup' having been run. Profile created in a different config file than the one pointed to by the 'config_file' attribute.","solutions":["List available profiles: cat ~/.oci/config and verify the section header matches your backend 'profile' value exactly.","Run 'oci setup config' to create the profile if it doesn't exist.","Ensure the 'config_file' backend attribute points to the correct file path containing the profile.","Check for case mismatches — 'DEFAULT' and 'default' are treated as distinct profile names by this matching logic."],"exampleFix":"// backend config — ensure profile matches a [section] in ~/.oci/config\nterraform {\n  backend \"oci\" {\n    // before (typo)\n    profile = \"producton\"\n    // after\n    profile = \"production\"\n  }\n}","handlingStrategy":"validation","validationCode":"// Validate OCI config profile existence before Terraform init\nimport (\n    \"os\"\n    \"regexp\"\n    \"strings\"\n)\n\nfunc validateOCIProfile(configPath, profile string) error {\n    data, err := os.ReadFile(configPath)\n    if err != nil {\n        return fmt.Errorf(\"cannot read OCI config at %s: %w\", configPath, err)\n    }\n    profileRegex := regexp.MustCompile(`^\\[(.*)\\]`)\n    for _, line := range strings.Split(string(data), \"\\n\") {\n        if match := profileRegex.FindStringSubmatch(line); match != nil && len(match) > 1 && match[1] == profile {\n            return nil\n        }\n    }\n    return fmt.Errorf(\"profile %q not found in %s — available profiles can be listed with: grep '^\\[' %s\", profile, configPath, configPath)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run 'oci setup config' and note the profile name you create.","Use 'oci iam region list --profile <name>' to verify the profile works before configuring the Terraform backend.","Keep the config_file and profile attributes in the backend block consistent with your ~/.oci/config."],"tags":["oci","configuration","authentication","profile"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}