Skip to content

Commit

Permalink
Switch the public registry hostname depends on tfExecType
Browse files Browse the repository at this point in the history
The state replace-provider command returns the following error when
using a legacy terraform state in tofu.

```
tofu state replace-provider registry.terraform.io/-/null registry.terraform.io/hashicorp/null

Error: Invalid "from" provider "registry.terraform.io/-/null"

Invalid provider namespace: The legacy provider namespace "-" can be used
only with hostname registry.opentofu.org.
```
  • Loading branch information
minamijoyo committed Nov 9, 2023
1 parent be2841a commit 6f1cd7b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tfmigrate/state_replace_provider_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,17 @@ func TestAccStateReplaceProviderAction(t *testing.T) {
tf := tfexec.SetupTestAccForStateReplaceProvider(t, workspace, backend+source)
ctx := context.Background()

registry := "registry.terraform.io"
tfExecType, _, err := tf.Version(ctx)
if err != nil {
t.Fatalf("failed to get tfExecType: %s", err)
}
if tfExecType == "opentofu" {
registry = "registry.opentofu.org"
}

actions := []StateAction{
NewStateReplaceProviderAction("registry.terraform.io/-/null", "registry.terraform.io/hashicorp/null"),
NewStateReplaceProviderAction(registry+"/-/null", registry+"/hashicorp/null"),
}

m := NewStateMigrator(tf.Dir(), workspace, actions, &MigratorOption{}, false, false)
Expand Down

0 comments on commit 6f1cd7b

Please sign in to comment.