hashicorp/terraform · error
configuration file did not contain profile: %s
Error message
configuration file did not contain profile: %s
What it means
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.
Source
Thrown at internal/backend/remote-state/oci/util.go:68
return ""
}
return home
}
func checkProfile(profile string, path string) (err error) {
var profileRegex = regexp.MustCompile(`^\[(.*)\]`)
data, err := os.ReadFile(path)
if err != nil {
return err
}
content := string(data)
splitContent := strings.Split(content, "\n")
for _, line := range splitContent {
if match := profileRegex.FindStringSubmatch(line); match != nil && len(match) > 1 && match[1] == profile {
return nil
}
}
return fmt.Errorf("configuration file did not contain profile: %s", profile)
}
// cleans and expands the path if it contains a tilde , returns the expanded path or the input path as is if not expansion
// was performed
func expandPath(filepath string) string {
if strings.HasPrefix(filepath, fmt.Sprintf("~%c", os.PathSeparator)) {
filepath = path.Join(getHomeFolder(), filepath[2:])
}
return path.Clean(filepath)
}
func getBackendAttrWithDefault(obj cty.Value, attrName, def string) (cty.Value, bool) {
value := backendbase.GetAttrDefault(obj, attrName, cty.StringVal(getEnvSettingWithDefault(attrName, def)))
return value, value.IsKnown() && !value.IsNull()
}
func getBackendAttr(obj cty.Value, attrName string) (cty.Value, bool) {
return getBackendAttrWithDefault(obj, attrName, "")View on GitHub (pinned to c9def3e214)
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.
Example fix
// before: terraform backend block profile = "prod" # but ~/.oci/config only has [DEFAULT] and [nonprod] # after: align names profile = "nonprod" # or add to ~/.oci/config: # [prod] # user=ocid1.user... # tenancy=ocid1.tenancy... # key_file=~/.oci/prod.pem # region=us-phoenix-1
Defensive patterns
Strategy: validation
Validate before calling
// Replicate checkProfile's scan before configuring the backend.
func profileExists(configPath, profile string) error {
re := regexp.MustCompile(`^\[(.*)\]`)
data, err := os.ReadFile(configPath)
if err != nil { return err }
for _, line := range strings.Split(string(data), "\n") {
if m := re.FindStringSubmatch(line); m != nil && len(m) > 1 && strings.TrimSpace(m[1]) == profile {
return nil
}
}
return fmt.Errorf("profile %q not found in %s", profile, configPath)
} Try / catch
if err := checkProfile(profile, ociConfigPath); err != nil {
log.Fatalf("OCI backend misconfigured: %v. Run `oci setup config`.", err)
} Prevention
- Pin OCI_CONFIG_FILE explicitly in CI.
- List profiles before running: grep '^\[' ~/.oci/config.
- Avoid trailing spaces in profile names.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- must not be null
- must not be a whole number
- attribute %q is required
- sasToken cannot be empty
- subscription id not specified
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/e444e882bc329dc8.
Report an issue: GitHub.