{"record":{"id":"605be1dde8212c84","repo":"hashicorp/terraform","slug":"failed-to-convert-provider-version-to-go-version","errorCode":null,"errorMessage":"Failed to convert provider version to Go version: %s","messagePattern":"Failed to convert provider version to Go version: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/state_migrate.go","lineNumber":289,"sourceCode":"\t\tif !diags.HasErrors() {\n\t\t\tmigrateOpts.DestinationType = rootMod.StateStore.Type\n\t\t\tmigrateOpts.Destination = dstB\n\t\t}\n\n\t\t// Capture details of the destination state store for updating the backend state file after a successful migration.\n\t\t_, cHash, sscDiags := c.stateStoreConfig(&BackendOpts{\n\t\t\tStateStoreConfig: rootMod.StateStore,\n\t\t\tLocks:            destinationLock,\n\t\t})\n\t\tdiags = diags.Append(sscDiags)\n\t\tif sscDiags.HasErrors() {\n\t\t\tview.Diagnostics(diags)\n\t\t\treturn 1\n\t\t}\n\t\tv := destinationLock.Provider(rootMod.StateStore.ProviderAddr).Version() // We just downloaded this provider, so the lock wil be present.\n\t\tversion, err := providerreqs.GoVersionFromVersion(v)\n\t\tif err != nil {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"Failed to convert provider version to Go version: %s\", err))\n\t\t\tview.Diagnostics(diags)\n\t\t\treturn 1\n\t\t}\n\n\t\tbsf.StateStore = &workdir.StateStoreConfigState{\n\t\t\tType: rootMod.StateStore.Type,\n\t\t\tHash: uint64(cHash),\n\t\t\tProvider: &workdir.ProviderConfigState{\n\t\t\t\tSource:  &rootMod.StateStore.ProviderAddr,\n\t\t\t\tVersion: version,\n\t\t\t},\n\t\t\tProviderSupplyMode: rootMod.StateStore.ProviderSupplyMode,\n\t\t}\n\t\terr = bsf.StateStore.SetConfig(stateStoreConfigVal, dstB.ConfigSchema())\n\t\tif err != nil {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"Failed to set state store configuration: %w\", err))\n\t\t\tview.Diagnostics(diags)\n\t\t\treturn 1","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/state_migrate.go#L271-L307","documentation":"Thrown when providerreqs.GoVersionFromVersion(v) fails to convert the just-downloaded destination state-store provider version into a hashicorp/go-version Version. GoVersionFromVersion simply calls version.NewVersion(v.String()); it fails only if the provider version string is not valid semver. The %s is the parse error. This is essentially an internal invariant failure since the version came from a successfully resolved provider lock.","triggerScenarios":"During `terraform state migrate` to a state_store destination, after downloading the destination provider, converting its version (from destinationLock.Provider(...).Version()) to a Go version fails because the version string is malformed. Practically only seen with corrupted lock-file version fields, a malicious/corrupt provider registry, or a hand-edited .terraform.lock.hcl.","commonSituations":"Manually edited .terraform.lock.hcl with a non-semver version; a private/provider mirror serving a non-conforming version; downgrade/upgrade path through a provider that published a non-semver tag.","solutions":["Delete the dependency lock file and re-run `terraform state migrate -upgrade` so the provider version is re-resolved cleanly.","Inspect .terraform.lock.hcl for the state-store provider entry and fix or remove any non-semver version string.","Verify the provider registry/mirror serves standard semver versions for that provider.","Report a bug if the version is valid semver but still fails — this path should be unreachable for normally-resolved versions."],"exampleFix":"# before: corrupted lock entry\nprovider \"registry.example.com/foo/state\" {\n  version = \"v1.2.3-beta\"  # leading v may break strict parsers\n}\n\n# after: re-resolve from scratch\nrm .terraform.lock.hcl\nterraform state migrate -upgrade","handlingStrategy":"validation","validationCode":"// before relying on a provider version, validate it is parseable semver.\nfunc validProviderVersion(v string) error {\n    _, err := semver.Parse(v)\n    return err\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never hand-edit .terraform.lock.hcl version fields; let Terraform resolve them.","Use reputable provider registries/mirrors that publish standard semver tags.","Delete and regenerate the lock file if versions look malformed.","Pin required_providers to clean version constraints."],"tags":["state-migrate","state-store","provider","version","semver"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}