minamijoyo / tfmigrate

A Terraform / OpenTofu state migration tool for GitOps
MIT License
1.13k stars 57 forks source link

Error asking for state migration action: input is disabled #45

Closed antigenius0910 closed 1 year ago

antigenius0910 commented 3 years ago

Hi thanks last time testing with me on the sandbox! it was great!

I am moving it to my codebase now but I hit another bug, can you take a look for me when you have time? thank you!

% cat tfmigrate_test.hcl 
migration "state" "test" {
  actions = [
    "mv github_repository.tfer--infra-002D-staging-002D-terraform github_repository.infra-staging-terraform",
  ]
}
 % TFMIGRATE_LOG=DEBUG tfmigrate plan tfmigrate_test.hcl
2021/10/12 16:44:17 [DEBUG] [main] start: tfmigrate plan tfmigrate_test.hcl
2021/10/12 16:44:17 [DEBUG] [main] tfmigrate version: 0.2.9
2021/10/12 16:44:17 [DEBUG] [command] config: &config.TfmigrateConfig{MigrationDir:".", History:(*history.Config)(nil)}
2021/10/12 16:44:17 [DEBUG] [command] option: &tfmigrate.MigratorOption{ExecPath:"", PlanOut:""}
2021/10/12 16:44:17 [INFO] [runner] load migration file: tfmigrate_test.hcl
2021/10/12 16:44:17 [INFO] [migrator] start state migrator plan
2021/10/12 16:44:17 [DEBUG] [executor@.]$ terraform version
2021/10/12 16:44:17 [INFO] [migrator@.] terraform version: 1.0.6
2021/10/12 16:44:17 [INFO] [migrator@.] initialize work dir
2021/10/12 16:44:22 [DEBUG] [executor@.]$ terraform init -input=false -no-color
2021/10/12 16:44:22 [INFO] [migrator@.] switch to remote workspace default
2021/10/12 16:44:23 [DEBUG] [executor@.]$ terraform workspace select default
2021/10/12 16:44:23 [INFO] [migrator@.] get the current remote state
2021/10/12 16:44:26 [DEBUG] [executor@.]$ terraform state pull
2021/10/12 16:44:26 [INFO] [migrator@.] override backend to local
2021/10/12 16:44:26 [INFO] [executor@.] create an override file
2021/10/12 16:44:26 [INFO] [migrator@.] creating local workspace folder in: terraform.tfstate.d/default
2021/10/12 16:44:26 [INFO] [executor@.] switch backend to local
2021/10/12 16:44:31 [DEBUG] [executor@.]$ terraform init -input=false -no-color -reconfigure
2021/10/12 16:44:31 [DEBUG] [executor@.] failed to run command: (*exec.ExitError)(0xc0002ca140)(exit status 1)
failed to switch backend to local: failed to run command (exited 1): terraform init -input=false -no-color -reconfigure
stdout:

Initializing the backend...

stderr:

Error: Error asking for state migration action: input is disabled

but "terraform init -input=false -no-color -reconfigure" run seems fine by itself

% terraform init -input=false -no-color -reconfigure

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of integrations/github from the dependency lock file
- Using previously-installed integrations/github v4.14.0

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

checking file context

% cat repository.tf | grep tfer--infra-002D-staging-002D-terraform
resource "github_repository" "tfer--infra-002D-staging-002D-terraform" {
 % cat terraform.tfstate | grep  github_repository.tfer--infra-002D-staging-002D-terraform
    "github_repository_tfer--infra-002D-staging-002D-terraform_id": {
minamijoyo commented 3 years ago

Hi, @antigenius0910. Thank you for reporting the issue.

Error: Error asking for state migration action: input is disabled

The error message seems to come from the workspace related code in Terraform core. https://github.com/hashicorp/terraform/blob/v1.0.6/internal/command/meta_backend_migrate.go#L164 https://github.com/hashicorp/terraform/blob/v1.0.6/internal/command/meta_backend_migrate.go#L225

Does your configuration use the workspace feature? https://www.terraform.io/docs/cli/workspaces/index.html

antigenius0910 commented 3 years ago

Hi @minamijoyo,

Thanks for the prompt response!

I think I am not using workspace feature. one more info here. this codebase's tf files were all pull from terraformer https://github.com/GoogleCloudPlatform/terraformer

% ls -al
total 97184
drwxr-xr-x  13 yen  staff       416 Oct 12 10:34 .
drwxr-xr-x   9 yen  staff       288 Oct 12 10:20 ..
-rw-r--r--   1 yen  staff        26 Oct 12 10:34 .gitignore
-rwxr-xr-x   1 yen  staff   3445692 Oct 12 10:20 outputs.tf
-rwxr-xr-x   1 yen  staff       180 Oct 12 10:25 provider.tf
-rwxr-xr-x   1 yen  staff    362482 Oct 12 10:31 repository.tf
-rwxr-xr-x   1 yen  staff    379808 Oct 12 10:20 repository.tfe
-rwxr-xr-x   1 yen  staff   3630701 Oct 12 10:20 repository_collaborator.tf
-rwxr-xr-x   1 yen  staff     32123 Oct 12 10:20 repository_deploy_key.tf
-rwxr-xr-x   1 yen  staff    225383 Oct 12 10:20 repository_webhook.tf
-rwxr-xr-x   1 yen  staff  13969026 Oct 12 10:26 terraform.tfstate
-rw-r--r--   1 yen  staff  13768749 Oct 12 10:25 terraform.tfstate.1634052349.backup
-rw-r--r--   1 yen  staff  13914405 Oct 12 10:26 terraform.tfstate.1634052364.backup

% terraform workspace list
* default
minamijoyo commented 3 years ago

OK, you don't look like using the workspace. I'm curious that terraform.tfstate exists in the current directory. I guess you're probably using a local backend. Which backend do you use? The default is local and the reason I'm asking this is because tfmigrate doesn't work with the local backend.

https://www.terraform.io/docs/language/settings/backends/configuration.html

antigenius0910 commented 3 years ago

aww yes, local is exactly what I use for now. cool, I will test it on S3 later and come back report if it works on S3 backend! thank you so much for a prompt troubleshoot!

minamijoyo commented 1 year ago

I'm going to close this because there has been no activity on this recently. Please feel free to reopen this if you have any questions or suggestions. Thanks!

Diliz commented 1 year ago

Hello! Still have the issue here, no local storage state migration available since then?

minamijoyo commented 1 year ago

I have no plan to support a local backend. If your state is not shared with someone, wouldn't it be enough to run the terraform state command directly?