{"record":{"id":"938c57d01f3de259","repo":"hashicorp/terraform","slug":"unexpected-command-type-in-confirmprovideristruste","errorCode":null,"errorMessage":"Unexpected command type in confirmProviderIsTrusted; this is a bug in Terraform and should be reported.","messagePattern":"Unexpected command type in confirmProviderIsTrusted; this is a bug in Terraform and should be reported\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/meta_backend.go","lineNumber":3168,"sourceCode":"\t\t\t\t\tlockfileProblem = \"Terraform used the working directory's lock file by default, but it was empty or did not exist.\"\n\t\t\t\tdefault:\n\t\t\t\t\t// Default lock file used, and it exists/has locks in it.\n\t\t\t\t\tlockfileProblem = \"Terraform used the working directory's lock file by default, but it did not contain a lock for the state store provider.\"\n\t\t\t\t}\n\n\t\t\t\tvar guidance string\n\t\t\t\tvar remediationInstructions string\n\t\t\t\tswitch command.(type) {\n\t\t\t\tcase *InitCommand:\n\t\t\t\t\tguidance = `When performing a \"terraform init\" command in automation, make sure to supply a lock file for the state store provider using the -state-provider-lock-file flag.`\n\t\t\t\t\tremediationInstructions = `To fix this, create a minimal configuration containing the specific provider version(s) you need and then perform \"terraform init\" with input enabled. Check the contents of the lock file created by that command and then retry \"terraform init -state-provider-lock-file=<path to lockfile>\".\n`\n\t\t\t\tcase *StateMigrateCommand:\n\t\t\t\t\tguidance = `When performing a \"terraform state migrate\" command in automation, make sure to supply a lock file for the source and/or destination state store providers using -source-provider-lock-file and/or -destination-provider-lock-file flags.`\n\t\t\t\t\tremediationInstructions = `To fix this, create a minimal configuration(s) containing the specific provider version(s) you need and then perform \"terraform init\" with input enabled. Check the contents of the lock file created by that command and then retry \"terraform state migrate -source-provider-lock-file=<path to lockfile> -destination-provider-lock-file=<path to lockfile>\".`\n\n\t\t\t\tdefault:\n\t\t\t\t\tpanic(\"Unexpected command type in confirmProviderIsTrusted; this is a bug in Terraform and should be reported.\")\n\t\t\t\t}\n\n\t\t\t\tdiags = diags.Append(tfdiags.Sourceless(\n\t\t\t\t\ttfdiags.Error,\n\t\t\t\t\t\"Missing lock for state store provider\",\n\t\t\t\t\tfmt.Sprintf(`Terraform is initializing a state store for the first time in a non-interactive mode but no lock was found for the state store provider.\n%s\n\n%s\n\n%s`,\n\t\t\t\t\t\tlockfileProblem,\n\t\t\t\t\t\tguidance,\n\t\t\t\t\t\tremediationInstructions,\n\t\t\t\t\t),\n\t\t\t\t))\n\t\t\t\treturn diags\n\t\t\t}","sourceCodeStart":3150,"sourceCodeEnd":3186,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_backend.go#L3150-L3186","documentation":"Programmer-error panic in confirmProviderIsTrusted: during non-interactive safe-init handling, the command value passed in is neither *InitCommand nor *StateMigrateCommand. Because the trust/lock-file guidance text is command-specific, the default branch panics rather than guessing. Message explicitly says it is a Terraform bug.","triggerScenarios":"A code path that triggers the RequiresApproval + non-interactive branch from a command type other than Init or StateMigrate (e.g. a new state-related command added without updating this switch).","commonSituations":"Internal Terraform refactor introducing a new command that reaches state-store init approval; or invoking confirmProviderIsTrusted with a wrapped/aliased command type.","solutions":["Report as a Terraform bug; include the command you ran.","Run the equivalent terraform init in interactive mode (with input enabled) as a workaround.","Supply the state-store provider lock file via -state-provider-lock-file so the non-interactive branch is avoided."],"exampleFix":"// before (library code)\ndefault:\n    panic(\"Unexpected command type in confirmProviderIsTrusted; this is a bug in Terraform and should be reported.\")\n\n// after (defensive)\ndefault:\n    return diags.Append(tfdiags.Sourceless(tfdiags.Error, \"Unsupported command for state store trust approval\", \"...\"))","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Defensive: degrade to a generic error instead of panicking\ndefer func() {\n    if r := recover(); r != nil {\n        diags = diags.Append(tfdiags.Sourceless(tfdiags.Error, \"Unsupported command\", fmt.Sprintf(\"%v\", r)))\n    }\n}()","preventionTips":["Run terraform init with input enabled interactively when possible.","Supply -state-provider-lock-file in automation to avoid the non-interactive approval branch.","Report the triggering command as a Terraform bug."],"tags":["terraform","state-store","panic","internal-bug","safe-init"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}